Advertisement
Guest User

SpookyX v21

a guest
Mar 27th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // Displayable Name of your script
  3. // @name           SpookyX
  4.  
  5. // Brief description
  6. // @description    Enhances functionality of FoolFuuka boards. Devloped further for more comfortable ghost-posting on the moe archives.
  7.  
  8. // Your name, copyright  
  9. // @author          GNH
  10. // @copyright      2014, GNH
  11.  
  12. // Version Number
  13. // @version        20
  14.  
  15. // @include          https://*4plebs.org/*
  16. // @include          http://*4plebs.org/*
  17. // @include          https://archive.moe/*
  18. // @include          http://*loveisover.me/*
  19. // @include          https://*loveisover.me/*
  20. // @include          http://*imcute.yt/*
  21. // @include          https://*imcute.yt/*
  22. // @include          http://boards.foolz.us/*
  23. // @include          https://boards.foolz.us/*
  24. // @include          https://*nyafuu.org/*
  25. // @include          http://*nyafuu.org/*
  26. // @include          https://*fgts.jp/*
  27. // @include          http://*fgts.jp/*
  28. // @include          https://*not4plebs.org/*
  29. // @include          http://*not4plebs.org/*
  30.  
  31. // @grant       none
  32.  
  33. // ==/UserScript==
  34.  
  35. /* USER OPTIONS START */
  36. var imgSites = "puu.sh|i.imgur.com|data.archive.moe|i.4cdn.org|i0.kym-cdn.com|[\\S]*.deviantart.net|a.pomf.se"; // Sites to embed images from
  37. var imgNumMaster = 1; // Max number of images to embed
  38. var autoplayVids = false; // Make embedded videos play automatically (they start muted, expanding unmutes)
  39. var hideQROptions = true; // Make the reply options hidden by default in the quick reply
  40. var features = {
  41.     "postCounter":false,   // Add a post counter to the reply box
  42.     "inlineImages":true,   // Load full-size images in the thread, enable click to expand
  43.     "hidePosts":false,     // Allow user to hide posts manually
  44.     "newPosts":true,       // Reflect new posts in the tab name
  45.     "embedImages":true,    // Embed image links in thread
  46.     "inlineReplies":true,  // Click replies to expand them inline
  47.     "postQuote":true,      // Clicking the post number will insert highlighted text into the reply box
  48.     "filter":false,          // Hide undesirable posts from view
  49.     "labelYourPosts":true  // Add '(You)' to your posts and links that point to them
  50. };
  51. var filterCharThreshold = 100; // Filter posts with less than this number of characters
  52. var filteredStringsT0 = [    // List of Tier 0 strings to filter for. Capitalisation sensitive
  53.     //"[\\S]*(a{4,}|b{4,}|c{4,}|d{4,}|e{4,}|f{4,}|g{4,}|h{4,}|i{4,}|j{4,}|k{4,}|l{4,}|m{4,}|n{4,}|o{4,}|p{4,}|q{4,}|r{4,}|s{4,}|t{4,}|u{4,}|v{4,}|w{4,}|x{4,}|y{4,}|z{4,})[\\S]*",
  54.     "[\\S]*(e{4,}|E{4,}|i{4,}|I{4,}|o{4,}|O{4,}|u{4,}|U{4,})[\\S]*",
  55.     "E(G|g)(O|o)(-kun|kun)?"
  56. ];
  57. var filteredStringsT1 = [    // List of Tier 1 strings to filter for
  58.     "daki[\\S]*",
  59.     "ded",
  60.     "ayy lmao",
  61.     "incest",
  62.     "imoutos?",
  63.     "moonrunes",
  64.     "tale[\\S]*[^( of witches)]",
  65.     "ree+[\\S]*",
  66.     "boogeyman",
  67.     "normies"
  68. ];
  69. var filteredStringsT2 = [    // List of Tier 2 strings to filter for
  70.     "quest whe?n[\?]*",
  71.     "test",
  72.     "tsukaima"
  73. ];
  74. var filteredTrips = [       // List of tripcodes to filter for
  75.     "!!/90sanF9F3Z"
  76. ];
  77. var filteredNames = [       // List of names to filter for
  78.     "久保島のミズゴロウ"
  79. ];
  80. /* USER OPTIONS END */
  81.  
  82. var newPostCount = 0;
  83. var DocumentTitle = document.title;
  84. var ignoreInline = ['v'];
  85. var rulesBox = $(".rules_box").html();
  86. if(autoplayVids){var autoplayVid = "autoplay"}else{var autoplayVid=""};
  87. var threadID;
  88. var queuedYouLabels = [];
  89.  
  90. function ThreadUpdate(features) {
  91.     if (features.postCounter){postCounter();}  
  92.     if (features.inlineImages){inlineImages();}
  93.     if (features.hidePosts){hidePosts();}
  94.     if (features.newPosts){newPosts();}
  95.     if (features.embedImages){embedImages();}
  96.     if (features.inlineReplies){inlineReplies();}
  97.     if (features.postQuote){postQuote();}
  98.     if (features.filter){filter();}
  99. }
  100.  
  101. $.fn.elemText = function() {
  102.     var text = '';
  103.     this.each(function() {
  104.         $(this).contents().each(function() {
  105.             if (this.nodeType == Node.TEXT_NODE)
  106.                 text += this.textContent;
  107.         });
  108.     });
  109.     return text;
  110. };
  111.  
  112. var escapeRegExp;
  113.  
  114. (function () {
  115.     // Referring to the table here:
  116.     // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/regexp
  117.     // these characters should be escaped
  118.     // \ ^ $ * + ? . ( ) | { } [ ]
  119.     // These characters only have special meaning inside of brackets
  120.     // they do not need to be escaped, but they MAY be escaped
  121.     // without any adverse effects (to the best of my knowledge and casual testing)
  122.     // : ! , =
  123.     // my test "~!@#$%^&*(){}[]`/=?+\|-_;:'\",<.>".match(/[\#]/g)
  124.  
  125.     var specials = [
  126.         // order matters for these
  127.         "-"
  128.         , "["
  129.         , "]"
  130.         // order doesn't matter for any of these
  131.         , "/"
  132.         , "{"
  133.         , "}"
  134.         , "("
  135.         , ")"
  136.         , "*"
  137.         , "+"
  138.         , "?"
  139.         , "."
  140.         , "\\"
  141.         , "^"
  142.         , "$"
  143.         , "|"
  144.     ]
  145.  
  146.     // I choose to escape every character with '\'
  147.     // even though only some strictly require it when inside of []
  148.     , regex = RegExp('[' + specials.join('\\') + ']', 'g')
  149.     ;
  150.     escapeRegExp = function (str) {
  151.         return str.replace(regex, "\\$&");
  152.     };
  153.  
  154.     // test escapeRegExp("/path/to/res?search=this.that")
  155. }());
  156.  
  157. shortcut = {
  158.     'all_shortcuts':{},//All the shortcuts are stored in this array
  159.     'add': function(shortcut_combination,callback,opt) {
  160.         //Provide a set of default options
  161.         var default_options = {
  162.             'type':'keydown',
  163.             'propagate':false,
  164.             'disable_in_input':false,
  165.             'target':document,
  166.             'keycode':false
  167.         };
  168.         if(!opt) opt = default_options;
  169.         else {
  170.             for(var dfo in default_options) {
  171.                 if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
  172.             }
  173.         }
  174.  
  175.         var ele = opt.target;
  176.         if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
  177.         var ths = this;
  178.         shortcut_combination = shortcut_combination.toLowerCase();
  179.  
  180.         //The function to be called at keypress
  181.         var func = function(e) {
  182.             e = e || window.event;
  183.  
  184.             if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
  185.                 var element;
  186.                 if(e.target) element=e.target;
  187.                 else if(e.srcElement) element=e.srcElement;
  188.                 if(element.nodeType==3) element=element.parentNode;
  189.  
  190.                 if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
  191.             }
  192.  
  193.             //Find Which key is pressed
  194.             if (e.keyCode) code = e.keyCode;
  195.             else if (e.which) code = e.which;
  196.             var character = String.fromCharCode(code).toLowerCase();
  197.  
  198.             if(code == 188) character=","; //If the user presses , when the type is onkeydown
  199.             if(code == 190) character="."; //If the user presses , when the type is onkeydown
  200.  
  201.             var keys = shortcut_combination.split("+");
  202.             //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
  203.             var kp = 0;
  204.  
  205.             //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
  206.             var shift_nums = {
  207.                 "`":"~",
  208.                 "1":"!",
  209.                 "2":"@",
  210.                 "3":"#",
  211.                 "4":"$",
  212.                 "5":"%",
  213.                 "6":"^",
  214.                 "7":"&",
  215.                 "8":"*",
  216.                 "9":"(",
  217.                 "0":")",
  218.                 "-":"_",
  219.                 "=":"+",
  220.                 ";":":",
  221.                 "'":"\"",
  222.                 ",":"<",
  223.                 ".":">",
  224.                 "/":"?",
  225.                 "\\":"|"
  226.             };
  227.             //Special Keys - and their codes
  228.             var special_keys = {
  229.                 'esc':27,
  230.                 'escape':27,
  231.                 'tab':9,
  232.                 'space':32,
  233.                 'return':13,
  234.                 'enter':13,
  235.                 'backspace':8,
  236.  
  237.                 'scrolllock':145,
  238.                 'scroll_lock':145,
  239.                 'scroll':145,
  240.                 'capslock':20,
  241.                 'caps_lock':20,
  242.                 'caps':20,
  243.                 'numlock':144,
  244.                 'num_lock':144,
  245.                 'num':144,
  246.  
  247.                 'pause':19,
  248.                 'break':19,
  249.  
  250.                 'insert':45,
  251.                 'home':36,
  252.                 'delete':46,
  253.                 'end':35,
  254.  
  255.                 'pageup':33,
  256.                 'page_up':33,
  257.                 'pu':33,
  258.  
  259.                 'pagedown':34,
  260.                 'page_down':34,
  261.                 'pd':34,
  262.  
  263.                 'left':37,
  264.                 'up':38,
  265.                 'right':39,
  266.                 'down':40,
  267.  
  268.                 'f1':112,
  269.                 'f2':113,
  270.                 'f3':114,
  271.                 'f4':115,
  272.                 'f5':116,
  273.                 'f6':117,
  274.                 'f7':118,
  275.                 'f8':119,
  276.                 'f9':120,
  277.                 'f10':121,
  278.                 'f11':122,
  279.                 'f12':123
  280.             };
  281.  
  282.             var modifiers = {
  283.                 shift: { wanted:false, pressed:false},
  284.                 ctrl : { wanted:false, pressed:false},
  285.                 alt  : { wanted:false, pressed:false},
  286.                 meta : { wanted:false, pressed:false} //Meta is Mac specific
  287.             };
  288.  
  289.             if(e.ctrlKey) modifiers.ctrl.pressed = true;
  290.             if(e.shiftKey)  modifiers.shift.pressed = true;
  291.             if(e.altKey)  modifiers.alt.pressed = true;
  292.             if(e.metaKey)   modifiers.meta.pressed = true;
  293.  
  294.             for(var i=0; k=keys[i],i<keys.length; i++) {
  295.                 //Modifiers
  296.                 if(k == 'ctrl' || k == 'control') {
  297.                     kp++;
  298.                     modifiers.ctrl.wanted = true;
  299.  
  300.                 } else if(k == 'shift') {
  301.                     kp++;
  302.                     modifiers.shift.wanted = true;
  303.  
  304.                 } else if(k == 'alt') {
  305.                     kp++;
  306.                     modifiers.alt.wanted = true;
  307.                 } else if(k == 'meta') {
  308.                     kp++;
  309.                     modifiers.meta.wanted = true;
  310.                 } else if(k.length > 1) { //If it is a special key
  311.                     if(special_keys[k] == code) kp++;
  312.  
  313.                 } else if(opt['keycode']) {
  314.                     if(opt['keycode'] == code) kp++;
  315.  
  316.                 } else { //The special keys did not match
  317.                     if(character == k) kp++;
  318.                     else {
  319.                         if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
  320.                             character = shift_nums[character];
  321.                             if(character == k) kp++;
  322.                         }
  323.                     }
  324.                 }
  325.             }
  326.  
  327.             if(kp == keys.length &&
  328.                modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
  329.                modifiers.shift.pressed == modifiers.shift.wanted &&
  330.                modifiers.alt.pressed == modifiers.alt.wanted &&
  331.                modifiers.meta.pressed == modifiers.meta.wanted) {
  332.                 callback(e);
  333.  
  334.                 if(!opt['propagate']) { //Stop the event
  335.                     //e.cancelBubble is supported by IE - this will kill the bubbling process.
  336.                     e.cancelBubble = true;
  337.                     e.returnValue = false;
  338.  
  339.                     //e.stopPropagation works in Firefox.
  340.                     if (e.stopPropagation) {
  341.                         e.stopPropagation();
  342.                         e.preventDefault();
  343.                     }
  344.                     return false;
  345.                 }
  346.             }
  347.         }
  348.         this.all_shortcuts[shortcut_combination] = {
  349.             'callback':func,
  350.             'target':ele,
  351.             'event': opt['type']
  352.         };
  353.         //Attach the function with the event
  354.         if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
  355.         else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
  356.         else ele['on'+opt['type']] = func;
  357.     },
  358.  
  359.     //Remove the shortcut - just specify the shortcut and I will remove the binding
  360.     'remove':function(shortcut_combination) {
  361.         shortcut_combination = shortcut_combination.toLowerCase();
  362.         var binding = this.all_shortcuts[shortcut_combination];
  363.         delete(this.all_shortcuts[shortcut_combination])
  364.         if(!binding) return;
  365.         var type = binding['event'];
  366.         var ele = binding['target'];
  367.         var callback = binding['callback'];
  368.  
  369.         if(ele.detachEvent) ele.detachEvent('on'+type, callback);
  370.         else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
  371.         else ele['on'+type] = false;
  372.     }
  373. }
  374.  
  375. var getBoard = function() {
  376.     URL = document.URL;
  377.     return URL.split("/")[3];
  378. }
  379.  
  380. var inlineImages = function()
  381. {
  382.     // I Believe because I'm setting the src of the thumbnail to the full image right away,
  383.     // it also causes the images to be prefetched
  384.     $('.thread_image_box').each(function(index,currentImage) {
  385.         if ($(currentImage).data("inline") != "true"){
  386.             //$(currentImage).find('a').each(function() {
  387.             $(currentImage).find('>a').each(function() {
  388.                 fullImage = $(this).attr('href');
  389.                 //    if (!fullImage.match(/thumb(-[23])?/)){
  390.                 //        if (!fullImage.match(/search(-[23])?/)){
  391.                 //            if (!fullImage.match(/redirect?/)){
  392.                 //                if (!fullImage.match(/download/)){
  393.                 if (fullImage.match(/\.webm$/)){ // Handle post webms
  394.                     $(currentImage).html('<video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+fullImage+'" type="video/webm"></video>');
  395.                 }else if (!fullImage.match(/(\.pdf|\.swf)$/)){
  396.                     $(currentImage).find('img').each(function()  {
  397.                         $(this).attr('src',fullImage);
  398.                         $(this).removeAttr('width');
  399.                         $(this).removeAttr('height');
  400.                         if ($(this).data("handled") != "true"){
  401.                             if ($(this).hasClass("thread_image")){ // Handle OP images
  402.                                 $(this).data("handled","true");
  403.                                 $(this).addClass("smallImageOP");
  404.                                 $(this).click(function(e){
  405.                                     if (!e.originalEvent.ctrlKey && e.which == 1){
  406.                                         e.preventDefault();
  407.                                         $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
  408.                                         $(this).toggleClass("smallImageOP");
  409.                                         $(this).toggleClass("bigImage");
  410.                                     }
  411.                                 });
  412.                             }else{ // Handle post images
  413.                                 $(this).addClass("smallImage");
  414.                                 $(this).click(function(e){
  415.                                     if (!e.originalEvent.ctrlKey && e.which == 1){
  416.                                         e.preventDefault();
  417.                                         $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
  418.                                         $(this).toggleClass("smallImage");
  419.                                         $(this).toggleClass("bigImage");
  420.                                     }
  421.                                 });
  422.                             }
  423.                         }
  424.                     });
  425.                 }
  426.                 //              }
  427.                 //          }    
  428.                 $(currentImage).data("inline","true");
  429.                 //      }
  430.                 //  }
  431.             });
  432.         }
  433.     });
  434.  
  435.     $('video').each(function(index,currentVideo) {
  436.         if ($(currentVideo).data("inline") != "true"){
  437.             $(this).click(function(e){
  438.                 //e.preventDefault();
  439.                 if ($(this).hasClass("fullVideo")){
  440.                     this.muted=true;
  441.                     $(this).attr('width',"125");
  442.                     $(this).removeAttr('controls');
  443.                     $(this).removeClass("fullVideo");
  444.                 }else{
  445.                     $(this).removeAttr('width');
  446.                     $(this).attr('controls',"");
  447.                     $(this).addClass("fullVideo");
  448.                     this.muted=false;
  449.                 }
  450.             });
  451.             $(currentVideo).data("inline","true");
  452.         }
  453.     });
  454. }
  455.  
  456. var inlineReplies = function(){
  457.     $('article.post').each(function(index,currentPost) {
  458.         if ($(currentPost).data("inline") != "true"){
  459.             $(this).addClass("base");
  460.         }
  461.         $(currentPost).data("inline","true");
  462.     });
  463.     $('.post_backlink > .backlink').each(function(index,currentPost) {
  464.         if ($(currentPost).data("inline") != "true"){
  465.             $(this).on("click", function(e){
  466.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  467.                     e.preventDefault();
  468.                     //e.stopPropagation();
  469.                     var postID = $(this).attr("data-post");
  470.                     var rootPostID = $(e["target"].closest('article.base')).attr('id');
  471.                     if ($(e["target"]).hasClass("inlined")){
  472.                         $(e["target"]).removeClass("inlined");
  473.                         $('.sub'+rootPostID).each(function(index,currentPost){
  474.                             $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
  475.                         });
  476.                         $('#i'+postID+'.sub'+rootPostID).remove();
  477.                     }else{
  478.                         $(e["target"]).addClass("inlined");
  479.                         $(e["target"]["parentNode"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
  480.                         $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
  481.                         $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
  482.                             if (!$(this).hasClass('sub'+rootPostID)){
  483.                                 $(this).attr("class","inline sub"+rootPostID);
  484.                             }
  485.                         });
  486.                         $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
  487.                     }
  488.                 }
  489.             });
  490.             $(currentPost).data("inline","true")
  491.         }
  492.     });
  493.     $('.text .backlink').each(function(index,currentPost) {
  494.         if ($(currentPost).data("inline") != "true"){
  495.             $(this).on("click", function(e){
  496.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  497.                     e.preventDefault();
  498.                     //e.stopPropagation();
  499.                     var postID = $(this).attr("data-post");
  500.                     var rootPostID = $(e["target"].closest('article.base')).attr('id');
  501.                     if ($(e["target"]).hasClass("inlined")){
  502.                         $(e["target"]).removeClass("inlined");
  503.                         $('.sub'+rootPostID).each(function(index,currentPost){
  504.                             $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
  505.                         });
  506.                         $('#i'+postID+'.sub'+rootPostID).remove();
  507.                     }else{
  508.                         $(e["target"]).addClass("inlined");
  509.                         $(e["target"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
  510.                         $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
  511.                         $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
  512.                             if (!$(this).hasClass('sub'+rootPostID)){
  513.                                 $(this).attr("class","inline sub"+rootPostID);
  514.                             }
  515.                         });
  516.                         $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
  517.                     }
  518.                 }
  519.             });
  520.             $(currentPost).data("inline","true")
  521.         }
  522.     });
  523. };
  524.  
  525. function getSelectionText() {
  526.     var text = "";
  527.     if (window.getSelection) {
  528.         text = window.getSelection().toString();
  529.     } else if (document.selection && document.selection.type != "Control") {
  530.         text = document.selection.createRange().text;
  531.     }
  532.     return text;
  533. }
  534.  
  535. var postQuote = function(){
  536.     $('.post_data > [data-function=quote]').each(function(index,currentPost) {
  537.         if ($(currentPost).data("quotable") != "true"){
  538.             $(this).removeAttr("data-function"); // Disable native quote function
  539.             $(this).on("click", function(e){
  540.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  541.                     e.preventDefault();
  542.                     var postnum = $(this)["0"].innerHTML;
  543.                     var input = document.getElementById('reply_chennodiscursus')
  544.  
  545.                     if (input.selectionStart != undefined)
  546.                     {
  547.                         var startPos = input.selectionStart;
  548.                         var endPos = input.selectionEnd;
  549.                         var startText = input.value.substring(0, startPos);
  550.                         var endText = input.value.substring(startPos);
  551.  
  552.                         var originalText = input.value;
  553.                         var selectedText = getSelectionText();
  554.                         if (selectedText == ""){
  555.                             var newText = startText +">>"+postnum+"\n"+ endText;
  556.                         }else{
  557.                             var newText = startText +">>"+postnum+"\n>"+ selectedText +"\n"+ endText;
  558.                         }
  559.                         document.getElementById('reply_chennodiscursus').value = originalText.replace(originalText,newText);
  560.                     }
  561.                 }
  562.             });
  563.             $(currentPost).data("quotable","true");
  564.         }
  565.     });
  566. };
  567.  
  568. var hidePosts = function()
  569. {
  570.     $('.pull-left').each(function(index, currentPost) {
  571.         if ($(currentPost).hasClass('stub')) {
  572.             $(currentPost).removeClass('stub')
  573.         }
  574.     });
  575. }
  576.  
  577. var filter = function(){
  578.     var sieveStrT0 = new RegExp("\\b("+filteredStringsT0.join("|")+")\\b"); // \b or (^|\s) works
  579.     var sieveStrT1 = new RegExp("\\b("+filteredStringsT1.join("|")+")\\b","i"); // \b or (^|\s) works
  580.     var sieveStrT2 = new RegExp("(^|\\s)("+filteredStringsT2.join("|")+")($|\\s)","i");
  581.     var sieveTrip = new RegExp("("+filteredTrips.join("|")+")");
  582.     var sieveName = new RegExp("("+filteredNames.join("|")+")");
  583.  
  584.     $('article.post').each(function(index,currentPost) {
  585.         if ($(currentPost).data("filtered") != "true"){
  586.             $(currentPost).data("filtered","true");
  587.             var postText = $(this).find('.text').elemText();
  588.             if (sieveTrip.test($(this).find('.post_tripcode').text()) || sieveName.test($(this).find('.post_author').text())){
  589.                 shitpostT2(currentPost, postText);
  590.             }else if(sieveStrT0.test(postText)){
  591.                 //console.log(postText.match(sieveStrT0));
  592.                 shitpostT0(currentPost, postText);
  593.             }else if (postText.length <= filterCharThreshold){
  594.                 if (sieveStrT1.test(postText)){
  595.                     //console.log(postText.match(sieveStrT1));
  596.                     shitpostT1(currentPost, postText);
  597.                 } else if (sieveStrT2.test(postText)){
  598.                     //console.log(postText.match(sieveStrT2));
  599.                     shitpostT2(currentPost, postText);
  600.                 }
  601.             }
  602.         }
  603.     });
  604. }
  605. function shitpostT0(post, postText){
  606.     $(post).addClass("shitpost");
  607. }
  608. function shitpostT1(post, postText){
  609.     $(post).addClass("shitpost");
  610. }
  611. function shitpostT2(post, postText){
  612.     $(post).removeClass('stub');
  613.     $(post).find('.pull-left').removeClass('stub');
  614.     var docID = $(post).find('.pull-left > button').attr("data-doc-id");
  615.     $('.doc_id_'+docID).hide();
  616.     $('.stub_doc_id_'+docID).show();
  617. }
  618.  
  619. var embedImages = function() {
  620.     $('.posts article').each(function(index, currentArticle){
  621.         if ($(currentArticle).data('imgEmbed') != 'true'){
  622.             var patt = new RegExp("http[s]?://("+imgSites+")/[^\"]*");
  623.             var imgNum = imgNumMaster - $(currentArticle).find('.thread_image_box').length;
  624.             $(currentArticle).find(".text > a, .text > .spoiler, .text > strong").each(function(index, currentLink){
  625.                 if (imgNum == 0) {
  626.                     return false;
  627.                 }
  628.                 var imglink = patt.exec($(this).html());
  629.                 if (imglink !== null){
  630.                     imgNum--;
  631.                     // var patt2 = new RegExp(escapeRegExp(imglink["0"]), 'g'); Can't see what this does, uncomment if things break again
  632.                     imglink["0"] = imglink["0"].replace(/.gifv/g, ".webm"); // Only tested to work with Imgur
  633.                     if ((/.webm/g).test(imglink["0"])){
  634.                         console.log(imglink["0"]);
  635.                         $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"></div>');
  636.                         $(currentArticle).find(".thread_image_box:first-child").html('<video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+imglink["0"]+'" type="video/webm"></video>');
  637.                     }else if ($(this).hasClass("spoiler")){
  638.                         $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><a href="'+imglink["0"]+'" target="_blank" rel="noreferrer" class="thread_image_link"><div class="spoilerText">Spoiler</div><img src="'+imglink["0"]+'" class="lazyload post_image spoilerImage smallImage"></a></div>');
  639.                     }else{
  640.                         $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><a href="'+imglink["0"]+'" target="_blank" rel="noreferrer" class="thread_image_link"><img src="'+imglink["0"]+'" class="lazyload post_image smallImage"></a></div>');
  641.                     }
  642.                     $(this).remove();
  643.                 }
  644.             });
  645.             $(currentArticle).data('imgEmbed', 'true');
  646.         }
  647.     });
  648. }
  649.  
  650. var seenPosts = function(){$('article').each(function(index, currentArticle){$(currentArticle).data('seen','true')});}
  651.  
  652. var newPosts = function() {
  653.     $('article').each(function(index, currentArticle){
  654.         if ($(currentArticle).data('seen') != 'true')
  655.         {
  656.             $(currentArticle).data('seen', 'true')
  657.             newPostCount +=1
  658.         }
  659.     });
  660.  
  661.     if (windowFocus == true) newPostCount = 0
  662.     document.title = "(" + newPostCount + ") " + DocumentTitle
  663. }
  664.  
  665. var postCounter = function() {$(".rules_box").html("<h6>Posts: " + $('.post_wrapper').length + "/400 <br> Images: " + $(".thread_image_box").length + "/250</h6>" + rulesBox)}
  666.  
  667. var bindShortcuts = function()
  668. {
  669.  
  670. }
  671.  
  672. var pokemon = ["bulbasaur","ivysaur","venusaur","charmander","charmeleon","charizard","squirtle","wartortle","blastoise","caterpie","metapod","butterfree","weedle","kakuna","beedrill","pidgey","pidgeotto","pidgeot","rattata","raticate","spearow","fearow","ekans","arbok","pikachu","raichu","sandshrew","sandslash","nidoran♀","nidorina","nidoqueen","nidoran♂","nidorino","nidoking","clefairy","clefable","vulpix","ninetales","jigglypuff","wigglytuff","zubat","golbat","oddish","gloom","vileplume","paras","parasect","venonat","venomoth","diglett","dugtrio","meowth","persian","psyduck","golduck","mankey","primeape","growlithe","arcanine","poliwag","poliwhirl","poliwrath","abra","kadabra","alakazam","machop","machoke","machamp","bellsprout","weepinbell","victreebel","tentacool","tentacruel","geodude","graveler","golem","ponyta","rapidash","slowpoke","slowbro","magnemite","magneton","farfetch'd","doduo","dodrio","seel","dewgong","grimer","muk","shellder","cloyster","gastly","haunter","gengar","onix","drowzee","hypno","krabby","kingler","voltorb","electrode","exeggcute","exeggutor","cubone","marowak","hitmonlee","hitmonchan","lickitung","koffing","weezing","rhyhorn","rhydon","chansey","tangela","kangaskhan","horsea","seadra","goldeen","seaking","staryu","starmie","mr. mime","scyther","jynx","electabuzz","magmar","pinsir","tauros","magikarp","gyarados","lapras","ditto","eevee","vaporeon","jolteon","flareon","porygon","omanyte","omastar","kabuto","kabutops","aerodactyl","snorlax","articuno","zapdos","moltres","dratini","dragonair","dragonite","mewtwo","mew","chikorita","bayleef","meganium","cyndaquil","quilava","typhlosion","totodile","croconaw","feraligatr","sentret","furret","hoothoot","noctowl","ledyba","ledian","spinarak","ariados","crobat","chinchou","lanturn","pichu","cleffa","igglybuff","togepi","togetic","natu","xatu","mareep","flaaffy","ampharos","bellossom","marill","azumarill","sudowoodo","politoed","hoppip","skiploom","jumpluff","aipom","sunkern","sunflora","yanma","wooper","quagsire","espeon","umbreon","murkrow","slowking","misdreavus","unown","wobbuffet","girafarig","pineco","forretress","dunsparce","gligar","steelix","snubbull","granbull","qwilfish","scizor","shuckle","heracross","sneasel","teddiursa","ursaring","slugma","magcargo","swinub","piloswine","corsola","remoraid","octillery","delibird","mantine","skarmory","houndour","houndoom","kingdra","phanpy","donphan","porygon2","stantler","smeargle","tyrogue","hitmontop","smoochum","elekid","magby","miltank","blissey","raikou","entei","suicune","larvitar","pupitar","tyranitar","lugia","ho-oh","celebi","treecko","grovyle","sceptile","torchic","combusken","blaziken","mudkip","marshtomp","swampert","poochyena","mightyena","zigzagoon","linoone","wurmple","silcoon","beautifly","cascoon","dustox","lotad","lombre","ludicolo","seedot","nuzleaf","shiftry","taillow","swellow","wingull","pelipper","ralts","kirlia","gardevoir","surskit","masquerain","shroomish","breloom","slakoth","vigoroth","slaking","nincada","ninjask","shedinja","whismur","loudred","exploud","makuhita","hariyama","azurill","nosepass","skitty","delcatty","sableye","mawile","aron","lairon","aggron","meditite","medicham","electrike","manectric","plusle","minun","volbeat","illumise","roselia","gulpin","swalot","carvanha","sharpedo","wailmer","wailord","numel","camerupt","torkoal","spoink","grumpig","spinda","trapinch","vibrava","flygon","cacnea","cacturne","swablu","altaria","zangoose","seviper","lunatone","solrock","barboach","whiscash","corphish","crawdaunt","baltoy","claydol","lileep","cradily","anorith","armaldo","feebas","milotic","castform","kecleon","shuppet","banette","duskull","dusclops","tropius","chimecho","absol","wynaut","snorunt","glalie","spheal","sealeo","walrein","clamperl","huntail","gorebyss","relicanth","luvdisc","bagon","shelgon","salamence","beldum","metang","metagross","regirock","regice","registeel","latias","latios","kyogre","groudon","rayquaza","jirachi","deoxys","turtwig","grotle","torterra","chimchar","monferno","infernape","piplup","prinplup","empoleon","starly","staravia","staraptor","bidoof","bibarel","kricketot","kricketune","shinx","luxio","luxray","budew","roserade","cranidos","rampardos","shieldon","bastiodon","burmy","wormadam","mothim","combee","vespiquen","pachirisu","buizel","floatzel","cherubi","cherrim","shellos","gastrodon","ambipom","drifloon","drifblim","buneary","lopunny","mismagius","honchkrow","glameow","purugly","chingling","stunky","skuntank","bronzor","bronzong","bonsly","mime jr.","happiny","chatot","spiritomb","gible","gabite","garchomp","munchlax","riolu","lucario","hippopotas","hippowdon","skorupi","drapion","croagunk","toxicroak","carnivine","finneon","lumineon","mantyke","snover","abomasnow","weavile","magnezone","lickilicky","rhyperior","tangrowth","electivire","magmortar","togekiss","yanmega","leafeon","glaceon","gliscor","mamoswine","porygon-z","gallade","probopass","dusknoir","froslass","rotom","uxie","mesprit","azelf","dialga","palkia","heatran","regigigas","giratina","cresselia","phione","manaphy","darkrai","shaymin","arceus","victini","snivy","servine","serperior","tepig","pignite","emboar","oshawott","dewott","samurott","patrat","watchog","lillipup","herdier","stoutland","purrloin","liepard","pansage","simisage","pansear","simisear","panpour","simipour","munna","musharna","pidove","tranquill","unfezant","blitzle","zebstrika","roggenrola","boldore","gigalith","woobat","swoobat","drilbur","excadrill","audino","timburr","gurdurr","conkeldurr","tympole","palpitoad","seismitoad","throh","sawk","sewaddle","swadloon","leavanny","venipede","whirlipede","scolipede","cottonee","whimsicott","petilil","lilligant","basculin","sandile","krokorok","krookodile","darumaka","darmanitan","maractus","dwebble","crustle","scraggy","scrafty","sigilyph","yamask","cofagrigus","tirtouga","carracosta","archen","archeops","trubbish","garbodor","zorua","zoroark","minccino","cinccino","gothita","gothorita","gothitelle","solosis","duosion","reuniclus","ducklett","swanna","vanillite","vanillish","vanilluxe","deerling","sawsbuck","emolga","karrablast","escavalier","foongus","amoonguss","frillish","jellicent","alomomola","joltik","galvantula","ferroseed","ferrothorn","klink","klang","klinklang","tynamo","eelektrik","eelektross","elgyem","beheeyem","litwick","lampent","chandelure","axew","fraxure","haxorus","cubchoo","beartic","cryogonal","shelmet","accelgor","stunfisk","mienfoo","mienshao","druddigon","golett","golurk","pawniard","bisharp","bouffalant","rufflet","braviary","vullaby","mandibuzz","heatmor","durant","deino","zweilous","hydreigon","larvesta","volcarona","cobalion","terrakion","virizion","tornadus","thundurus","reshiram","zekrom","landorus","kyurem","keldeo","meloetta","genesect","chespin","quilladin","chesnaught","fennekin","braixen","delphox","froakie","frogadier","greninja","bunnelby","diggersby","fletchling","fletchinder","talonflame","scatterbug","spewpa","vivillon","litleo","pyroar","flabébé","floette","florges","skiddo","gogoat","pancham","pangoro","furfrou","espurr","meowstic","honedge","doublade","aegislash","spritzee","aromatisse","swirlix","slurpuff","inkay","malamar","binacle","barbaracle","skrelp","dragalge","clauncher","clawitzer","helioptile","heliolisk","tyrunt","tyrantrum","amaura","aurorus","sylveon","hawlucha","dedenne","carbink","goomy","sliggoo","goodra","klefki","phantump","trevenant","pumpkaboo","gourgeist","bergmite","avalugg","noibat","noivern","xerneas","yveltal","zygarde","diancie","hoopa","volcanion"];
  673. function notifyMe(title, image, body){
  674.     if (!Notification){
  675.         alert('Please us a modern version of Chrome, Firefox, Opera or Firefox.');
  676.         return;
  677.     }
  678.  
  679.     if (Notification.permission !== "granted")
  680.         Notification.requestPermission();
  681.     var icon = image;
  682.     if(!Math.floor(Math.random()*8192)){
  683.         var ND = Math.floor(Math.random()*720);
  684.         icon = "http://img.pokemondb.net/sprites/black-white/shiny/"+pokemon[ND]+".png";
  685.     }
  686.  
  687.     var notification = new Notification(title, {
  688.         icon: icon,
  689.         body: body
  690.     });
  691.  
  692.     notification.onshow = function (){
  693.         setTimeout(notification.close.bind(notification), 5000);
  694.     }
  695.     notification.onclick = function (){
  696.         window.focus();
  697.     }
  698. }
  699.  
  700. if (features.labelYourPosts){
  701.     var yourPosts = localStorage.yourPosts;
  702.     if (yourPosts == undefined){
  703.         yourPosts = {};
  704.         console.log("Created post archive for the first time");
  705.     } else {
  706.         yourPosts = JSON.parse(localStorage.yourPosts);
  707.     }
  708.     window.addEventListener("beforeunload", function (e) {
  709.         if (localStorage.yourPosts == undefined){
  710.             localStorage.yourPosts = JSON.stringify(yourPosts);
  711.         } else {
  712.             localStorage.yourPosts = JSON.stringify($.extend(true, yourPosts, JSON.parse(localStorage.yourPosts)));
  713.         }
  714.         //var confirmationMessage = "\o/";
  715.  
  716.         //(e || window.event).returnValue = confirmationMessage; //Gecko + IE
  717.         //return confirmationMessage;                            //Webkit, Safari, Chrome
  718.     });
  719. }
  720.  
  721. function labelYourPosts(firstcall){
  722.     $.each(queuedYouLabels, function(i, v){ // Parse all names on pageload and with each post submission
  723.         $('#'+v+' .post_author').after('<span> (You)</span>');
  724.     });
  725.     queuedYouLabels = [];
  726.  
  727.     if (firstcall){ // Parse all backlinks present on pageload
  728.         $.each(yourPosts[threadID], function(i,v){
  729.             $('.backlink[data-post='+v+']').each(function(){
  730.                 if ($(this).data('linkedYou') != 'true'){
  731.                     this.textContent += ' (You)';
  732.                     $(this).data('linkedYou','true');
  733.                 }
  734.             });
  735.         });
  736.     }
  737. }
  738.  
  739. function labelNewPosts(response){
  740.     var newPosts = Object.keys(response[threadID]["posts"]);
  741.     $.each(newPosts, function(i,v){ // For each post returned by update
  742.         var notificationTriggered = false;
  743.         $('#'+v+' .greentext > a').each(function(i, link){ // For each post content backlink
  744.             var linkID = $(link).attr('data-post');
  745.             if ($.inArray(linkID, yourPosts[threadID])+1){ // If the link points to your post
  746.                 if (!notificationTriggered){
  747.                     notifyMe($('#'+v+' .post_poster_data').text().trim()+" replied to you","http://i.imgur.com/HTcKk4Y.png",$('#'+v+' .text').text().trim());
  748.                     notificationTriggered = true;
  749.                 }
  750.                 link.textContent += ' (You)'; // Designate the link as such
  751.             }
  752.             if ($.inArray(v, yourPosts[threadID])+1){ // If the post is your own
  753.                 var backlink = $('#'+linkID+' .post_backlink [data-post='+v+']');
  754.                 if (backlink.data('linkedYou') != 'true'){
  755.                     backlink[0].textContent += ' (You)'; // Find your post's new reply backlink and designate it too
  756.                     backlink.data('linkedYou','true');
  757.                 }
  758.             }
  759.         });
  760.     });
  761. }
  762.  
  763. var lastSubmittedContent;
  764.  
  765. function postSubmitEvent(){
  766.     if ($('#reply [type=submit]').length){
  767.         window.MutationObserver = window.MutationObserver
  768.         || window.WebKitMutationObserver
  769.         || window.MozMutationObserver;
  770.         var target =  $('#reply [type=submit]')["0"],
  771.             observer = new MutationObserver(function(mutation) {
  772.                 //console.log("Post Submit Event Triggered");
  773.                 lastSubmittedContent = $('#reply_chennodiscursus')[0].value;
  774.             }),
  775.             config = {
  776.                 attributes: true
  777.             };
  778.         observer.observe(target, config);
  779.     }
  780. }
  781.  
  782. $(document).ready(function(){
  783.     $('head').after('<script src="https://cdn.rawgit.com/madapaja/jquery.selection/master/src/jquery.selection.js"></script>'); // Pull in selection plugin (http://madapaja.github.io/jquery.selection/)
  784.     $('head').after('<style type="text/css" id="FoolX-css">.bigImage{opacity: 1!important; max-width:100%;}.smallImage{max-width:125px; max-height:125px}.smallImageOP{max-width:250px; max-height:250px}.spoilerImage{opacity: 0.1}.spoilerText{position: relative; height: 0px; font-size: 19px; top: 47px;}.forwarded{display:none}.inline{border:1px solid; display: table; margin: 2px 0;}.inlined{opacity:0.5}.post_wrapper{border-right: 1px solid #cccccc;}.post_wrapperInline{border-right:0!important; border-bottom:0!important;}.quickReply{position: fixed; top: 0; right: 0; margin: 3px !important;}.shitpost{opacity: 0.3}</style>');
  785.     windowFocus = true
  786.     $(window).focus(function(){windowFocus = true; ThreadUpdate(features)})
  787.     $(window).blur(function(){windowFocus = false})
  788.     if (hideQROptions){
  789.         $('#reply').toggleClass("showQROptions"); // Make options hidden in QR by default
  790.     }
  791.     if (features.labelYourPosts){
  792.         threadID = $('#main > article[data-thread-num]').attr('id');
  793.         if (yourPosts[threadID] == undefined){
  794.             yourPosts[threadID] = [];
  795.         } else {
  796.             queuedYouLabels = yourPosts[threadID].slice(0);
  797.             //console.log(queuedYouLabels);
  798.         }
  799.         //console.log(yourPosts);
  800.         postSubmitEvent();
  801.  
  802.         $(document).ajaxComplete(function(event, request, settings) {
  803.             //console.log(event);
  804.             //console.log(request);
  805.             //console.log(settings);
  806.             if (request.responseText != ""){
  807.                 response = JSON.parse(request.responseText);
  808.             }else{
  809.                 response = {"error":"No responseText"};
  810.             }
  811.             //console.log(response);
  812.             if (response.error != undefined){
  813.                 console.log(response.error);
  814.             }else{
  815.                 if (settings.type == "POST"){
  816.                     if (response.error == undefined ){
  817.                         for (var post in response[threadID]["posts"]) {
  818.                             //console.log(lastSubmittedContent);                    
  819.                             if(response[threadID]["posts"][post]["comment"].replace(/[\r\n]/g,'') == lastSubmittedContent.replace(/[\r\n]/g,'')){
  820.                                 yourPosts[threadID].push(post);
  821.                                 queuedYouLabels.push(post);
  822.                                 //console.log(yourPosts);
  823.                                 //console.log(queuedYouLabels);
  824.                                 labelYourPosts();
  825.                                 break;
  826.                             }
  827.                         }
  828.                         labelNewPosts(response);
  829.                     }else{
  830.                         console.log(response.error);
  831.                     }
  832.                 }else{
  833.                     if (response[threadID] != undefined){
  834.                         labelNewPosts(response);
  835.                     }else{
  836.                         console.log("Not in a thread");
  837.                     }
  838.                 }
  839.             }
  840.         });
  841.         labelYourPosts(true); // First call, add (You) to page content
  842.     }
  843. });
  844.  
  845. var executeShortcut = function(shortcut) {
  846.     //console.log(shortcut);
  847.     var input = document.getElementById('reply_chennodiscursus');
  848.  
  849.     if (input.selectionStart != undefined){
  850.         $('#reply_chennodiscursus').selection('insert', {
  851.             text: "["+shortcut+"]",
  852.             mode: 'before'
  853.         });
  854.         $('#reply_chennodiscursus').selection('insert', {
  855.             text: "[/"+shortcut+"]",
  856.             mode: 'after'
  857.         });
  858.     }
  859. }
  860.  
  861. function quickReply(){
  862.     $('#reply').toggleClass("quickReply");
  863.     $('#reply fieldset > div:nth-child(1)').css("width","");
  864.     if ($('#reply').hasClass("showQROptions")){
  865.         $('#reply fieldset > div:nth-child(2)').toggle();
  866.     }
  867. }
  868.  
  869. function quickReplyOptions(){
  870.     $('#reply').toggleClass("showQROptions");
  871.     $('#reply.quickReply fieldset > div:nth-child(2)').toggle();
  872. }
  873.  
  874. $(function(){
  875.     shortcut.add("ctrl+s", function(){ executeShortcut("spoiler")});
  876.     shortcut.add("ctrl+i", function(){ executeShortcut("i")});
  877.     shortcut.add("ctrl+b", function(){ executeShortcut("b")});
  878.     shortcut.add("ctrl+u", function(){ executeShortcut("u")});
  879.     shortcut.add("q", function(){quickReply()}, {"disable_in_input":true});
  880.     shortcut.add("ctrl+q", function(){quickReplyOptions()}, {"disable_in_input":false});
  881.  
  882.     seenPosts();
  883.     ThreadUpdate(features);
  884.     getBoard();
  885.     bindShortcuts();
  886.     window.setInterval( function(){ ThreadUpdate(features); }, 500 );
  887. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement