Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BnW FsB GvN
- // @namespace bnw_default_interface_fix
- // @description Turns off ajax autoremoval deleted messages/comments; turns off 20 posts per page limit; hides every blacklisted post until it gets comments/recommendation
- // @include http://bnw.im/*
- // @include https://bnw.im/*
- // @version 1.3
- // @grant unsafeWindow
- // ==/UserScript==
- (function (window, undefined) {
- 'use strict';
- var w;
- if (typeof unsafeWindow !== undefined) {
- w = unsafeWindow;
- } else {
- w = window;
- }
- if (w.self != w.top) {
- return;
- }
- var BLACKLIST = ['anonymous', 'moskvano', 'x01eg'];
- var patch_bnw = function() {
- w.ws.onclose = function() {};
- w.ws.close();
- var add_node = function(html, to, at_top) {
- var node = $(html).hide();
- node.addClass("outerborder_added");
- node.find("img.avatar").removeClass("avatar_ps");
- node.find("img.imgpreview_ps").each(function() {
- $(this).removeClass("imgpreview_ps");
- });
- $("code",node).each(function(i, e) {hljs.highlightBlock(e);});
- node.mouseover(function() {
- $(this).removeClass("outerborder_added");
- $(this).unbind("mouseover");
- });
- if (at_top) {
- node.prependTo(to);
- } else {
- node.appendTo(to);
- }
- node.fadeIn("slow");
- w.change_favicon();
- };
- var main_page_handler = function(e) {
- var d = JSON.parse(e.data);
- var msg;
- if (d.type == "new_message" &&
- window.location.search.indexOf("page") == -1) {
- // Add new messages only to first page.
- add_node(d.html, "#messages", true);
- w.add_main_page_actions(d.id, d.user);
- // make anonymous msg invisible until it gets recommendation
- if (w.is_anonymous_filtered && BLACKLIST.includes(d.user)) {
- msg = $("#"+d.id);
- if (msg.length) {
- msg.hide();
- }
- }
- } else if (d.type == "del_message") {
- msg = $("#"+d.id);
- if (msg.length) {
- msg.removeClass("outerborder_added"
- ).addClass("outerborder_deleted");
- }
- } else if (d.type == "upd_comments_count") {
- msg = $("#"+d.id);
- var t;
- if (msg.length) {
- t = msg.find("div.sign").contents()[3];
- t.nodeValue = t.nodeValue.replace(/\([0-9]+(\+)?/, "("+d.num+"$1");
- }
- } else if (d.type == "upd_recommendations_count") {
- msg = $("#"+d.id);
- if (msg.length) {
- t = msg.find("div.sign").contents()[3];
- var val = t.nodeValue;
- var re = /\+[0-9]+\)/;
- var new_val = d.num ? "+"+d.num+")" : ")";
- if (val.match(re)) {
- t.nodeValue = val.replace(re, new_val);
- } else {
- t.nodeValue = val.replace(/\)/, new_val);
- }
- // make anonymous msg visible since it got recommendation
- if (w.is_anonymous_filtered && BLACKLIST.includes(msg.find(".usrid").text().slice(1))) {
- if (d.num > 0) {
- msg.show();
- } else {
- msg.hide();
- }
- }
- }
- }
- };
- var message_page_handler = function(e) {
- var d = JSON.parse(e.data);
- if (d.type == "new_comment") {
- add_node(d.html, "#comments", false);
- w.add_message_page_actions(d.id, d.user);
- } else if (d.type == "del_comment") {
- var short_id = d.id.split("/")[1];
- var comment = $("#"+short_id);
- if (comment.length) {
- comment.removeClass("outerborder_added"
- ).addClass("outerborder_deleted");
- }
- }
- };
- w.is_anonymous_filtered = localStorage.is_anonymous_filtered == "true" ? true : false;
- filter_anonymous_with_no_recommends();
- switch (w.page_type) {
- case "main":
- w.onmessage = main_page_handler;
- w.openws();
- // filter control button
- $("#login_button").before("<a href='#' class='headlink' id='filter_anon_button'>"+
- (w.is_anonymous_filtered ? "Вернуть пуки" : "Откачать пуки")+
- "</a>");
- $("#filter_anon_button").click(function() {
- change_filter_state();
- filter_anonymous_with_no_recommends();
- });
- break;
- case "message":
- w.onmessage = message_page_handler;
- w.openws();
- break;
- case "user":
- w.onmessage = main_page_handler;
- w.openws();
- break;
- }
- function change_filter_state() {
- w.is_anonymous_filtered = w.is_anonymous_filtered ? false : true;
- localStorage.is_anonymous_filtered = w.is_anonymous_filtered;
- var caption = w.is_anonymous_filtered ? "Вернуть пуки" : "Откачать пуки";
- $("#filter_anon_button").text(caption);
- }
- function filter_anonymous_with_no_recommends() {
- // preloaded posts
- $(".message").each(function() {
- var msg = $(this);
- if (BLACKLIST.includes(msg.find(".usrid").text().slice(1))) {
- var t = msg.find("div.sign").contents()[3];
- var val = t.nodeValue;
- var re = /\+[0-9]+\)/;
- if (w.is_anonymous_filtered && !val.match(re)) {
- // seems u got no recommends
- msg.hide();
- } else {
- msg.show();
- };
- }
- });
- }
- console.log('BnW ajax handlers have been successfuly patched');
- };
- if (w.addEventListener)
- w.addEventListener("load", patch_bnw, false);
- else if (w.attachEvent)
- w.attachEvent("onload", patch_bnw);
- })(window);
Add Comment
Please, Sign In to add comment