Omnom_Options.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. OmnomIRC COPYRIGHT 2010,2011 Netham45
  3. This file is part of OmnomIRC.
  4. OmnomIRC is free software: you can redistribute it and/or modifys
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. OmnomIRC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with OmnomIRC. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. //******************************
  16. // Option Engine Start *
  17. //******************************
  18. (function(window,undefined){
  19. var Options = "----------------------------------------|", //40 for future expansion!(and 40 bytes isn't much.) Pipe is a terminator.
  20. cookieLoad = window.cookieLoad = function() {
  21. if (document.cookie.indexOf("OmnomIRC") >= 0) {
  22. Options = document.cookie.replace(/^.*OmnomIRC=(.+?)|.*/, "\$1");
  23. }else{
  24. document.cookie = "OmnomIRC=" + Options + ";expires=Sat, 20 Nov 2286 17:46:39 GMT;";
  25. }
  26. },
  27. getOption = window.getOption = function(Option,def) { //Returns what 'Option' is. Option must be a number 1-40. def is what to return if it is not set(equal to -)
  28. if (Option < 1 || Option > 40){
  29. return 0;
  30. }
  31. var result = Options.charAt(Option - 1);
  32. if (result == '-'){
  33. return def;
  34. }
  35. return result;
  36. },
  37. setOption = window.setOption = function(Option, value,noRefresh) { //Sets 'Option' to 'value'. Value must be a single char. Option must be a number 1-40.
  38. if (Option < 1 || Option > 40){
  39. return;
  40. }
  41. Options = Options.substring(0, Option - 1) + value + Options.substring(Option);
  42. document.cookie = "OmnomIRC=" + Options + ";expires=Sat, 20 Nov 2286 17:46:39 GMT;";
  43. if (!noRefresh){
  44. document.location.reload();
  45. }
  46. };
  47. function getHTMLToggle(State, StateOn, StateOff,StateOnFunc,StateOffFunc){
  48. var result = "";
  49. if (State){
  50. result += "<b>";
  51. result += StateOn;
  52. result += "</b>";
  53. }else{
  54. result += '<a href="#" onclick="'+StateOnFunc+'">';
  55. result += StateOn;
  56. result += '</a>';
  57. }
  58. result += "</td><td>";
  59. if(!State){
  60. result += "<b>";
  61. result += StateOff;
  62. result += "</b>";
  63. }else{
  64. result += '<a href="#" onclick="'+StateOffFunc+'">';
  65. result += StateOff;
  66. result += '</a>';
  67. }
  68. return result;
  69. }
  70. function clearCookies(){
  71. document.cookie = "OmnomIRC=a;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  72. document.cookie = "OmnomChannels=a;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  73. document.location.reload();
  74. }
  75. window.onLoad=cookieLoad();
  76. //******************************
  77. // Option Engine End *
  78. //******************************
  79. //******************************
  80. // Chrome Notification Start *
  81. //******************************
  82. function showNotification(message){
  83. if (window.webkitNotifications === undefined || window.webkitNotifications === null || !window.webkitNotifications){
  84. return 0;
  85. }
  86. if (window.webkitNotifications.checkPermission() !== 0){
  87. return 0;
  88. }
  89. var n;
  90. n = window.webkitNotifications.createNotification('http://www.omnimaga.org/favicon.ico', 'OmnomIRC Highlight', message);
  91. n.show();
  92. }
  93. function setAllowNotification(){
  94. if (window.webkitNotifications === undefined || window.webkitNotifications === null || !window.webkitNotifications){
  95. alert("This feature only works in chrome.");
  96. return;
  97. }
  98. window.webkitNotifications.requestPermission(permissionGranted);
  99. }
  100. function permissionGranted(){
  101. if (window.webkitNotifications.checkPermission() === 0){
  102. showNotification("Notifications Enabled!");
  103. setOption(7,'T');
  104. window.location.refresh(true);
  105. }
  106. }
  107. //******************************
  108. // Chrome Notification End *
  109. //******************************
  110. })(window);