Browse Source

post-hider.js: fixed multiple board issues; eg. you could hide a thread on one board, and threads from other boards with the same id would have been hidden too

pull/40/head
czaks 11 years ago
parent
commit
0cae0d70b8
  1. 32
      js/post-hider.js

32
js/post-hider.js

@ -1,33 +1,37 @@
function phGetCookieName(id) { function phGetCookieName(board, id) {
return "ph_hide_" + id; return "ph_hide_" + board + "_" + id;
} }
function phPostHidden(id) { function phPostHidden(board, id) {
return (localStorage.getItem(phGetCookieName(id)) != null); return (localStorage.getItem(phGetCookieName(board, id)) != null);
} }
function phPostToggle(id) { function phPostToggle(board, id) {
if(phPostHidden(id)) { localStorage.removeItem(phGetCookieName(id)); } if(phPostHidden(board, id)) { localStorage.removeItem(phGetCookieName(board, id)); }
else { localStorage.setItem(phGetCookieName(id),"yes"); } else { localStorage.setItem(phGetCookieName(board, id),"yes"); }
} }
function phGetInnerText(id) { function phGetInnerText(board, id) {
if(phPostHidden(id)) { return "[+]"; } if(phPostHidden(board, id)) { return "[+]"; }
else { return "[-]"; } else { return "[]"; }
} }
function phGetOpID(element) { function phGetOpID(element) {
return Number(element.children("div.post.op").children("p.intro").children("a.post_no:eq(1)").text()); return Number(element.children("div.post.op").children("p.intro").children("a.post_no:eq(1)").text());
} }
function phGetOpBoard(element) {
return element.data("board");
}
function phPostHandle(element) { function phPostHandle(element) {
var id = phGetOpID(element); var id = phGetOpID(element);
var board = phGetOpBoard(element);
var preplies = element.children("div.post.reply"); var preplies = element.children("div.post.reply");
var pbody = element.children("div.post.op").children("div.body"); var pbody = element.children("div.post.op").children("div.body");
var pimage = element.children("a:first").children("img"); var pimage = element.children("a:first").children("img");
var pbutton = element.children("div.post.op").children("p.intro").children("a.posthider"); var pbutton = element.children("div.post.op").children("p.intro").children("a.posthider");
var pomitted = element.children("div.post.op").children("span.omitted"); var pomitted = element.children("div.post.op").children("span.omitted");
if(phPostHidden(id)) { element.addClass("thread-hidden"); pomitted.hide(); preplies.hide(); pbody.hide(); pimage.hide(); pbutton.text("[+]"); } if(phPostHidden(board, id)) { element.addClass("thread-hidden"); pomitted.hide(); preplies.hide(); pbody.hide(); pimage.hide(); pbutton.text("[+]"); }
else { element.removeClass("thread-hidden"); pomitted.show(); preplies.show(); pbody.show(); pimage.show(); pbutton.text("[-]"); } else { element.removeClass("thread-hidden"); pomitted.show(); preplies.show(); pbody.show(); pimage.show(); pbutton.text("[]"); }
} }
$(document).ready(function(){ $(document).ready(function(){
$('div[id^="thread"]').each(function(index, element){ $('form[name="postcontrols"] > div[id^="thread"]').each(function(index, element){
// Get thread ID. // Get thread ID.
var pin = $(this).children("div.post.op").children("p.intro"); var pin = $(this).children("div.post.op").children("p.intro");
var tid = phGetOpID($(this)); var tid = phGetOpID($(this));
@ -35,7 +39,7 @@ $(document).ready(function(){
$("<a href='javascript:;' class='posthider'>[?]</a>").insertAfter(pin.children('a:last')).click(function(e) { $("<a href='javascript:;' class='posthider'>[?]</a>").insertAfter(pin.children('a:last')).click(function(e) {
var eO = $(e.target); var eO = $(e.target);
var par = eO.parent().parent().parent(); var par = eO.parent().parent().parent();
phPostToggle(phGetOpID(par)); phPostToggle(phGetOpBoard(par), phGetOpID(par));
phPostHandle(par); phPostHandle(par);
return false; return false;
}); });

Loading…
Cancel
Save