[s4s] Enhancer

Highlights dubs - Never miss your chance to check em again!

  1. // ==UserScript==
  2. // @name [s4s] Enhancer
  3. // @namespace https://userscripts.org/users/532546
  4. // @email lefuncssman@mail.com
  5. // @description Highlights dubs - Never miss your chance to check em again!
  6. // @include https://boards.4chan.org/*
  7. // @include http://boards.4chan.org/*
  8. // @author le fun css man AKA Doctor Worse Than Hitler
  9. // @version 1.32
  10. // ==/UserScript==
  11.  
  12. // NOTE:
  13. // This is a copy that works on all 4chan subs. I haven't edited anything but the includes.
  14.  
  15.  
  16. initialize();
  17. addCSS(); // add the css
  18. highlightDubs(); // highlight dubs
  19. changePosts(); // color and replace text
  20.  
  21.  
  22. // if this page is a thread, then we need to periodically check for updates brought in by the auto-update
  23. //if(document.URL.indexOf("res") != -1)
  24. //{
  25. setInterval(function(){checkIfUpdated()}, 5000); // check if the thread is updated every 5 seconds
  26. //}
  27. function initialize()
  28. {
  29. window.lastNo = 0; // used to make sure we don't check posts twice
  30. window.lastMessage = 0; // don't want to check texts twice either
  31. window.replaceLimit = 10; // limits number of times an individual emote can be used
  32. window.totalLimit = 50; // limits total number of emotes per post. These limits are too prevent errors like "unresponsive script"
  33. window.posts = getPosts();
  34. // Replaces ":key:" with the image"
  35. window.replaceList = {
  36. doge: 'http://i.imgur.com/5XD1CYW.png',
  37. kek: 'http://i.imgur.com/lblY5Sn.png',
  38. checkem: 'http://i.imgur.com/PwAtIwi.png',
  39. froge: 'http://i.imgur.com/j8uUz62.png',
  40. lel: 'http://i.imgur.com/1DfcjLb.png',
  41. thinchin: 'http://i.imgur.com/SwNA28g.png',
  42. ptree: 'http://i.imgur.com/rUDbkXw.png',
  43. btree: 'http://i.imgur.com/M2kjuLL.png',
  44. pktree: 'http://i.imgur.com/GWepwsJ.png',
  45. rtree: 'http://i.imgur.com/l5fKXY7.png',
  46. ruse: 'http://i.imgur.com/8XBt7yF.png',
  47. mot: 'http://i.imgur.com/IfMpxw1.png',
  48. a: 'http://i.imgur.com/q8hHbwQ.gif',
  49. b: 'http://i.imgur.com/03xYJTU.gif',
  50. c: 'http://i.imgur.com/9UxS7ej.gif',
  51. d: 'http://i.imgur.com/gJezGs5.gif',
  52. e: 'http://i.imgur.com/J9df7FB.gif',
  53. f: 'http://i.imgur.com/XgufMCh.gif',
  54. g: 'http://i.imgur.com/BDKY6vy.gif',
  55. h: 'http://i.imgur.com/JWRrUUO.gif',
  56. i: 'http://i.imgur.com/gZLK7Dc.gif',
  57. j: 'http://i.imgur.com/BiZ3dqk.gif',
  58. k: 'http://i.imgur.com/15DDVOh.gif',
  59. l: 'http://i.imgur.com/p0HyNUw.gif',
  60. m: 'http://i.imgur.com/JX55XPt.gif',
  61. n: 'http://i.imgur.com/XhUUK36.gif',
  62. o: 'http://i.imgur.com/04fvVIM.gif',
  63. p: 'http://i.imgur.com/TlWblXt.gif',
  64. q: 'http://i.imgur.com/aEGHWjg.gif',
  65. r: 'http://i.imgur.com/PD6x0Uh.gif',
  66. s: 'http://i.imgur.com/wirH3pL.gif',
  67. t: 'http://i.imgur.com/hsKlJrv.gif',
  68. u: 'http://i.imgur.com/Xpf1VnM.gif',
  69. v: 'http://i.imgur.com/g3INSef.gif',
  70. w: 'http://i.imgur.com/cF6pbpj.gif',
  71. x: 'http://i.imgur.com/UVbdagZ.gif',
  72. y: 'http://i.imgur.com/2BJaMA3.gif',
  73. z: 'http://i.imgur.com/itOUZ85.gif',
  74. }
  75. }
  76. function highlightDubs()
  77. {
  78. // grabs the elements that contain "No. <postno>"
  79. var postNum = document.getElementsByClassName("postNum");
  80. // iterate through all post numbers and check for dubs
  81. for(var i = window.lastNo; i < postNum.length; i++)
  82. {
  83. // get the post number
  84. var no = postNum[i].children[1].innerHTML;
  85. // check for dubs, but only if this isn't already highlighted
  86. if(no.charAt(no.length - 1) == no.charAt(no.length - 2))
  87. {
  88. // highlight it
  89. postNum[i].children[1].className += " dubsHighlight";
  90. }
  91. }
  92. window.lastNo = postNum.length; //last number we checked
  93. }
  94.  
  95. function addCSS()
  96. {
  97. var css = document.createElement("style");
  98. css.type = "text/css";
  99. css.innerHTML = ".dubsHighlight { background-color: orange;" +
  100. "padding: 0 1px; }";
  101. document.head.appendChild(css);
  102. }
  103.  
  104. function getPosts()
  105. {
  106. return document.getElementsByClassName("replyContainer").length
  107. }
  108.  
  109.  
  110. /* function colorText() colors the text in a post based on < > [] {} etc
  111. * This code is a modification of Chest54's extension
  112. * http://userscripts.org/scripts/source/177986
  113. */
  114. function colorText(postMessage)
  115. {
  116. var checkora = postMessage.innerHTML.replace('<span class="fortune"','<br><span class="fortune"').split('<br>');
  117. for(j = 0; j < checkora.length; j++)
  118. {
  119. temp = checkora[j].replace('\n','');
  120. if(temp.length-temp.lastIndexOf('&lt;') == 4 && temp.indexOf('&lt;') !=-1)
  121. {
  122. checkora[j] = '<span style="color:orange">' + checkora[j] + '</span>';
  123. }
  124. else if(temp.indexOf('&lt;')==0)
  125. {
  126. checkora[j] = '<span style="color:red">' + checkora[j] + '</span>';
  127. }
  128. else if(temp.length-temp.lastIndexOf(' ]')== 2 && temp.indexOf(' ]') != -1)
  129. {
  130. if(temp.indexOf('[ ') == 0)
  131. {
  132. checkora[j] = '<span style="color:blue;font-family:monospace;font-weight:bold">' + checkora[j] + '</span>';
  133. }
  134. }
  135. else if(temp.length-temp.lastIndexOf(' }') == 2 && temp.indexOf(' }') !=-1)
  136. {
  137. if(temp.indexOf('{ ') == 0)
  138. {
  139. checkora[j] = '<span style="color:purple;font-family:monospace;font-weight:bold">' + checkora[j] + '</span>';
  140. }
  141. }
  142. if(temp.indexOf('[spoiler]') + 1 && temp.indexOf('[/spoiler]'))
  143. {
  144. if(temp.indexOf('[spoiler]')<temp.indexOf('[/spoiler]'))
  145. {
  146. checkora[j]=checkora[j].replace('[spoiler]','<span class="spoiler">');
  147. checkora[j]=checkora[j].replace('[/spoiler]','</span>');
  148. }
  149. }
  150. }
  151. var checkorb = checkora.join('<br>').replace('<br><span class="fortune"','<span class="fortune"');
  152. postMessage.innerHTML=checkorb;
  153. }
  154. // handles post modifcations such as colorText() and replaceText()
  155. function changePosts()
  156. {
  157. var postMessage=document.getElementsByClassName('postMessage'); // get all post messages
  158. for(i = window.lastMessage; i < postMessage.length; i++)
  159. {
  160. colorText(postMessage[i]);
  161. replaceText(postMessage[i]);
  162. }
  163. window.lastMessage = postMessage.length;
  164. }
  165.  
  166. function replaceText(postMessage)
  167. {
  168. var totalCount = 0; // count replaced stuff so we don't overdo it
  169. // replace everything in the replace list
  170. for(var key in window.replaceList)
  171. {
  172. var singleCount = 0;
  173. while(singleCount < window.replaceLimit && postMessage.innerHTML.indexOf(':'+key+':') != -1)
  174. {
  175. singleCount++;
  176. postMessage.innerHTML = postMessage.innerHTML.replace(':' + key + ':', '<img class="emote" src="' + window.replaceList[key] +
  177. '" alt="' + key + '" title="' + key + '" />');
  178. }
  179. totalCount += singleCount;
  180. if(totalCount >= window.totalLimit)
  181. break;
  182. }
  183. }
  184.  
  185. // supposed to do stuff after a page is updated
  186. function checkIfUpdated()
  187. {
  188. //console.log("checked!");
  189. // if there are new posts, thread has been updated!
  190. if(window.posts < getPosts())
  191. {
  192. window.posts = getPosts();
  193. updateCare(); // update stuff!
  194. }
  195. }
  196.  
  197. // things to do on thread update
  198. function updateCare()
  199. {
  200. highlightDubs(); // highlight new post dubs
  201. changePosts(); // update posts
  202. }