Guest User

Fixed BJ pie filter

a guest
Mar 25th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Balloon Juice Disemvoweller
  3. // @namespace      http://ok-cleek.com
  4. // @description    Add the names of the people you wish to disemvowel on www.balloon-juice.com, and it will abuse thier comments in a variety of ways.
  5. // @include        http://www.balloon-juice.com/*
  6. // ==/UserScript==
  7.  
  8. /*------------------------------------------------------*/
  9. // this is the stuff you can edit
  10.  
  11. /*------------------------------------------------------
  12.   the bad guys. if you want to edit your list by hand, you can do it here.
  13.   ex:
  14.   var baddies = new Array("bad guy 1", "BADGUY2", "someone else");
  15.  
  16.   by default, this is empty because you can now add baddies directly
  17.   from the web page.
  18. ------------------------------------------------------*/
  19. var baddies = new Array();
  20.  
  21. // how to abuse the comment:
  22. // 0 = replace text with big white-on-black "REDACTED"  (see redactedText. below)
  23. // 1 = make them tell you how much they love pie
  24. var abuseStyle = 1;
  25.  
  26. // set this to true, to knock out the "Share This" gadgets
  27. var noShareThingy = true;
  28.  
  29. // contact ok-cleek.com to load addtional pie messages ?
  30. // set to false if you don't trust me.
  31. // turning this off may also speed-up rendering, since you don't
  32. // have to talk to my server before drawing the page. but then you'll
  33. // be stuck with the same old pie messages...
  34. var dynamicPieText = true;
  35.  
  36. var redactedText = "   REDACTED   ";
  37.  
  38. // don't edit below here unless you know what you're doing!
  39. /*------------------------------------------------------*/
  40.  
  41. var ambientPieListName = "cleeksBJPieList";
  42.  
  43. var redactedTextArrayBuiltIn = new Array(
  44. "Gosh, you know, I really like pie.",
  45. "It's pie for me, guys!",
  46. "All I really know for sure is that nothing picks me up like a nice piece of pie.",
  47. "Pie? You bet!",
  48. "I think that pie may be one of the best foods we have.</p><p>No, wait, <i>the</i> best food we have.",
  49. "Me, when I'm feeling down, I like some pie.",
  50. "I don't know about all this stuff, guys, but I do know that I like pie.",
  51. "Who can argue with pie? Not me.",
  52. "That all may be so, but I notice that you didn't say anything about pie.",
  53. "Peach, strawberry, apple, blueberry, pecan, even mincemeat, they're all damned good. Because they're <i>pies</i>.",
  54. "It may look like I talk about pies a lot, but I'm actually restraining myself from bringing them up more often. They're <i>that</i> good!",
  55. "Pie. Pie. Pie. Pie.</p><p>Ever notice how totally great that word sounds?",
  56. "That's great. Anyone have any pie?",
  57. "That's total crap. <i>My</i> mother made the best apple pie.",
  58. "I just ate some pie, and darned if I don't want some more already.",
  59. "I'd just like to say that I agree with all the positive comments made about pie. It's a pleasure being around commenters who have their heads on straight and really know what pie is all about.",
  60. "Excuse the language, but goddamn! Pie is good!",
  61. "When all is said and done, pie is still excellent.",
  62. "Churchill liked pie, you know. And not that Ward guy. The other one, the British guy, he liked pies.",
  63. "I'm not really sure why I like pies so much. The roundness? The delicious crust? I dunno, man, I dunno.",
  64. "I like pie. A lot.",
  65. "Pies suck!</p><p>Ha ha, I'm joking, of course. Pies RULE!!",
  66. "You guys don't mention pie enough.",
  67. "For God loves us so, he gave us pie.",
  68. "Imagine a world without pie. Sad, isn't it?",  
  69. "OT: Pie!",
  70. "Getting back on topic: Pie is not only delicious, it's round, too!",
  71. "I thought we were talking about pie?",
  72. "You can have your cakes, petit fors, and tarts. For me it's pie, or nothing at all!",
  73. "Your comment reminds me, I could really use some pie!",
  74. "If we're not talking about pie, I don't want any part of it.",
  75. "I don't want to live in a world without pie.",
  76. "Q: What's round, brown and full of hot steamy goodness?<br><br>A: <b>PIE!</b>",
  77. "So, if it comes to that, and I'm not saying it will, but if it does, <i>what about the pie</i>?",
  78. "I think you misunderstand; I'm really talking about pie.",
  79. "Pie!",
  80. "Give me pie lots of pie / 'neath the starry skies above / Don't fence me in - without pie, that is.",
  81. "I pledge allegiance <i>to pie!</i>",
  82. "Ever see \"American Pie\"? That's how much I like pie.",
  83. "What's hot, moist, and crusty around the edges? Pie!",
  84. "It doesn't always have to be steamy you know. Some cold pies can be excellent as well!",
  85. "In the beginning, there was pie. Praise Jesus!",
  86. "This is a fascinating topic, but I have to go now. The pie is ready.",
  87. "The sad part is that this entire controversy could end right here, if we could all sit down and share some pie!",
  88. "PIE! I EAT IT!",
  89. "You can learn more about pie, <a href='http://en.wikipedia.org/wiki/Pie'>here</a>!",
  90. "Bottom-crust-only pies may be known as tarts or tartlets.",
  91. "\"Pieing\" can result in injury to the target and assault or more serious charges against the pie throwers. Don't throw pies!",
  92. "Whether or not what we experienced was an According to Hoyle miracle is insignificant. What is significant is that I smelled pie. Pie was involved.",
  93. "Pie is the cornerstone of any nutritious breakfast.",
  94. "Your ideas intrigue me. Would you care to discuss them with me over pie?",
  95. "Sweet Home Ala<i>bama</i> but I could use me some pie!",
  96. "Remember <i>Warrant</i>? That was a good band. Any band with a song about pie knows what's important."
  97. );
  98.  
  99.  
  100. ///////////////////////////////////
  101.  
  102. getAmbientNames();
  103.  
  104. var redactedTextArray = redactedTextArrayBuiltIn;
  105.  
  106. if (dynamicPieText)
  107. {
  108.   // async call to ok-cleek.com to get additional pie text
  109.   GM_xmlhttpRequest({
  110.       method: 'GET',
  111.       url: 'http://ok-cleek.com/stuff/pie_strings.json',
  112.       headers: {
  113.           'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  114.           'Accept': 'application/atom+xml,application/xml,text/xml',
  115.       },
  116.       onload: function(responseDetails)
  117.     {
  118.       if (responseDetails.status == 200) // 200 = HTTP success
  119.       {
  120.         // parse them
  121.         var redactedTextArrayJSON = JSON.parse(responseDetails.responseText);
  122.        
  123.         // append them to the builtins
  124.         redactedTextArray = redactedTextArrayBuiltIn.concat(redactedTextArrayJSON);
  125.       }
  126.       // if that failed, we'll just use the builtins. no big deal.
  127.      
  128.       replaceText();
  129.       }
  130.   });
  131. }
  132. else
  133. {
  134.   replaceText();
  135. }
  136.  
  137. addPieControls();
  138.  
  139. killShareStuff();
  140.  
  141. ///////////////////////////////////
  142.  
  143. String.prototype.trim = function() {
  144.   return this.replace(/^\s+|\s+$/g,"");
  145. }
  146. String.prototype.ltrim = function() {
  147.   return this.replace(/^\s+/,"");
  148. }
  149. String.prototype.rtrim = function() {
  150.   return this.replace(/\s+$/,"");
  151. }
  152.    
  153. function GetFirstChildOfType(par, typ)
  154. {
  155.   if (par != null)
  156.   {
  157.       for (var i=0;i < par.childNodes.length;i++)
  158.       {
  159.           if (par.childNodes[i].tagName!=null &&
  160.           par.childNodes[i].tagName.toLowerCase()==typ)
  161.           {
  162.         return par.childNodes[i];
  163.           }
  164.       }
  165.   }
  166.   return null;
  167. }
  168.  
  169. function GetFirstChildOfTypeAndClass(par, typ, cls)
  170. {
  171.   if (par != null)
  172.   {
  173.       for (var i=0;i < par.childNodes.length;i++)
  174.       {
  175.           if (par.childNodes[i].tagName!=null &&
  176.           par.childNodes[i].tagName.toLowerCase()==typ &&
  177.           par.childNodes[i].className.toLowerCase()==cls)
  178.           {
  179.         return par.childNodes[i];
  180.           }
  181.       }
  182.   }
  183.   return null;
  184. }
  185.  
  186. function GetNextSiblingOfType(cur, typ)
  187. {
  188.   var nxt = cur.nextSibling;
  189.   while (nxt != null)
  190.   {
  191.     if (nxt.tagName!=null && nxt.tagName.toLowerCase()==typ)
  192.     {
  193.       return nxt;
  194.     }
  195.    
  196.     nxt = nxt.nextSibling;
  197.   }
  198.  
  199.   return null;
  200. }
  201.  
  202. function GetBadNameIdx(name)
  203. {
  204.   var nameText = name.toLowerCase();
  205.  
  206.   // see if the text of that href matches anyone in our baddies list
  207.   for (var baddiesIdx=0;baddiesIdx<baddies.length;baddiesIdx++)
  208.   {
  209.     if (nameText == baddies[baddiesIdx].toLowerCase())
  210.     {
  211.       return baddiesIdx;            
  212.     }
  213.   }
  214.  
  215.     return -1;
  216. }
  217.  
  218. function GetPieText()
  219. {
  220.    var pieText = "";
  221.    
  222.    if (abuseStyle==1) // pie
  223.    {
  224.       var randomNum = Math.floor( Math.random() * redactedTextArray.length );
  225.       return redactedTextArray[ randomNum ];          
  226.    }
  227.    else
  228.    {
  229.       return "<span style='background:black;color:white;font-weight:bold'>" + redactedText + "</span>";
  230.    }
  231. }
  232.  
  233. ///////////////////////////////////
  234.  
  235. function ReplaceQuotedBaddies(thisLI)
  236. {
  237.   // now what if someone has quoted a baddie?
  238.   // look for "@baddie", which is actually:
  239.   //     <p>@<a href="#comment-#######" rel="nofollow">baddie</a>:
  240.   // followed by:
  241.   //     </p><blockquote><p>text</p></blockquote>
  242.  
  243.   // first P is the comment header
  244.   commenterP = GetFirstChildOfTypeAndClass(thisLI, "strong", "");
  245.   if (commenterP!=null)
  246.   {
  247.     // next P...
  248.     var thisP = GetNextSiblingOfType(commenterP, "div");
  249.     while (thisP != null)
  250.     {
  251.        // want P with no class name
  252.        if (thisP.className=="ctext")
  253.        {
  254.           // is the next one a blockquote?
  255.           var bq = GetFirstChildOfTypeAndClass(thisP, "blockquote", "");
  256.           if (bq != null)
  257.           {
  258.             // yes! blockquote!
  259.            
  260.             // does thisP have a backlink ?
  261.             var re = new RegExp('@<a href="#comment-\\d+" rel="nofollow">(.*)</a>:(?:<.*>|[\r\n\s])*<blockquote>', "g");
  262.             if (re)
  263.             {
  264.               var m = re.exec(thisP.innerHTML);
  265.               if (m!=null && m.length==2)
  266.               {
  267.                 // it's a link. is it to a baddie?
  268.                 if (GetBadNameIdx(m[1]) != -1)
  269.                 {
  270.                   // yep. replace that blockquote.
  271.                   bq.innerHTML = GetPieText();
  272.                 }
  273.               }
  274.             }
  275.           }
  276.        }
  277.        
  278.        // loop over the rest, in case there are multiple quotes
  279.        thisP = GetNextSiblingOfType(thisP, "p");
  280.     }
  281.   }
  282. }
  283.  
  284. ///////////////////////////////////
  285.  
  286. function replaceText()
  287. {
  288.   var allLIs, thisLI;
  289.   allLIs = document.evaluate(
  290.     "//li[starts-with(@id, 'comment-')]",
  291.     document,
  292.     null,
  293.     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  294.     null);
  295.  
  296.     for (var story = 0; story < allLIs.snapshotLength; story++)
  297.     {
  298.       thisLI = allLIs.snapshotItem(story);
  299.    
  300.       var avatarfloat = null;
  301.       var dateright = null;
  302.       var commenterP = null;
  303.       var badIdx = -1;
  304.  
  305.       // find comment footer, look for match
  306.       if (thisLI.childNodes != null)
  307.       {
  308.           commenterP = GetFirstChildOfTypeAndClass(thisLI, "strong", "");
  309.           if (commenterP!=null)
  310.           {
  311.             var a = GetFirstChildOfType(commenterP, "a");
  312.              
  313.             if (a != null)
  314.             {
  315.               var name = a.text.trim();
  316.               badIdx = GetBadNameIdx(name);
  317.             }
  318.             else
  319.             {
  320.               var name = commenterP.childNodes[0].textContent.trim();
  321.               badIdx = GetBadNameIdx(name);
  322.             }
  323.           }
  324.  
  325.           // did we find anyone?
  326.           if (badIdx != -1)
  327.           {
  328.             // yarr holds the 'Reply' button
  329.             var ctext = GetFirstChildOfTypeAndClass(thisLI, "div", "ctext");
  330.             var yarr = GetFirstChildOfTypeAndClass(ctext, "div", "yarr");
  331.            
  332.             var pieText = GetPieText();
  333.          
  334.             var pText = "<p>" +
  335.                   pieText +
  336.                   "</p>";
  337.            
  338.             ctext.innerHTML = pText + "<div class=\"yarr\">" + yarr.innerHTML + "</div>";
  339.           }
  340.           else
  341.           {
  342.             ReplaceQuotedBaddies(thisLI);
  343.           }
  344.       }
  345.    }
  346. }
  347.  
  348. //////////
  349.  
  350. function killShareStuff()
  351. {
  352.   if (noShareThingy==true)
  353.   {
  354.     // <div class="addtoany_share_save_container">
  355.     var shareDivs;
  356.     shareDivs = document.evaluate(
  357.       "//div[@class='addtoany_share_save_container']",
  358.       document,
  359.       null,
  360.       XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  361.       null);
  362.    
  363.     for (var x=0;x<shareDivs.snapshotLength; x++)
  364.     {
  365.       var thisDiv = shareDivs.snapshotItem(x);
  366.       thisDiv.innerHTML = "";
  367.     }
  368.   }
  369. }
  370.  
  371. //////////
  372.  
  373. // add ambient pie names
  374. function getAmbientNames()
  375. {
  376.   var ambientList = "";
  377.  
  378.   var ambientListJSON = GM_getValue( ambientPieListName, "");
  379.   if (ambientListJSON != "")
  380.   {
  381.     ambientList = JSON.parse(ambientListJSON);
  382.     baddies = baddies.concat(ambientList);
  383.   }
  384. }
  385.  
  386. //////////
  387.  
  388. Array.prototype.unique = function()
  389. {
  390.   var o = {}, i, l = this.length, r = [];
  391.   for(i=0; i<l;i+=1) o[this[i]] = this[i];
  392.   for(i in o) r.push(o[i]);
  393.   return r;
  394. };
  395.  
  396. function removeByElement(arrayName, arrayElement)
  397. {
  398.   for(var i=0; i<arrayName.length;i++ )
  399.   {
  400.     if(arrayName[i]==arrayElement)
  401.       arrayName.splice(i,1);
  402.   }
  403. }
  404.  
  405.  
  406. function addToAmbientPieFilters(targetName)
  407. {
  408.   var listJSON = GM_getValue( ambientPieListName, "");
  409.  
  410.   var list;
  411.   if (listJSON != "")
  412.   {
  413.     list = JSON.parse(listJSON);
  414.     list.push(targetName);
  415.     list = list.unique();
  416.   }
  417.   else
  418.   {
  419.     list = new Array(targetName)
  420.   }
  421.  
  422.   var js_list = JSON.stringify(list);
  423.  
  424.   GM_setValue( ambientPieListName, js_list );
  425. }
  426.  
  427. //////////
  428.  
  429. function removeFromAmbientPieFilters(targetName)
  430. {
  431.   var listJSON = GM_getValue( ambientPieListName, "");
  432.  
  433.   var list;
  434.   if (listJSON != "")
  435.   {
  436.     list = JSON.parse(listJSON);
  437.     removeByElement(list, targetName);
  438.     list = list.unique();
  439.    
  440.     removeByElement(baddies, targetName);
  441.   }
  442.   else
  443.   {
  444.     list = new Array(targetName)
  445.   }
  446.  
  447.   var js_list = JSON.stringify(list);
  448.  
  449.   GM_setValue( ambientPieListName, js_list );
  450. }
  451.  
  452. //////////
  453.  
  454. function doAddPie()
  455. {
  456.   var txt = getSelText() + ''; // + '' to cvt to string
  457.   txt = txt.trim();
  458.  
  459.   if (txt != "")
  460.   {
  461.     if (confirm('Add "' + txt + '" to pie filter?'))
  462.     {
  463.       addToAmbientPieFilters(txt);
  464.       getAmbientNames();
  465.       replaceText();
  466.     }
  467.   }
  468. }
  469.  
  470. //////////
  471.  
  472. function doRemovePie()
  473. {
  474.   var txt = getSelText() + ''; // + '' to cvt to string
  475.   txt = txt.trim();
  476.  
  477.   if (txt != "")
  478.   {
  479.     if (confirm('Remove "' + txt + '" from pie filter?'))
  480.     {
  481.       removeFromAmbientPieFilters(txt);
  482.       location.reload(true);
  483.     }
  484.   }
  485. }
  486.  
  487. //////////
  488.  
  489. function doQuote()
  490. {
  491.     var txt = getSelText();
  492.     insertAtCaret("comment", "<blockquote>" + txt + "</blockquote>");
  493. }
  494.  
  495. function insertAtCaret(areaId,text)
  496. {
  497.   var txtarea = document.getElementById(areaId);
  498.   var scrollPos = txtarea.scrollTop;
  499.   var strPos = 0;
  500.   var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) );
  501.   if (br == "ie")
  502.   {
  503.     txtarea.focus();
  504.     var range = document.selection.createRange();
  505.     range.moveStart ('character', -txtarea.value.length);
  506.     strPos = range.text.length;
  507.   }
  508.   else if (br == "ff")
  509.     strPos = txtarea.selectionStart;
  510.   var front = (txtarea.value).substring(0,strPos);
  511.   var back = (txtarea.value).substring(strPos,txtarea.value.length);
  512.   txtarea.value=front+text+back;
  513.   strPos = strPos + text.length;
  514.   if (br == "ie")
  515.   {
  516.     txtarea.focus();
  517.     var range = document.selection.createRange();
  518.     range.moveStart ('character', -txtarea.value.length);
  519.     range.moveStart ('character', strPos);
  520.     range.moveEnd ('character', 0);
  521.     range.select();
  522.   }
  523.   else if (br == "ff")
  524.   {
  525.     txtarea.selectionStart = strPos;
  526.     txtarea.selectionEnd = strPos;
  527.     txtarea.focus();
  528.   }
  529.   txtarea.scrollTop = scrollPos;
  530. }
  531.  
  532. //////////
  533.  
  534. function getSelText()
  535. {
  536.   var txt = '';
  537.   if (window.getSelection)
  538.   {
  539.     txt = window.getSelection();
  540.   }
  541.   else if (document.getSelection) // FireFox
  542.   {
  543.     txt = document.getSelection();
  544.   }
  545.   else if (document.selection)  // IE 6/7
  546.   {
  547.     txt = document.selection.createRange().text;
  548.   }
  549.  
  550.   return txt;
  551. }
  552.  
  553. //////////
  554.  
  555. function addButtonListeners()
  556. {
  557.   var button1 = document.getElementById("cleeksAddPieButton");
  558.   button1.addEventListener('click',doAddPie,true);
  559.  
  560.   var button2 = document.getElementById("cleeksRemovePieButton");
  561.   button2.addEventListener('click',doRemovePie,true);
  562.  
  563.   var button3 = document.getElementById("cleeksQuoteButton");
  564.   button3.addEventListener('click',doQuote,true);
  565. }
  566.  
  567. //////////
  568.  
  569. function addPieControls()
  570. {
  571.   var commentForm;
  572.   commentForm = document.evaluate(
  573.     "//form[@id='commentform']",
  574.     document,
  575.     null,
  576.     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  577.     null);
  578.    
  579.     if (commentForm.snapshotLength == 1)
  580.     {
  581.       var thisDiv = commentForm.snapshotItem(0);
  582.      
  583.       // try to make the pie box as wide as the comment box
  584.       var taw = "100%";
  585.       var frm = GetFirstChildOfType(thisDiv, "form");
  586.       if (frm != null)
  587.       {
  588.         var ta = GetFirstChildOfType(frm, "textarea");
  589.         if (ta != null)
  590.         {
  591.          
  592.           taw = ta.offsetWidth;
  593.           taw += 'px';
  594.         }
  595.       }
  596.      
  597.       // can't touch the innerHTML of the comment form, breaks other JS on the page.
  598.       // so, do it the OO/DOM way...
  599.       var el = document.createElement("div");
  600.       el.innerHTML =
  601.         '&nbsp;Pie filter stuff&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
  602.         '<input id="cleeksAddPieButton" type="button" value="Add selected" style="color:#404040" title="Highlight the person\'s name and click this to add him/her to your pie filter."/>' +
  603.         '&nbsp;' +
  604.         '<input id="cleeksRemovePieButton" type="button" value="Remove selected"  style="color:#404040" title="Highlight the person\'s name and click this to remove him/her from your pie filter."/>' +
  605.         '&nbsp;' +
  606.         '<input id="cleeksQuoteButton" type="button" value="Quote"  style="color:#404040" title="Copies and blockquotes the selected text into the comment box."/>';
  607.        
  608.       el.style.color = '#606060';
  609.       el.style.border='solid 1px #b0b0b0';
  610.       el.style.padding='2px';
  611.       el.style.backgroundColor='#f0f0f0';
  612.       el.style.width = taw;
  613.  
  614.       thisDiv.appendChild(el);      
  615.  
  616.       addButtonListeners();
  617.     }
  618. }
Advertisement
Add Comment
Please, Sign In to add comment