Advertisement
Guest User

SpookyX v20

a guest
Mar 27th, 2015
247
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 = true; // 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.     //if (features.labelYourPosts){labelYourPosts();}
  100. }
  101.  
  102. $.fn.elemText = function() {
  103.     var text = '';
  104.     this.each(function() {
  105.         $(this).contents().each(function() {
  106.             if (this.nodeType == Node.TEXT_NODE)
  107.                 text += this.textContent;
  108.         });
  109.     });
  110.     return text;
  111. };
  112.  
  113. var escapeRegExp;
  114.  
  115. (function () {
  116.     // Referring to the table here:
  117.     // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/regexp
  118.     // these characters should be escaped
  119.     // \ ^ $ * + ? . ( ) | { } [ ]
  120.     // These characters only have special meaning inside of brackets
  121.     // they do not need to be escaped, but they MAY be escaped
  122.     // without any adverse effects (to the best of my knowledge and casual testing)
  123.     // : ! , =
  124.     // my test "~!@#$%^&*(){}[]`/=?+\|-_;:'\",<.>".match(/[\#]/g)
  125.  
  126.     var specials = [
  127.         // order matters for these
  128.         "-"
  129.         , "["
  130.         , "]"
  131.         // order doesn't matter for any of these
  132.         , "/"
  133.         , "{"
  134.         , "}"
  135.         , "("
  136.         , ")"
  137.         , "*"
  138.         , "+"
  139.         , "?"
  140.         , "."
  141.         , "\\"
  142.         , "^"
  143.         , "$"
  144.         , "|"
  145.     ]
  146.  
  147.     // I choose to escape every character with '\'
  148.     // even though only some strictly require it when inside of []
  149.     , regex = RegExp('[' + specials.join('\\') + ']', 'g')
  150.     ;
  151.     escapeRegExp = function (str) {
  152.         return str.replace(regex, "\\$&");
  153.     };
  154.  
  155.     // test escapeRegExp("/path/to/res?search=this.that")
  156. }());
  157.  
  158. shortcut = {
  159.     'all_shortcuts':{},//All the shortcuts are stored in this array
  160.     'add': function(shortcut_combination,callback,opt) {
  161.         //Provide a set of default options
  162.         var default_options = {
  163.             'type':'keydown',
  164.             'propagate':false,
  165.             'disable_in_input':false,
  166.             'target':document,
  167.             'keycode':false
  168.         };
  169.         if(!opt) opt = default_options;
  170.         else {
  171.             for(var dfo in default_options) {
  172.                 if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
  173.             }
  174.         }
  175.  
  176.         var ele = opt.target;
  177.         if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
  178.         var ths = this;
  179.         shortcut_combination = shortcut_combination.toLowerCase();
  180.  
  181.         //The function to be called at keypress
  182.         var func = function(e) {
  183.             e = e || window.event;
  184.  
  185.             if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
  186.                 var element;
  187.                 if(e.target) element=e.target;
  188.                 else if(e.srcElement) element=e.srcElement;
  189.                 if(element.nodeType==3) element=element.parentNode;
  190.  
  191.                 if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
  192.             }
  193.  
  194.             //Find Which key is pressed
  195.             if (e.keyCode) code = e.keyCode;
  196.             else if (e.which) code = e.which;
  197.             var character = String.fromCharCode(code).toLowerCase();
  198.  
  199.             if(code == 188) character=","; //If the user presses , when the type is onkeydown
  200.             if(code == 190) character="."; //If the user presses , when the type is onkeydown
  201.  
  202.             var keys = shortcut_combination.split("+");
  203.             //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
  204.             var kp = 0;
  205.  
  206.             //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
  207.             var shift_nums = {
  208.                 "`":"~",
  209.                 "1":"!",
  210.                 "2":"@",
  211.                 "3":"#",
  212.                 "4":"$",
  213.                 "5":"%",
  214.                 "6":"^",
  215.                 "7":"&",
  216.                 "8":"*",
  217.                 "9":"(",
  218.                 "0":")",
  219.                 "-":"_",
  220.                 "=":"+",
  221.                 ";":":",
  222.                 "'":"\"",
  223.                 ",":"<",
  224.                 ".":">",
  225.                 "/":"?",
  226.                 "\\":"|"
  227.             };
  228.             //Special Keys - and their codes
  229.             var special_keys = {
  230.                 'esc':27,
  231.                 'escape':27,
  232.                 'tab':9,
  233.                 'space':32,
  234.                 'return':13,
  235.                 'enter':13,
  236.                 'backspace':8,
  237.  
  238.                 'scrolllock':145,
  239.                 'scroll_lock':145,
  240.                 'scroll':145,
  241.                 'capslock':20,
  242.                 'caps_lock':20,
  243.                 'caps':20,
  244.                 'numlock':144,
  245.                 'num_lock':144,
  246.                 'num':144,
  247.  
  248.                 'pause':19,
  249.                 'break':19,
  250.  
  251.                 'insert':45,
  252.                 'home':36,
  253.                 'delete':46,
  254.                 'end':35,
  255.  
  256.                 'pageup':33,
  257.                 'page_up':33,
  258.                 'pu':33,
  259.  
  260.                 'pagedown':34,
  261.                 'page_down':34,
  262.                 'pd':34,
  263.  
  264.                 'left':37,
  265.                 'up':38,
  266.                 'right':39,
  267.                 'down':40,
  268.  
  269.                 'f1':112,
  270.                 'f2':113,
  271.                 'f3':114,
  272.                 'f4':115,
  273.                 'f5':116,
  274.                 'f6':117,
  275.                 'f7':118,
  276.                 'f8':119,
  277.                 'f9':120,
  278.                 'f10':121,
  279.                 'f11':122,
  280.                 'f12':123
  281.             };
  282.  
  283.             var modifiers = {
  284.                 shift: { wanted:false, pressed:false},
  285.                 ctrl : { wanted:false, pressed:false},
  286.                 alt  : { wanted:false, pressed:false},
  287.                 meta : { wanted:false, pressed:false} //Meta is Mac specific
  288.             };
  289.  
  290.             if(e.ctrlKey) modifiers.ctrl.pressed = true;
  291.             if(e.shiftKey)  modifiers.shift.pressed = true;
  292.             if(e.altKey)  modifiers.alt.pressed = true;
  293.             if(e.metaKey)   modifiers.meta.pressed = true;
  294.  
  295.             for(var i=0; k=keys[i],i<keys.length; i++) {
  296.                 //Modifiers
  297.                 if(k == 'ctrl' || k == 'control') {
  298.                     kp++;
  299.                     modifiers.ctrl.wanted = true;
  300.  
  301.                 } else if(k == 'shift') {
  302.                     kp++;
  303.                     modifiers.shift.wanted = true;
  304.  
  305.                 } else if(k == 'alt') {
  306.                     kp++;
  307.                     modifiers.alt.wanted = true;
  308.                 } else if(k == 'meta') {
  309.                     kp++;
  310.                     modifiers.meta.wanted = true;
  311.                 } else if(k.length > 1) { //If it is a special key
  312.                     if(special_keys[k] == code) kp++;
  313.  
  314.                 } else if(opt['keycode']) {
  315.                     if(opt['keycode'] == code) kp++;
  316.  
  317.                 } else { //The special keys did not match
  318.                     if(character == k) kp++;
  319.                     else {
  320.                         if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
  321.                             character = shift_nums[character];
  322.                             if(character == k) kp++;
  323.                         }
  324.                     }
  325.                 }
  326.             }
  327.  
  328.             if(kp == keys.length &&
  329.                modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
  330.                modifiers.shift.pressed == modifiers.shift.wanted &&
  331.                modifiers.alt.pressed == modifiers.alt.wanted &&
  332.                modifiers.meta.pressed == modifiers.meta.wanted) {
  333.                 callback(e);
  334.  
  335.                 if(!opt['propagate']) { //Stop the event
  336.                     //e.cancelBubble is supported by IE - this will kill the bubbling process.
  337.                     e.cancelBubble = true;
  338.                     e.returnValue = false;
  339.  
  340.                     //e.stopPropagation works in Firefox.
  341.                     if (e.stopPropagation) {
  342.                         e.stopPropagation();
  343.                         e.preventDefault();
  344.                     }
  345.                     return false;
  346.                 }
  347.             }
  348.         }
  349.         this.all_shortcuts[shortcut_combination] = {
  350.             'callback':func,
  351.             'target':ele,
  352.             'event': opt['type']
  353.         };
  354.         //Attach the function with the event
  355.         if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
  356.         else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
  357.         else ele['on'+opt['type']] = func;
  358.     },
  359.  
  360.     //Remove the shortcut - just specify the shortcut and I will remove the binding
  361.     'remove':function(shortcut_combination) {
  362.         shortcut_combination = shortcut_combination.toLowerCase();
  363.         var binding = this.all_shortcuts[shortcut_combination];
  364.         delete(this.all_shortcuts[shortcut_combination])
  365.         if(!binding) return;
  366.         var type = binding['event'];
  367.         var ele = binding['target'];
  368.         var callback = binding['callback'];
  369.  
  370.         if(ele.detachEvent) ele.detachEvent('on'+type, callback);
  371.         else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
  372.         else ele['on'+type] = false;
  373.     }
  374. }
  375.  
  376. var getBoard = function() {
  377.     URL = document.URL;
  378.     return URL.split("/")[3];
  379. }
  380.  
  381. var inlineImages = function()
  382. {
  383.     // I Believe because I'm setting the src of the thumbnail to the full image right away,
  384.     // it also causes the images to be prefetched
  385.     $('.thread_image_box').each(function(index,currentImage) {
  386.         if ($(currentImage).data("inline") != "true"){  
  387.             //$(currentImage).find('a').each(function() {
  388.             $(currentImage).find('>a').each(function() {
  389.                 fullImage = $(this).attr('href');
  390.                 //    if (!fullImage.match(/thumb(-[23])?/)){
  391.                 //        if (!fullImage.match(/search(-[23])?/)){
  392.                 //            if (!fullImage.match(/redirect?/)){
  393.                 //                if (!fullImage.match(/download/)){
  394.                 if (fullImage.match(/\.webm$/)){ // Handle post webms
  395.                     $(currentImage).html('<div class="thread_image_box"><video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+fullImage+'" type="video/webm"></video></div>');
  396.                 }else if (!fullImage.match(/(\.pdf|\.swf)$/)){
  397.                     $(currentImage).find('img').each(function()  {
  398.                         $(this).attr('src',fullImage);
  399.                         $(this).removeAttr('width');
  400.                         $(this).removeAttr('height');
  401.                         if ($(this).data("handled") != "true"){
  402.                             if ($(this).hasClass("thread_image")){ // Handle OP images
  403.                                 $(this).data("handled","true");
  404.                                 $(this).addClass("smallImageOP");
  405.                                 $(this).click(function(e){
  406.                                     if (!e.originalEvent.ctrlKey && e.which == 1){
  407.                                         e.preventDefault();
  408.                                         $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
  409.                                         $(this).toggleClass("smallImageOP");
  410.                                         $(this).toggleClass("bigImage");
  411.                                     }
  412.                                 });
  413.                             }else{ // Handle post images
  414.                                 $(this).addClass("smallImage");
  415.                                 $(this).click(function(e){
  416.                                     if (!e.originalEvent.ctrlKey && e.which == 1){
  417.                                         e.preventDefault();
  418.                                         $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
  419.                                         $(this).toggleClass("smallImage");
  420.                                         $(this).toggleClass("bigImage");
  421.                                     }
  422.                                 });
  423.                             }
  424.                         }
  425.                     });
  426.                 }
  427.                 //              }
  428.                 //          }    
  429.                 $(currentImage).data("inline","true");
  430.                 //      }
  431.                 //  }
  432.             });
  433.         }
  434.     });
  435.  
  436.     $('video').each(function(index,currentVideo) {
  437.         if ($(currentVideo).data("inline") != "true"){
  438.             $(this).click(function(e){
  439.                 //e.preventDefault();
  440.                 if ($(this).hasClass("fullVideo")){
  441.                     this.muted =true;
  442.                     $(this).attr('width',"125");
  443.                     $(this).removeAttr('controls');
  444.                     $(this).removeClass("fullVideo");
  445.                 }else{
  446.                     $(this).removeAttr('width');
  447.                     $(this).attr('controls',"");
  448.                     $(this).addClass("fullVideo");
  449.                     this.muted =false;
  450.                 }
  451.             });
  452.             $(currentVideo).data("inline","true");
  453.         }
  454.     });
  455. }
  456.  
  457. var inlineReplies = function(){
  458.     $('article.post').each(function(index,currentPost) {
  459.         if ($(currentPost).data("inline") != "true"){
  460.             $(this).addClass("base");
  461.         }
  462.         $(currentPost).data("inline","true");
  463.     });
  464.     $('.post_backlink > .backlink').each(function(index,currentPost) {
  465.         if ($(currentPost).data("inline") != "true"){
  466.             $(this).on("click", function(e){
  467.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  468.                     e.preventDefault();
  469.                     //e.stopPropagation();
  470.                     var postID = $(this).attr("data-post");
  471.                     var rootPostID = $(e["target"].closest('article.base')).attr('id');
  472.                     if ($(e["target"]).hasClass("inlined")){
  473.                         $(e["target"]).removeClass("inlined");
  474.                         $('.sub'+rootPostID).each(function(index,currentPost){
  475.                             $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
  476.                         });
  477.                         $('#i'+postID+'.sub'+rootPostID).remove();
  478.                     }else{
  479.                         $(e["target"]).addClass("inlined");
  480.                         $(e["target"]["parentNode"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
  481.                         $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
  482.                         $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
  483.                             if (!$(this).hasClass('sub'+rootPostID)){
  484.                                 $(this).attr("class","inline sub"+rootPostID);
  485.                             }
  486.                         });
  487.                         $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
  488.                     }
  489.                 }
  490.             });
  491.             $(currentPost).data("inline","true")
  492.         }
  493.     });
  494.     $('.text .backlink').each(function(index,currentPost) {
  495.         if ($(currentPost).data("inline") != "true"){
  496.             $(this).on("click", function(e){
  497.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  498.                     e.preventDefault();
  499.                     //e.stopPropagation();
  500.                     var postID = $(this).attr("data-post");
  501.                     var rootPostID = $(e["target"].closest('article.base')).attr('id');
  502.                     if ($(e["target"]).hasClass("inlined")){
  503.                         $(e["target"]).removeClass("inlined");
  504.                         $('.sub'+rootPostID).each(function(index,currentPost){
  505.                             $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
  506.                         });
  507.                         $('#i'+postID+'.sub'+rootPostID).remove();
  508.                     }else{
  509.                         $(e["target"]).addClass("inlined");
  510.                         $(e["target"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
  511.                         $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
  512.                         $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
  513.                             if (!$(this).hasClass('sub'+rootPostID)){
  514.                                 $(this).attr("class","inline sub"+rootPostID);
  515.                             }
  516.                         });
  517.                         $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
  518.                     }
  519.                 }
  520.             });
  521.             $(currentPost).data("inline","true")
  522.         }
  523.     });
  524. };
  525.  
  526. function getSelectionText() {
  527.     var text = "";
  528.     if (window.getSelection) {
  529.         text = window.getSelection().toString();
  530.     } else if (document.selection && document.selection.type != "Control") {
  531.         text = document.selection.createRange().text;
  532.     }
  533.     return text;
  534. }
  535.  
  536. var postQuote = function(){
  537.     $('.post_data > [data-function=quote]').each(function(index,currentPost) {
  538.         if ($(currentPost).data("quotable") != "true"){
  539.             $(this).removeAttr("data-function"); // Disable native quote function
  540.             $(this).on("click", function(e){
  541.                 if (!e.originalEvent.ctrlKey && e.which == 1){
  542.                     e.preventDefault();
  543.                     var postnum = $(this)["0"].innerHTML;
  544.                     var input = document.getElementById('reply_chennodiscursus')
  545.  
  546.                     if (input.selectionStart != undefined)
  547.                     {
  548.                         var startPos = input.selectionStart;
  549.                         var endPos = input.selectionEnd;
  550.                         var startText = input.value.substring(0, startPos);
  551.                         var endText = input.value.substring(startPos);
  552.  
  553.                         var originalText = input.value;
  554.                         var selectedText = getSelectionText();
  555.                         if (selectedText == ""){
  556.                             var newText = startText +">>"+postnum+"\n"+ endText;
  557.                         }else{
  558.                             var newText = startText +">>"+postnum+"\n>"+ selectedText +"\n"+ endText;
  559.                         }
  560.                         document.getElementById('reply_chennodiscursus').value = originalText.replace(originalText,newText);
  561.                     }
  562.                 }
  563.             });
  564.             $(currentPost).data("quotable","true");
  565.         }
  566.     });
  567. };
  568.  
  569. var hidePosts = function()
  570. {
  571.     $('.pull-left').each(function(index, currentPost) {
  572.         if ($(currentPost).hasClass('stub')) {
  573.             $(currentPost).removeClass('stub')
  574.         }
  575.     });
  576. }
  577.  
  578. var filter = function(){
  579.     var sieveStrT0 = new RegExp("\\b("+filteredStringsT0.join("|")+")\\b"); // \b or (^|\s) works
  580.     var sieveStrT1 = new RegExp("\\b("+filteredStringsT1.join("|")+")\\b","i"); // \b or (^|\s) works
  581.     var sieveStrT2 = new RegExp("(^|\\s)("+filteredStringsT2.join("|")+")($|\\s)","i");
  582.     var sieveTrip = new RegExp("("+filteredTrips.join("|")+")");
  583.     var sieveName = new RegExp("("+filteredNames.join("|")+")");
  584.  
  585.     $('article.post').each(function(index,currentPost) {
  586.         if ($(currentPost).data("filtered") != "true"){
  587.             $(currentPost).data("filtered","true");
  588.             var postText = $(this).find('.text').elemText();
  589.             if (sieveTrip.test($(this).find('.post_tripcode').text()) || sieveName.test($(this).find('.post_author').text())){
  590.                 shitpostT2(currentPost, postText);
  591.             }else if(sieveStrT0.test(postText)){
  592.                 //console.log(postText.match(sieveStrT0));
  593.                 shitpostT0(currentPost, postText);
  594.             }else if (postText.length <= filterCharThreshold){
  595.                 if (sieveStrT1.test(postText)){
  596.                     //console.log(postText.match(sieveStrT1));
  597.                     shitpostT1(currentPost, postText);
  598.                 } else if (sieveStrT2.test(postText)){
  599.                     //console.log(postText.match(sieveStrT2));
  600.                     shitpostT2(currentPost, postText);
  601.                 }
  602.             }
  603.         }
  604.     });
  605. }
  606. function shitpostT0(post, postText){
  607.     $(post).addClass("shitpost");
  608. }
  609. function shitpostT1(post, postText){
  610.     $(post).addClass("shitpost");
  611. }
  612. function shitpostT2(post, postText){
  613.     $(post).removeClass('stub');
  614.     $(post).find('.pull-left').removeClass('stub');
  615.     var docID = $(post).find('.pull-left > button').attr("data-doc-id");
  616.     $('.doc_id_'+docID).hide();
  617.     $('.stub_doc_id_'+docID).show();
  618. }
  619.  
  620. var embedImages = function() {
  621.     $('.posts article').each(function(index, currentArticle){
  622.         if ($(currentArticle).data('imgEmbed') != 'true'){
  623.             var patt = new RegExp("http[s]?://("+imgSites+")/[^\"]*");
  624.             var imgNum = imgNumMaster - $(currentArticle).find('.thread_image_box').length;
  625.             $(currentArticle).find(".text > a, .text > .spoiler, .text > strong").each(function(index, currentLink){
  626.                 if (imgNum == 0) {
  627.                     return false;
  628.                 }
  629.                 var imglink = patt.exec($(this).html());
  630.                 if (imglink !== null){
  631.                     imgNum--;
  632.                     // var patt2 = new RegExp(escapeRegExp(imglink["0"]), 'g'); Can't see what this does, uncomment if things break again
  633.                     imglink["0"] = imglink["0"].replace(/.gifv/g, ".webm"); // Only tested to work with Imgur
  634.                     if ((/.webm/g).test(imglink["0"])){
  635.                         $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+imglink["0"]+'" type="video/webm"></video></div>');
  636.                     }else if ($(this).hasClass("spoiler")){
  637.                         $(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>');
  638.                     }else{
  639.                         $(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>');
  640.                     }
  641.                     $(this).remove();
  642.                 }
  643.             });
  644.             $(currentArticle).data('imgEmbed', 'true');
  645.         }
  646.     });
  647. }
  648.  
  649. function notifyMe() {
  650.     if (!Notification) {
  651.         alert('Please us a modern version of Chrome, Firefox, Opera or Firefox.');
  652.         return;
  653.     }
  654.  
  655.     if (Notification.permission !== "granted")
  656.         Notification.requestPermission();
  657.  
  658.     var notification = new Notification('Notification title', {
  659.         icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
  660.         body: "Hey there! You've been notified!"
  661.     });
  662.  
  663.  
  664.     notification.onclick = function () {
  665.         window.open("http://stackoverflow.com/a/13328397/1269037");
  666.     }
  667. }
  668.  
  669. var seenPosts = function(){$('article').each(function(index, currentArticle){$(currentArticle).data('seen','true')});}
  670.  
  671. var newPosts = function() {
  672.     $('article').each(function(index, currentArticle){
  673.         if ($(currentArticle).data('seen') != 'true')
  674.         {
  675.             $(currentArticle).data('seen', 'true')
  676.             newPostCount +=1
  677.         }
  678.     });
  679.  
  680.     if (windowFocus == true) newPostCount = 0
  681.     document.title = "(" + newPostCount + ") " + DocumentTitle
  682. }
  683.  
  684. var postCounter = function() {$(".rules_box").html("<h6>Posts: " + $('.post_wrapper').length + "/400 <br> Images: " + $(".thread_image_box").length + "/250</h6>" + rulesBox)}
  685.  
  686. var bindShortcuts = function()
  687. {
  688.  
  689. }
  690.  
  691. var yourPosts = localStorage.yourPosts;
  692. if (yourPosts == undefined){
  693.     yourPosts = {};
  694.     console.log("Created post archive for the first time");
  695. } else {
  696.     yourPosts = JSON.parse(localStorage.yourPosts);
  697. }
  698. window.addEventListener("beforeunload", function (e) {
  699.     if (localStorage.yourPosts == undefined){
  700.         localStorage.yourPosts = JSON.stringify(yourPosts);
  701.     } else {
  702.         localStorage.yourPosts = JSON.stringify($.extend(true, yourPosts, JSON.parse(localStorage.yourPosts)));
  703.     }
  704.     //var confirmationMessage = "\o/";
  705.  
  706.     //(e || window.event).returnValue = confirmationMessage; //Gecko + IE
  707.     //return confirmationMessage;                            //Webkit, Safari, Chrome
  708. });
  709.  
  710. function labelYourPosts(firstcall){
  711.     $.each(queuedYouLabels, function(i, v){ // Parse all names on pageload and with each post submission
  712.         $('#'+v+' .post_author').after('<span> (You)</span>');
  713.     });
  714.     queuedYouLabels = [];
  715.  
  716.     if (firstcall){ // Parse all backlinks present on pageload
  717.         $.each(yourPosts[threadID], function(i,v){
  718.             $('.backlink[data-post='+v+']').each(function(){
  719.                 if ($(this).data('linkedYou') != 'true'){
  720.                     this.textContent += ' (You)';
  721.                     $(this).data('linkedYou','true');
  722.                 }
  723.             });
  724.         });
  725.     }
  726. }
  727.  
  728. function labelNewPosts(response){
  729.     var newPosts = Object.keys(response[threadID]["posts"]);
  730.     $.each(newPosts, function(i,v){ // For each post returned by update
  731.         $('#'+v+' .greentext > a').each(function(i, link){ // For each post content backlink
  732.             var linkID = $(link).attr('data-post')
  733.             if ($.inArray(linkID, yourPosts[threadID])+1){ // If the link points to your post
  734.                 link.textContent += ' (You)'; // Designate the link as such
  735.                 $('#'+linkID+' .post_backlink [data-post='+v+']')[0].textContent += ' (You)'; // And find your post's new reply backlink and designate it too
  736.             }
  737.         });
  738.     });
  739. }
  740.  
  741. var lastSubmittedContent;
  742.  
  743. function postSubmitEvent(){
  744.     if ($('#reply [type=submit]').length){
  745.         window.MutationObserver = window.MutationObserver
  746.         || window.WebKitMutationObserver
  747.         || window.MozMutationObserver;
  748.         var target =  $('#reply [type=submit]')["0"],
  749.             observer = new MutationObserver(function(mutation) {
  750.                 //console.log("Post Submit Event Triggered");
  751.                 lastSubmittedContent = $('#reply_chennodiscursus')[0].value;
  752.             }),
  753.             config = {
  754.                 attributes: true
  755.             };
  756.         observer.observe(target, config);
  757.     }
  758. }
  759.  
  760. $(document).ready(function(){
  761.     //notifyMe();
  762.     $('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/)
  763.     $('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>');
  764.     windowFocus = true
  765.     $(window).focus(function(){windowFocus = true; ThreadUpdate(features)})
  766.     $(window).blur(function(){windowFocus = false})
  767.     if (hideQROptions){
  768.         $('#reply').toggleClass("showQROptions"); // Make options hidden in QR by default
  769.     }
  770.  
  771.     threadID = $('#main > article[data-thread-num]').attr('id');
  772.     if (yourPosts[threadID] == undefined){
  773.         yourPosts[threadID] = [];
  774.     } else {
  775.         queuedYouLabels = yourPosts[threadID].slice(0);
  776.         console.log(queuedYouLabels);
  777.     }
  778.     console.log(yourPosts);
  779.     postSubmitEvent();
  780.  
  781.     $(document).ajaxComplete(function(event, request, settings) {
  782.         //console.log(event);
  783.         //console.log(request);
  784.         //console.log(settings);
  785.         if (request.responseText != ""){
  786.             response = JSON.parse(request.responseText);
  787.         }else{
  788.             response = {"error":"No responseText"};
  789.         }
  790.         //console.log(response);
  791.         if (response.error != undefined){
  792.             console.log(response.error);
  793.         }else{
  794.             if (settings.type == "POST"){
  795.                 if (response.error == undefined ){
  796.                     for (var post in response[threadID]["posts"]) {
  797.                         //console.log(lastSubmittedContent);                    
  798.                         if(response[threadID]["posts"][post]["comment"].replace(/[\r\n]/g,'') == lastSubmittedContent.replace(/[\r\n]/g,'')){
  799.                             yourPosts[threadID].push(post);
  800.                             queuedYouLabels.push(post);
  801.                             //console.log(yourPosts);
  802.                             //console.log(queuedYouLabels);
  803.                             labelYourPosts();
  804.                             break;
  805.                         }
  806.                     }
  807.                     labelNewPosts(response);
  808.                 }else{
  809.                     console.log(response.error);
  810.                 }
  811.             }else{
  812.                 if (response[threadID] != undefined){
  813.                     //console.log("GET");
  814.                     labelNewPosts(response);
  815.                 }else{
  816.                     console.log("Not in a thread");
  817.                 }
  818.             }
  819.         }
  820.     });
  821.     labelYourPosts(true); // First call, add (You) to page content
  822. });
  823.  
  824. var executeShortcut = function(shortcut) {
  825.     //console.log(shortcut);
  826.     var input = document.getElementById('reply_chennodiscursus');
  827.  
  828.     if (input.selectionStart != undefined){
  829.         $('#reply_chennodiscursus').selection('insert', {
  830.             text: "["+shortcut+"]",
  831.             mode: 'before'
  832.         });
  833.         $('#reply_chennodiscursus').selection('insert', {
  834.             text: "[/"+shortcut+"]",
  835.             mode: 'after'
  836.         });
  837.     }
  838. }
  839.  
  840. function quickReply(){
  841.     $('#reply').toggleClass("quickReply");
  842.     $('#reply fieldset > div:nth-child(1)').css("width","");
  843.     if ($('#reply').hasClass("showQROptions")){
  844.         $('#reply fieldset > div:nth-child(2)').toggle();
  845.     }
  846. }
  847.  
  848. function quickReplyOptions(){
  849.     $('#reply').toggleClass("showQROptions");
  850.     $('#reply.quickReply fieldset > div:nth-child(2)').toggle();
  851. }
  852.  
  853. $(function(){
  854.     shortcut.add("ctrl+s", function(){ executeShortcut("spoiler")});
  855.     shortcut.add("ctrl+i", function(){ executeShortcut("i")});
  856.     shortcut.add("ctrl+b", function(){ executeShortcut("b")});
  857.     shortcut.add("ctrl+u", function(){ executeShortcut("u")});
  858.     shortcut.add("q", function(){quickReply()}, {"disable_in_input":true});
  859.     shortcut.add("ctrl+q", function(){quickReplyOptions()}, {"disable_in_input":false});
  860.  
  861.     seenPosts();
  862.     ThreadUpdate(features);
  863.     getBoard();
  864.     bindShortcuts();
  865.     window.setInterval( function(){ ThreadUpdate(features); }, 500 );
  866. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement