faceguydb Chat Box Notify

enter something useful

  1. // ==UserScript==
  2. // @name faceguydb Chat Box Notify
  3. // @namespace com.douglashuck.ogame.forum.chat.notify
  4. // @version 0.2.0
  5. // @description enter something useful
  6. // @include *forumotion.com/chatbox/index.forum*
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  10. // @copyright 2013 Douglas Huck - NO WARRENTY - Public Domain
  11. // ==/UserScript==
  12. if (typeof jQuery !== "undefined") {
  13. main ($);
  14. } else {
  15. add_jQuery (main, "1.7.2");
  16. }
  17.  
  18. function add_jQuery (callbackFn, jqVersion) {
  19. var jqVersion = jqVersion || "1.7.2";
  20. var D = document;
  21. var targ = D.body || D.documentElement;
  22. var scriptNode = D.createElement ('script');
  23. scriptNode.src = 'http://ajax.googleapis.com/ajax/libs/jquery/' + jqVersion + '/jquery.min.js';
  24. scriptNode.addEventListener ("load", function () {
  25. var scriptNode = D.createElement ("script");
  26. scriptNode.textContent = 'var gm_jQuery = jQuery.noConflict (true);\n' + '(' + callbackFn.toString () + ')(gm_jQuery);';
  27. targ.appendChild (scriptNode);
  28. }, false);
  29. targ.appendChild (scriptNode);
  30. main ($);
  31. }
  32. var lastSize = 0;
  33.  
  34. var timer="";
  35. var startTitle=document.title;
  36. var isBlurred=false;
  37. var newMessage=false;
  38. var userName="faceguydb";
  39. var checkboxDisable = "";
  40. var keepAliveCheckbox = "";
  41. var userNameField = "";
  42. var soundUrlField = "";
  43. var newSound = new Audio('http://douglashuck.com/temp/aim.mp3');
  44. newSound.play();
  45. function main ($) {
  46. GM_getValue = function(name, defaultValue) {
  47. var value = localStorage.getItem(name);
  48. if (!value)
  49. return defaultValue;
  50. var type = value[0];
  51. value = value.substring(1);
  52. switch (type) {
  53. case 'b':
  54. return value == 'true';
  55. case 'n':
  56. return Number(value);
  57. default:
  58. return value;
  59. }
  60. }
  61. GM_setValue = function(name, value) {
  62. value = (typeof value)[0] + value;
  63. localStorage.setItem(name, value);
  64. }
  65. soundUrlField = $('<span class="gen"><label>Sound Url: <input type="text" id="soundUrlField" name="soundUrlField" value="'+GM_getValue('soundUrlField', 'http://douglashuck.com/temp/aim.mp3')+'" /></label></span>');
  66. $('#chatbox_main_options').prepend("&nbsp;|&nbsp;");
  67. $('#chatbox_main_options').prepend(soundUrlField);
  68. checkboxDisable = $('<span class="gen"><label>Enable Sound: <input type="checkbox" id="enableSound" name="enableSound" value="" '+GM_getValue('enableSound', 'checked')+'></label></span>');
  69. $('#chatbox_main_options').prepend("&nbsp;|&nbsp;");
  70. $('#chatbox_main_options').prepend(checkboxDisable);
  71. keepAliveCheckbox = $('<span class="gen"><label>Keep Alive: <input type="checkbox" id="keepAliveCheckbox" name="keepAliveCheckbox" value=""'+GM_getValue('keepAliveCheckbox', 'checked')+'></label></span>');
  72. $('#chatbox_main_options').prepend("&nbsp;|&nbsp;");
  73. $('#chatbox_main_options').prepend(keepAliveCheckbox);
  74. userNameField = $('<span class="gen"><label>Username: <input type="text" id="userNameField" name="userNameField" value="'+GM_getValue('userNameField', 'faceguydb')+'" /></label></span>');
  75. $('#chatbox_main_options').prepend("&nbsp;|&nbsp;");
  76. $('#chatbox_main_options').prepend(userNameField);
  77. //$('#chatbox_messenger_form table table tr').prepend(userNameField);
  78. tradeLink = $('<a class="cattitle" id="tradeLinkA">Trade Calc</a>');
  79. tradeLink.click(function(){
  80. if($('#tradeLink').length != 0){
  81. $('#tradeLink').remove();
  82. }else{
  83. $('#chatbox').parent().append('<iframe style="position:relative;width:100%;height:600px;" id="tradeLink" src="http://proxyforgame.com/us/ogame/calc/trade.php"></iframe>');
  84. }
  85. });
  86. $('.cattitle').parent().append("&nbsp;|&nbsp;");
  87. $('.cattitle').parent().append(tradeLink);
  88. $('#enableSound').change(function(){
  89. if($('#enableSound').attr('checked')){
  90. GM_setValue('enableSound', 'checked');
  91. }else{
  92. GM_setValue('enableSound', '');
  93. }
  94. });
  95. $('#keepAliveCheckbox').change(function(){
  96. if($('#keepAliveCheckbox').attr('checked')){
  97. GM_setValue('keepAliveCheckbox', 'checked');
  98. }else{
  99. GM_setValue('keepAliveCheckbox', '');
  100. }
  101. });
  102. $('#userNameField').change(function(){
  103. GM_setValue('userNameField', $('#userNameField').val());
  104. });
  105. $('#soundUrlField').change(function(){
  106. GM_setValue('soundUrlField', $('#soundUrlField').val());
  107. newSound = new Audio($('#soundUrlField').val());
  108. });
  109. $('#message').attr('size', '100');
  110. $('#soundUrlField').change();
  111. setTimeout(function(){
  112. $('#soundUrlField').change();
  113. refresh();
  114. setInterval(checkForChange,50);
  115. },3000);
  116.  
  117. $(window).on("blur",function() {
  118. isBlurred = true;
  119. timer=window.setInterval(function() {
  120. if(newMessage){document.title = (document.title == startTitle ? "New Message!" : startTitle);}
  121. }, 1000);
  122. }).on("focus",function() {
  123. isBlurred = false;
  124. document.title = startTitle;
  125. clearInterval(timer);
  126. newMessage = false;
  127. });
  128. setUpKeepAlive();
  129. $('[name="post"]').submit(setUpKeepAlive);
  130. }
  131.  
  132. var keepAliveTimer = "";
  133. function setUpKeepAlive(){
  134. clearInterval(keepAliveTimer);
  135. keepAliveTimer = setInterval(keepAlive,(Math.floor((Math.random()*(4*60))+(10*60))*1000));//Mins*Seconds*Milliseconds
  136. }
  137. function checkForChange(){
  138. if($('#chatbox').html().length != lastSize && lastSize > 0){
  139. if($('#chatbox').children().last().find('.user a').text() == $('#userNameField').val() || $('#chatbox').children().last().find('.msg').text() == "."){
  140.  
  141. }else{
  142. if($('#enableSound').attr('checked')){
  143. newSound.play();
  144. }
  145. newMessage = true;
  146. }
  147. }
  148. lastSize = $('#chatbox').html().length;
  149. }
  150. function refresh(){
  151. $("#chatbox_main_options a:contains('Refresh')").click();
  152. }
  153. function keepAlive(){
  154. if($('#keepAliveCheckbox').attr('checked')){
  155. $('#message').val('.');
  156. $('#submit_button').click();
  157. }
  158. }