Imagenorator

turns images into links in specified people's posts

当前为 2014-11-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Imagenorator
  3. // @namespace pendevin
  4. // @description turns images into links in specified people's posts
  5. // @include http://boards.endoftheinter.net/showmessages.php?*
  6. // @include http://archives.endoftheinter.net/showmessages.php?*
  7. // @include https://boards.endoftheinter.net/showmessages.php?*
  8. // @include https://archives.endoftheinter.net/showmessages.php?*
  9. // @require http://code.jquery.com/jquery-2.1.0.min.js
  10. // @version 2
  11. // ==/UserScript==
  12.  
  13.  
  14. //add userIDs of people you want ignorated
  15. //this is CactusMD and Das Bhut
  16. const IMAGENORATED=$([13346,23945]);
  17.  
  18.  
  19. //ll breaks without noconflict jquery
  20. this.$ = this.jQuery = jQuery.noConflict(true);
  21.  
  22. //livelinks compatiblity *JQUERY
  23. //calls the function on each message-container in a document, including ones added by livelinks
  24. function livelinks(func,extraParams){
  25. if(extraParams==undefined)
  26. extraParams=null;
  27. //run the function on the message-containers currently on the page
  28. $('#u0_1 .message-container').each(function(i,container){
  29. func(container,extraParams);
  30. });
  31. //run it on any message-containers added in the future
  32. $('#u0_1').on(
  33. 'DOMNodeInserted',
  34. extraParams,
  35. function(e){
  36. if($(e.target).children('.message-container').length){
  37. $(e.target).children('.message-container').each(function(i,container){
  38. func(container,e.data);
  39. });
  40. }
  41. }
  42. );
  43. }
  44.  
  45. //adds a style to a document and returns the style object *JQUERY
  46. //css is a string, id is an optional string that determines the object's id
  47. function addStyle(css,id){
  48. //create a style
  49. var style=$('<style type="text/css">');
  50. //add the css data to it
  51. style.html(css);
  52. if(id){
  53. //remove any style that has our id
  54. $('#'+id).remove();
  55. //give our style the id after removing the other stuff. idk if it matters, but i'm too lazy to find out
  56. style.attr('id',id);
  57. }
  58. //add the style into the head
  59. $('head').append(style);
  60. //we're outta here
  61. return style;
  62. }
  63.  
  64. //tags message-tops with userids
  65. //should call it with livelinks imo *JQUERY
  66. function userids(container){
  67. $(container).find('.message-top').each(function(i,top){
  68. top=$(top);
  69. //get userid attribute from the profile link
  70. top.attr('userID',top.children('a[href*="user="]').attr('href').split('user=')[1]);
  71. });
  72. }
  73.  
  74. //puts the message body of any quoted-message in its own message div like normal messages for easier styling(hiding)
  75. //livelinks ready *JQUERY
  76. function rearrangeQuotes(container){
  77. //this is a for loop or something
  78. $(container).find('.quoted-message').each(function(i,quote){
  79. quote=$(quote);
  80. //create message div for quote
  81. var quoteBody=$('<div class="message">');
  82. //add everything but the message-top to the message div
  83. quote.contents().each(function(i2,node){
  84. node=$(node);
  85. //make sure we don't do shit with an already parsed quote
  86. if(!node.hasClass('message-top')&&!node.hasClass('message')){
  87. quoteBody.append(node);
  88. }
  89. });
  90. //add the new message div to the quoted-message if it's got anything in it
  91. if(quoteBody.contents()[0]){
  92. quote.append(quoteBody);
  93. }
  94. });
  95. }
  96.  
  97. //adds hidden class to posts of ignorated users
  98. //needs stuff and jquery
  99. function ignorate(container){
  100. rearrangeQuotes(container);
  101. userids(container);
  102. //get the messages and such
  103. $(container).find('.message-top').each(function(i,top){
  104. top=$(top);
  105. //check against each ignorated id
  106. IMAGENORATED.each(function(j,id){
  107. if(top.attr('userID')==id){
  108. //do the thing in the function and stuff
  109. hideImages(top.parent().find('.message:first'));
  110. //this guy breaks the loop
  111. return;
  112. }
  113. });
  114. });
  115. //do shit for blank quotes
  116. $(container).find('.quoted-message[msgid=""]>.message').each(function(i,message){
  117. message=$(message);
  118. //get appropriate userID
  119. //this could be inside a quote or directly inside a message
  120. var parentID=message.parent().parent().prev().attr('userID')?
  121. message.parent().parent().prev().attr('userID'):
  122. message.parent().parent().parent().parent().parent().prev().attr('userID');
  123. //find out if parent is imagenorated
  124. IMAGENORATED.each(function(j,id){
  125. if(parentID==id){
  126. //do the thing in the function and stuff
  127. hideImages(message);
  128. //this guy breaks the loop
  129. return;
  130. }
  131. });
  132. });
  133. }
  134.  
  135. //take a message element and turn images into links in it
  136. function hideImages(message){
  137. //aah we gotta do the same thing in multiple places
  138. function hider(i,img){
  139. img=$(img);
  140. //make sure you don't gots links turned on
  141. if(img.children()[0]){
  142. //hide image
  143. img.children().addClass('hidden');
  144. //get image name
  145. var name=decodeURIComponent(img[0].href.substring(img[0].href.lastIndexOf('/')+1));
  146. //stick name in link content
  147. img.append(name);
  148. //add a br tag after the link
  149. img.after('<br>');
  150. }
  151. }
  152.  
  153. //make sure we're only getting the imgs elements from this message and not subordinate ones
  154. message.children('.imgs').find('a').each(hider);
  155. //shit in spoilers oh god this is so long i wish i could select descendents of the selection context with find()
  156. message.children('.spoiler_closed,.spoiler_open').children('.spoiler_on_open').children('.imgs').find('a').each(hider);
  157. }
  158.  
  159. //tag posts with userids
  160. livelinks(ignorate);
  161. addStyle('.hidden{display:none}','hidden');