Guest User

Untitled

a guest
Jun 14th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        BnW FsB GvN
  3. // @namespace   bnw_default_interface_fix
  4. // @description Turns off ajax autoremoval deleted messages/comments; turns off 20 posts per page limit; hides every blacklisted post until it gets comments/recommendation
  5. // @include     http://bnw.im/*
  6. // @include     https://bnw.im/*
  7. // @version     1.3
  8. // @grant       unsafeWindow
  9. // ==/UserScript==
  10. (function (window, undefined) {
  11.     'use strict';
  12.     var w;
  13.     if (typeof unsafeWindow !== undefined) {
  14.         w = unsafeWindow;
  15.     } else {
  16.         w = window;
  17.     }
  18.     if (w.self != w.top) {
  19.         return;
  20.     }
  21.  
  22.     var BLACKLIST = ['anonymous', 'moskvano', 'x01eg'];
  23.  
  24.     var patch_bnw = function() {
  25.         w.ws.onclose = function() {};
  26.         w.ws.close();
  27.  
  28.         var add_node = function(html, to, at_top) {
  29.             var node = $(html).hide();
  30.             node.addClass("outerborder_added");
  31.             node.find("img.avatar").removeClass("avatar_ps");
  32.             node.find("img.imgpreview_ps").each(function() {
  33.                 $(this).removeClass("imgpreview_ps");
  34.             });
  35.             $("code",node).each(function(i, e) {hljs.highlightBlock(e);});
  36.             node.mouseover(function() {
  37.                 $(this).removeClass("outerborder_added");
  38.                 $(this).unbind("mouseover");
  39.             });
  40.             if (at_top) {
  41.                 node.prependTo(to);
  42.             } else {
  43.                 node.appendTo(to);
  44.             }
  45.             node.fadeIn("slow");
  46.             w.change_favicon();
  47.         };
  48.  
  49.         var main_page_handler = function(e) {
  50.             var d = JSON.parse(e.data);
  51.             var msg;
  52.             if (d.type == "new_message" &&
  53.                 window.location.search.indexOf("page") == -1) {
  54.                 // Add new messages only to first page.
  55.                     add_node(d.html, "#messages", true);
  56.                     w.add_main_page_actions(d.id, d.user);
  57.                     // make anonymous msg invisible until it gets recommendation
  58.                     if (w.is_anonymous_filtered && BLACKLIST.includes(d.user)) {
  59.                         msg = $("#"+d.id);
  60.                         if (msg.length) {
  61.                             msg.hide();
  62.                         }
  63.                     }
  64.             } else if (d.type == "del_message") {
  65.                 msg = $("#"+d.id);
  66.                 if (msg.length) {
  67.                     msg.removeClass("outerborder_added"
  68.                     ).addClass("outerborder_deleted");
  69.                 }
  70.             } else if (d.type == "upd_comments_count") {
  71.                 msg = $("#"+d.id);
  72.                 var t;
  73.                 if (msg.length) {
  74.                     t = msg.find("div.sign").contents()[3];
  75.                     t.nodeValue = t.nodeValue.replace(/\([0-9]+(\+)?/, "("+d.num+"$1");
  76.                 }
  77.             } else if (d.type == "upd_recommendations_count") {
  78.                 msg = $("#"+d.id);
  79.                 if (msg.length) {
  80.                     t = msg.find("div.sign").contents()[3];
  81.                     var val = t.nodeValue;
  82.                     var re = /\+[0-9]+\)/;
  83.                     var new_val = d.num ? "+"+d.num+")" : ")";
  84.                     if (val.match(re)) {
  85.                         t.nodeValue = val.replace(re, new_val);
  86.                     } else {
  87.                         t.nodeValue = val.replace(/\)/, new_val);
  88.                     }
  89.                     // make anonymous msg visible since it got recommendation
  90.                     if (w.is_anonymous_filtered && BLACKLIST.includes(msg.find(".usrid").text().slice(1))) {
  91.                         if (d.num > 0) {
  92.                             msg.show();
  93.                         } else {
  94.                             msg.hide();
  95.                         }
  96.                     }
  97.                 }
  98.             }
  99.         };
  100.  
  101.         var message_page_handler = function(e) {
  102.             var d = JSON.parse(e.data);
  103.             if (d.type == "new_comment") {
  104.                 add_node(d.html, "#comments", false);
  105.                 w.add_message_page_actions(d.id, d.user);
  106.             } else if (d.type == "del_comment") {
  107.                 var short_id = d.id.split("/")[1];
  108.                 var comment = $("#"+short_id);
  109.                 if (comment.length) {
  110.                     comment.removeClass("outerborder_added"
  111.                     ).addClass("outerborder_deleted");
  112.                 }
  113.             }
  114.         };
  115.  
  116.         w.is_anonymous_filtered = localStorage.is_anonymous_filtered == "true" ? true : false;
  117.         filter_anonymous_with_no_recommends();
  118.  
  119.         switch (w.page_type) {
  120.             case "main":
  121.                 w.onmessage = main_page_handler;
  122.                 w.openws();
  123.                 // filter control button
  124.                 $("#login_button").before("<a href='#' class='headlink' id='filter_anon_button'>"+
  125.                     (w.is_anonymous_filtered ? "Вернуть пуки" : "Откачать пуки")+
  126.                     "</a>");
  127.                 $("#filter_anon_button").click(function() {
  128.                     change_filter_state();
  129.                     filter_anonymous_with_no_recommends();
  130.                 });
  131.                 break;
  132.             case "message":
  133.                 w.onmessage = message_page_handler;
  134.                 w.openws();
  135.                 break;
  136.             case "user":
  137.                 w.onmessage = main_page_handler;
  138.                 w.openws();
  139.                 break;
  140.         }
  141.  
  142.         function change_filter_state() {
  143.             w.is_anonymous_filtered = w.is_anonymous_filtered ? false : true;
  144.             localStorage.is_anonymous_filtered = w.is_anonymous_filtered;
  145.             var caption = w.is_anonymous_filtered ? "Вернуть пуки" : "Откачать пуки";
  146.             $("#filter_anon_button").text(caption);
  147.         }
  148.  
  149.         function filter_anonymous_with_no_recommends() {
  150.             // preloaded posts
  151.             $(".message").each(function() {
  152.                 var msg = $(this);
  153.                 if (BLACKLIST.includes(msg.find(".usrid").text().slice(1))) {
  154.                     var t = msg.find("div.sign").contents()[3];
  155.                     var val = t.nodeValue;
  156.                     var re = /\+[0-9]+\)/;
  157.                     if (w.is_anonymous_filtered && !val.match(re)) {
  158.                         // seems u got no recommends
  159.                         msg.hide();
  160.                     } else {
  161.                         msg.show();
  162.                     };
  163.                 }
  164.             });
  165.         }
  166.  
  167.         console.log('BnW ajax handlers have been successfuly patched');
  168.     };
  169.  
  170.     if (w.addEventListener)
  171.         w.addEventListener("load", patch_bnw, false);
  172.     else if (w.attachEvent)
  173.         w.attachEvent("onload", patch_bnw);
  174. })(window);
Add Comment
Please, Sign In to add comment