anon4q27

Blacklist Script Dec 2018

Dec 16th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *
  3.  *
  4.  */
  5. // Blacklist Button - Permanently Blacklist Images
  6. var imageBlacklist = [] ;
  7. function loadImageBlacklist() { JSON.parse(localStorage.imageBlacklist || "[]").forEach(addToImageBlaclist); }
  8. function saveImageBlacklist() { localStorage.imageBlacklist = JSON.stringify(imageBlacklist); }
  9. function addToImageBlaclist(md5) { if (md5 && -1 === imageBlacklist.indexOf(md5)) imageBlacklist.push(md5); }
  10. function blacklistPostImages(post) { $(post).find('img.post-image').each(function (i, el) { var md5 = el.getAttribute('data-md5'); addToImageBlaclist(md5); el.remove(); }); }
  11. function removeBlacklistedImages() { var removed = 0; $('img.post-image').each(function (i, el) { if (-1 !== imageBlacklist.indexOf(el.getAttribute('data-md5'))) { el.remove(); removed += 1; } }); return removed; }
  12. function onNopeClicked(event) { event.preventDefault(); event.stopPropagation(); loadImageBlacklist(); var post = $(event.target).closest('.post'); blacklistPostImages(post); removeBlacklistedImages(); saveImageBlacklist(); }
  13. function addNopeButtons() { $('.post').each(function(i, post) { if ($(post).find('.nope').length === 0) { $(post).prepend("<input type='button' class='nope' onClick='onNopeClicked(event)' value='Blacklist'></input>"); } }) }
  14.  
  15. setInterval(function () { loadImageBlacklist(); removeBlacklistedImages(); addNopeButtons(); }, 500);
  16.  
  17. /* Display a replies counter overlay in the bottom right corner */
  18. $(function(){
  19.   $('head').append('<style>#thread_stats_posts_ovl { '+
  20.   'position:fixed;bottom:15px;right:35px;'+
  21.   'font:38px sans-serif;opacity:0.5;color:#f60;}</style>');
  22.   $('body').append('<div id="thread_stats_posts_ovl"/>');
  23.   function copyStats() { $('#thread_stats_posts_ovl').
  24.     text($('#thread_stats_posts').text());}
  25.   $(document).on('new_post',copyStats); copyStats();});
  26.  
  27. // User Settings
  28. var anonsw = {
  29.     qflair: '', // Examples: REAL, &rarr;
  30.     qcolor: '#ffc',
  31.     youcolor: '#fcc',
  32.     scrollcolor: 'rgba(153, 153, 153, 0.6)',
  33.     scrollbackcolor: '#333',
  34.     scrolltime: 400, // ms
  35.     updateDelay: 200, // ms
  36.     sidenavWidth: 20, // px
  37.    
  38. floodEnabled: true,
  39.     floodThreshold: 14, // min # posts before beginning fade
  40.     floodVanish: 15, // max # posts before completed fade/hide
  41.     floodBehavior: 'hide', // hide, hide
  42.     fadenametripregex: /^(Anon(ymous)?-.*|.*-!!mG7VJxZNCI)$/i,
  43.     fadenametripfloodvalue: -1, // Effective post count for fading, or -1 for auto of floodThreshold+post count
  44.     strikeThroughNameFags: true,
  45.  
  46.     rateHistoryLen: 50, // Data points on chart
  47.     rateAvgLen: 10 // Number of data points to average for instantaneous rate
  48. };
  49.  
  50. (function( anonsw_main, $, undefined ) {
  51.     // House keeping variables
  52.     var qposts = [];
  53.     var allqposts = [];
  54.     var currq = -1;
  55.     var youposts = [];
  56.     var curryou = -1;
  57.     var qnavposts = [];
  58.     var younavposts = [];
  59.     var ctx;
  60.     var borderSz;
  61.     var scrollWd;
  62.     var minheight;
  63.     var ratehistory = [];
  64.  
  65.     // Case insensitive contains selector for finding yous. SO #8746882
  66.     $.expr[":"].icontains = jQuery.expr.createPseudo(function (arg) {
  67.         return function (elem) {
  68.             return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
  69.         };
  70.     });
  71.  
  72.     // Get non-child text. SO #3442394
  73.     function immediateText(el) {
  74.         return el.contents().not(el.children()).text();
  75.     }
  76.  
  77.     // Highlight (you) posts/references
  78.     function highlightYous() {
  79.         $(youposts).each(function() {
  80.             $(this).css('background-color', anonsw.youcolor);
  81.         });
  82.         return $.Deferred().resolve();
  83.     }
  84.  
  85.     // Remove invalid (you)'s
  86.     function removeInvalidYous() {
  87.         $('div.body:icontains("(You)")').each(function() {
  88.             $(this).find(':not(small)').contents().filter(function() { return this.nodeType == 3 }).each(function() {
  89.                 this.textContent = this.textContent.replace(/\(+ *You *\)+/ig, "you");
  90.             });
  91.         });
  92.         return $.Deferred().resolve();
  93.     }
  94.  
  95.     // Highlight Q posts
  96.     function highlightQ() {
  97.         $(allqposts).each(function(idx,val) {
  98.             if($(val).css('background-color') !== anonsw.qcolor) {
  99.                 if(anonsw.qflair !== "") {
  100.                     $(val).find('p.intro > label > span.trip').first().prepend(anonsw.qflair + " ");
  101.                 }
  102.                 $(val).css('background-color', anonsw.qcolor);
  103.             }
  104.         });
  105.         return $.Deferred().resolve();
  106.     }
  107.  
  108.     // Set which posts are Q posts
  109.     function setQPosts() {
  110.         qposts = $.map($('div.post:not(.post-hover) > p.intro > label > span.trip:contains("!!mG7VJxZNCI")'), function(el) {
  111.             return $(el).closest('div.post');
  112.         });
  113.         allqposts = $.map($('div.post:not(.post-hover) > p.intro > label > span.trip:contains("!!mG7VJxZNCI")'), function(el) {
  114.             return $(el).closest('div.post');
  115.         });
  116.         return $.Deferred().resolve();
  117.     }
  118.  
  119.     // Set which posts are (you) posts
  120.     function setYouPosts() {
  121.         youposts = $.map($('div.post:not(.post-hover) > p.intro > label span.name > span.own_post, div.post:not(.post-hover) > div.body > p.body-line > small:icontains("(You)")'), function(el) {
  122.             return $(el).closest('div.post');
  123.         });
  124.         return $.Deferred().resolve();
  125.     }
  126.  
  127.     // Inserts side navigation (bird's eye)
  128.     function sidenav() {
  129.         $('body').append('<canvas id="sidenav"></canvas>');
  130.         var nav = $('#sidenav');
  131.         $(nav).css('position', 'fixed');
  132.         $(nav).css('top', $('div.boardlist').height());
  133.         $(nav).css('right', 0);
  134.         $(nav).css('width', anonsw.sidenavWidth);
  135.         $(nav).css('height', $(window).height() - $('div.boardlist').height());
  136.         $(nav).css('background-color', anonsw.scrollbackcolor);
  137.         $('body').css('margin-right', anonsw.sidenavWidth);
  138.         ctx = $('#sidenav').get(0).getContext('2d');
  139.         //ctx.canvas.height = $(document).height() - $('div.boardlist').height();
  140.         ctx.canvas.height = 2048;
  141.         ctx.canvas.width = anonsw.sidenavWidth;
  142.         borderSz = 1;
  143.         scrollWd = ctx.canvas.width / 2;
  144.     }
  145.  
  146.     // Set flood posts
  147.     function setFloodPosts() {
  148.         if(anonsw.floodEnabled) {
  149.             var stats = {};
  150.             var firstId = null;
  151.             //console.log("==[ Name Fags ]=================================================");
  152.             var posts = $('div.post:not(.post-hover)').not('.you');
  153.             $(posts).each(function () {
  154.                 var id = $(this).find('p > span.poster_id').first().text();
  155.                 if(firstId != null) {
  156.                     if (!(id in stats)) {
  157.                         stats[id] = {count: 0, namefag: false, floodcount: 0};
  158.                     }
  159.                     stats[id].count++;
  160.                     if(!stats[id].namefag) {
  161.                         var name = immediateText($(this).find('p > label span.name').first());
  162.                         var trip = $(this).find('p > label > span.trip').first().text();
  163.                         stats[id].namefag = !anonsw.fadenametripregex.test(name+'-'+trip);
  164.                         //if(stats[id].namefag) {
  165.                         //  console.log(id + '=' + stats[id].namefag + ', ' + name + ', ' + trip);
  166.                         //}
  167.                     }
  168.                     if(stats[id].namefag) {
  169.                         if(anonsw.fadenametripfloodvalue < 0) {
  170.                             stats[id].floodcount = anonsw.floodThreshold + stats[id].count;
  171.                         } else {
  172.                             stats[id].floodcount = anonsw.fadenametripfloodvalue;
  173.                         }
  174.                     } else {
  175.                         stats[id].floodcount = stats[id].count;
  176.                     }
  177.                 }
  178.                 if (firstId == null) {
  179.                     firstId = id;
  180.                 }
  181.             });
  182.             $.each(stats, function (key, value) {
  183.                 if (key !== firstId) {
  184.                     var ids = $('span.poster_id:contains("' + key + '")');
  185.                     if (value.floodcount > anonsw.floodThreshold || value.namefag) {
  186.                         if(anonsw.strikeThroughNameFags && value.namefag) {
  187.                             $(ids).each(function() {
  188.                                     $(this).closest('div.post').hide();
  189.                             });
  190.                         }
  191.                         if (anonsw.floodBehavior === 'fade') {
  192.                             var intensity = value.floodcount;
  193.                             if (intensity > anonsw.floodVanish) {
  194.                                 intensity = anonsw.floodVanish;
  195.                             }
  196.                             intensity = ((anonsw.floodVanish - anonsw.floodThreshold) - (intensity - anonsw.floodThreshold)) / (anonsw.floodVanish - anonsw.floodThreshold);
  197.                             if (intensity < 0.1) {
  198.                                 intensity = 0.1;
  199.                             }
  200.                             $(ids).each(function () {
  201.                                 $(this).closest('div.post').css('opacity', intensity);
  202.                                 $(this).closest('div.post').hover(function () {
  203.                                     $(this).animate({opacity: 1.0}, anonsw.updateDelay);
  204.                                 }, function () {
  205.                                     $(this).animate({opacity: intensity}, anonsw.updateDelay);
  206.                                 });
  207.                             });
  208.                         } else if (anonsw.floodBehavior === 'hide') {
  209.                             if (value.count >= anonsw.floodVanish) {
  210.                                 $(ids).each(function () {
  211.                                     $(this).closest('div.post').hide();
  212.                                 });
  213.                             }
  214.                         }
  215.                     } else {
  216.                         $(ids).each(function () {
  217.                             $(this).closest('div.post').css('opacity', 1.0);
  218.                         });
  219.                     }
  220.                 }
  221.             });
  222.         }
  223.         return $.Deferred().resolve();
  224.     }
  225.  
  226.      // Update navigation
  227.    function updateNav() {
  228.         updateNavGraphics();
  229.     }
  230.  
  231.  
  232.     // Update navigation graphics
  233.     function updateNavGraphics() {
  234.         var sidenav = $('#sidenav');
  235.         if(sidenav.length) {
  236.             $(sidenav).css('height', $(window).height() - $('div.boardlist').height());
  237.             minheight = ctx.canvas.height / ($(window).height() - $('div.boardlist').height()); // 1px
  238.             ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  239.  
  240.             // Draw nav q posts
  241.             qnavposts = [];
  242.             ctx.fillStyle = anonsw.qcolor;
  243.             for (i = 0; i < qposts.length; i++) {
  244.                 // TODO: check if we have already added post, don't draw it again
  245.                 var el = $(qposts).get(i);
  246.                 var height = $(el).height() / $(document).height() * ctx.canvas.height;
  247.                 if(height < minheight) height = minheight;
  248.                 qnavposts[i] = {
  249.                     x : borderSz,
  250.                     y : $(el).offset().top / $(document).height() * ctx.canvas.height,
  251.                     width : ctx.canvas.width - borderSz*2,
  252.                     height : height
  253.                 };
  254.                 ctx.fillRect(qnavposts[i].x, qnavposts[i].y, qnavposts[i].width, qnavposts[i].height);
  255.             }
  256.  
  257.             // Draw nav you posts
  258.             younavposts = [];
  259.             ctx.fillStyle = anonsw.youcolor;
  260.             for (i = 0; i < youposts.length; i++) {
  261.                 // TODO: check if we have already added post, don't add it again
  262.                 var el = $(youposts).get(i);
  263.                 var height = $(el).height() / $(document).height() * ctx.canvas.height;
  264.                 if(height < minheight) height = minheight;
  265.                 younavposts[i] = {
  266.                     x : borderSz,
  267.                     y : $(el).offset().top / $(document).height() * ctx.canvas.height,
  268.                     width : ctx.canvas.width - borderSz*2,
  269.                     height : height
  270.                 };
  271.                 ctx.fillRect(younavposts[i].x, younavposts[i].y, younavposts[i].width, younavposts[i].height);
  272.             }
  273.  
  274.             // Update nav window
  275.             ctx.fillStyle = anonsw.scrollcolor;
  276.             ctx.fillRect(
  277.                 scrollWd / 2,
  278.                 $(window).scrollTop() / $(document).height() * ctx.canvas.height,
  279.                 scrollWd,
  280.                 $(window).height() / $(document).height() * ctx.canvas.height
  281.             );
  282.  
  283.             // Add red marker at bottom of >750 posts
  284.             if($('#thread_stats_posts').text() > 750) {
  285.                 var barHeight = (4 * 2048) / ($(window).height() - $('div.boardlist').height());
  286.                 ctx.fillStyle = '#f66';
  287.                 ctx.fillRect(
  288.                     0,
  289.                     ctx.canvas.height - barHeight,
  290.                     ctx.canvas.width,
  291.                     barHeight
  292.                 );
  293.             }
  294.         }
  295.     }
  296.  
  297.     // Toggle post flooding
  298.     anonsw_main.toggleFlood = function() {
  299.         if(anonsw.floodEnabled) {
  300.             anonsw.floodEnabled = false;
  301.             $('.toggleFloodState').text('On');
  302.             if(anonsw.floodBehavior === 'fade') {
  303.                 $('span.poster_id').each(function () {
  304.                     $(this).closest('div.post').css('opacity', 1);
  305.                     $(this).closest('div.post').off('mouseenter mouseleave');
  306.                 });
  307.             } else if(anonsw.floodBehavior === 'hide') {
  308.                 $(this).closest('div.post').show();
  309.             }
  310.         } else {
  311.             anonsw.floodEnabled = true;
  312.             $('.toggleFloodState').text('Off');
  313.             runq()
  314.         }
  315.     };
  316.  
  317.     // Helper to run snippets in the right order
  318.     function runq() {
  319.         setQPosts()
  320.             .done(highlightQ)
  321.             .done(removeInvalidYous)
  322.             .done(setYouPosts)
  323.             .done(highlightYous)
  324.             .done(setFloodPosts)
  325.             .done(updateNav);
  326.     }
  327.  
  328.     anonsw_main.Q = function() {
  329.         sidenav();
  330.         runq();
  331.  
  332.         // Select the node that will be observed for mutations
  333.         var targetNode = $('div.thread')[0];
  334.  
  335.         // Options for the observer (which mutations to observe)
  336.         var config = { childList: true };
  337.  
  338.         // Callback function to execute when mutations are observed
  339.         var callback = function(mutationsList) {
  340.             for(var mutation in mutationsList) {
  341.                 if (mutationsList[mutation].type == 'childList') {
  342.                     runq();
  343.                     break;
  344.                 }
  345.             }
  346.         };
  347.  
  348.         // Create an observer instance linked to the callback function
  349.         var observer = new MutationObserver(callback);
  350.  
  351.         // Start observing the target node for configured mutations
  352.         observer.observe(targetNode, config);
  353.     };
  354. }( window.anonsw_main = window.anonsw_main || {}, jQuery ));
  355.  
  356. // Attach snippets to ready/change events
  357. $(document).ready(anonsw_main.Q);
Add Comment
Please, Sign In to add comment