-
-
Save anonymous/456b9d279c18032ec724 to your computer and use it in GitHub Desktop.
BnW ajax handlers patch: turns off ajax autoremove deleted messages/comments; turns off 20 posts per page limit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name BnW FsB GvN | |
// @namespace bnw_default_interface_fix | |
// @description Turns off ajax autoremove deleted messages/comments; turns off 20 posts per page limit. | |
// @include http://bnw.im/* | |
// @include https://bnw.im/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
(function (window, undefined) { | |
var w; | |
if (typeof unsafeWindow != undefined) { | |
w = unsafeWindow | |
} else { | |
w = window; | |
} | |
if (w.self != w.top) { | |
return; | |
} | |
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); | |
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); | |
} else if (d.type == "del_message") { | |
var msg = $("#"+d.id); | |
if (msg.length) { | |
msg.removeClass("outerborder_added" | |
).addClass("outerborder_deleted"); | |
} | |
} else if (d.type == "upd_comments_count") { | |
var msg = $("#"+d.id); | |
if (msg.length) { | |
var t = msg.find("div.sign").contents()[3]; | |
t.nodeValue = t.nodeValue.replace(/\([0-9]+(\+)?/, "("+d.num+"$1") | |
} | |
} else if (d.type == "upd_recommendations_count") { | |
var msg = $("#"+d.id); | |
if (msg.length) { | |
var 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); | |
} | |
} | |
} | |
} | |
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"); | |
} | |
} | |
} | |
switch (w.page_type) { | |
case "main": | |
w.onmessage = main_page_handler; | |
w.openws(); | |
break; | |
case "message": | |
w.onmessage = message_page_handler; | |
w.openws(); | |
break; | |
case "user": | |
w.onmessage = main_page_handler; | |
w.openws(); | |
break; | |
} | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment