Guest User

Reddit Collapse Children Buttons

a guest
Mar 10th, 2010
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Reddit Bookmarklets for Comments
  3. // @description    Add bookmarklets next to "sorted by:" on the comment pages.
  4. // @version        1.0
  5. // @date           2010.03.10
  6. // @include        http://*.reddit.com/r/*/comments/*
  7. // @include        http://reddit.com/r/*/comments/*
  8. // ==/UserScript==
  9.  
  10. (function() {
  11.  
  12. var bookmarklets = new Array()
  13.     bookmarklets[0] = "javascript:%20function%20show_images(find_string,%20gonewild){var%20gonewild%20=%20gonewild%20||%20'';var%20x=%20$(\".content\").find(find_string).each(function(){var%20re%20=%20new%20RegExp(\"[^a-zA-Z]\"+gonewild+\"[^a-zA-Z]\",\"i\");var%20href=$(this).attr(\"href\");var%20title_text=$(this).text();if((!$(this).hasClass(\"drowsapMorphed\"))%20&&%20($(this).next(\".drowsapMorphed\").length==0)%20&&%20href%20&&%20(gonewild%20==''%20||%20title_text.match(re))%20&&(href.indexOf('imgur.')>=0%20||%20href.indexOf('.jpeg')>=0%20||%20href.indexOf('.jpg')>=0%20||%20href.indexOf('.gif')>=0)){var%20ext%20=(href.indexOf('imgur.')>=0%20&&%20href.indexOf('.jpg')<0%20&&%20href.indexOf('.png')<0%20&&%20href.indexOf('.gif')<0)%20?%20'.jpg'%20:'';%20var%20img%20=%20$(\"<a%20class='drowsapMorphed'%20href='\"+href+\"'%20onclick='window.open(this.href);return%20false;'%20style='display:block'><img%20style='display:block;max-width:720px;'%20src='\"+href+%20ext+\"'%20/></a>\");$(this).after(img);}});};%20show_images(\"#siteTable%20div.entry%20p.title%20a.title\");show_images(\".usertext-body%20a\");";
  14.    
  15.     bookmarklets[1] =
  16.     "javascript: var%20depth%20= 0;(function%20toggle_children()%20{$(document).find(\".comment%20.child%20.entry%20.collapsed%20.expand\").click();$(document).find(\".comment%20\"%20+%20Array(depth+1).join(\".child \")%20+%20\".entry%20.noncollapsed%20.expand\").click();})()";
  17.    
  18.     bookmarklets[2] =  
  19.     "javascript: var%20depth%20= 1;(function%20toggle_children()%20{$(document).find(\".comment%20.child%20.entry%20.collapsed%20.expand\").click();$(document).find(\".comment%20\"%20+%20Array(depth+1).join(\".child \")%20+%20\".entry%20.noncollapsed%20.expand\").click();})()";
  20.  
  21.     bookmarklets[3] =
  22.     "javascript: var%20depth%20= 2;(function%20toggle_children()%20{$(document).find(\".comment%20.child%20.entry%20.collapsed%20.expand\").click();$(document).find(\".comment%20\"%20+%20Array(depth+1).join(\".child \")%20+%20\".entry%20.noncollapsed%20.expand\").click();})()";
  23.    
  24.     bookmarklets[4] =
  25.     "javascript: var%20depth%20= 3;(function%20toggle_children()%20{$(document).find(\".comment%20.child%20.entry%20.collapsed%20.expand\").click();$(document).find(\".comment%20\"%20+%20Array(depth+1).join(\".child \")%20+%20\".entry%20.noncollapsed%20.expand\").click();})()";
  26.  
  27. var titles = new Array()
  28.     titles[0] = "View Images";
  29.     titles[1] = "0"
  30.     titles[2] = "1";
  31.     titles[3] = "2";
  32.     titles[4] = "3";
  33.    
  34. var menu = document.getElementsByClassName('menuarea')[0];
  35.  
  36. for (var i = 0; i < bookmarklets.length; i++) {
  37.     var div = document.createElement('div');
  38.     var a = document.createElement('a');
  39.     var text = document.createTextNode("[ "+titles[i]+" ]");
  40.    
  41.     a.setAttribute('href',bookmarklets[i]);
  42.     a.appendChild(text);
  43.     div.appendChild(a);
  44.     div.className = "spacer";
  45.     menu.appendChild(div);
  46. }
  47.  
  48. })();
Add Comment
Please, Sign In to add comment