ETI Sig Fader

fades sigs

  1. // ==UserScript==
  2. // @name ETI Sig Fader
  3. // @namespace pendevin
  4. // @description fades sigs
  5. // @include http://boards.endoftheinter.net/showmessages.php*
  6. // @include http://archives.endoftheinter.net/showmessages.php*
  7. // @include http://endoftheinter.net/inboxthread.php*
  8. // @include https://boards.endoftheinter.net/showmessages.php*
  9. // @include https://archives.endoftheinter.net/showmessages.php*
  10. // @include https://endoftheinter.net/inboxthread.php*
  11. // @require http://code.jquery.com/jquery-2.1.3.min.js
  12. // @version 2.2
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16.  
  17. //this is the opacity level you want in percentage. 100 is fully opaque (normal). 0 is fully transparent.
  18. const SIG_OPACITY = 50;
  19. //to change the color of the sig text, set USE_SIG_COLOR to true and change SIG_COLOR to your desired color (hex values like #000000 are fine)
  20. const USE_SIG_COLOR = false;
  21. const SIG_COLOR = 'black';
  22. //if you want the sig to go to full opacity (like normal) when you mouse over it, set this to true
  23. const SIG_FADE_IN = true;
  24.  
  25. //any other styles you want to apply to sigs can be added to elements with class sig
  26.  
  27.  
  28. //ll breaks without noconflict jquery
  29. this.$ = this.jQuery = jQuery.noConflict(true);
  30.  
  31. //adds a style to a document and returns the style object *JQUERY
  32. //css is a string, id is an optional string that determines the object's id
  33. function addStyle(css, id) {
  34. //create a style
  35. var style = $('<style type="text/css">');
  36. //add the css data to it
  37. style.html(css);
  38. if (id) {
  39. //remove any style that has our id
  40. $('#' + id).remove();
  41. //give our style the id after removing the other stuff. idk if it matters, but i'm too lazy to find out
  42. style.attr('id', id);
  43. }
  44. //add the style into the head
  45. $('head').append(style);
  46. //we're outta here
  47. return style;
  48. }
  49.  
  50. //livelinks compatiblity *JQUERY
  51. //calls the function on each message-container in a document, including ones added by livelinks
  52. //place is an optional specialized location
  53. function livelinks(func, extraParams, place) {
  54. if (extraParams == undefined) {
  55. extraParams = null;
  56. }
  57. if (place == undefined) {
  58. place = '.message-container';
  59. }
  60. //run the function on the message-containers currently on the page
  61. $('#u0_1 ' + place).each(function(i, container) {
  62. func(container, extraParams);
  63. });
  64. //run it on any message-containers added in the future
  65. $('#u0_1').on(
  66. 'DOMNodeInserted',
  67. extraParams,
  68. function(e) {
  69. if ($(e.target).children(place).length) {
  70. $(e.target).children(place).each(function(i, container) {
  71. func(container, e.data);
  72. });
  73. }
  74. }
  75. );
  76. }
  77.  
  78. //puts sigs into their own element for easier styling
  79. function processSigs(place) {
  80. place = $(place);
  81. var message = place.find('td.message');
  82. //make sure we haven't already done this
  83. if (!message.find('.sig').length) {
  84. //make sig container
  85. var sig = $('<span class="sig">');
  86. message.append(sig);
  87. //find the sig belt
  88. //this should be the last sig belt on the block
  89. var sigBelt = message.contents().filter(function(i) {
  90. if (this.textContent.search('^\n?---$') == 0) {
  91. return true;
  92. } else {
  93. return false;
  94. }
  95. }).last();
  96. //fallback for if there isn't a sig belt
  97. var sigIndex = message.contents().length;
  98. if (sigBelt.length) {
  99. var sigIndex = message.contents().index(sigBelt);
  100. }
  101. //stuff junk in sig container
  102. message.contents().slice(sigIndex).appendTo(sig);
  103. }
  104.  
  105. //fuck with what happens when you hit the quote button because normal luelinks can't handle dese sigs
  106. var quote = place.find('.message-top > a[href*="&quote="]');
  107. //probably don't have to do this but you know just as a reminder that i ain't doin that shit or something
  108. quote.removeAttr('onclick');
  109. //the normal quote function
  110. var quoteFunc = function() {
  111. return window.QuickPost.publish('quote', quote[0]);
  112. };
  113. //move the sig belt out where it will be recognized, run the quote function, then move it back in
  114. quote.on('click', function(e) {
  115. e.preventDefault();
  116. sigBelt.insertBefore(sig);
  117. quoteFunc();
  118. sig.prepend(sigBelt);
  119. });
  120. }
  121.  
  122. //fade the sigs
  123. var css = '\
  124. .sig{\
  125. opacity:' + SIG_OPACITY / 100 + ';\
  126. }\
  127. ';
  128. if (USE_SIG_COLOR) {
  129. css += '\
  130. .sig{\
  131. color:' + SIG_COLOR + ';\
  132. }\
  133. ';
  134. }
  135. if (SIG_FADE_IN) {
  136. css += '\
  137. .sig:hover{\
  138. opacity:1;\
  139. }\
  140. ';
  141. }
  142. addStyle(css, 'sigFader');
  143.  
  144. //activate the thing
  145. livelinks(processSigs);