From 0cae0d70b8a25264871a0d39dc1bfdbfa53e44dd Mon Sep 17 00:00:00 2001 From: czaks Date: Mon, 24 Jun 2013 09:02:12 -0400 Subject: [PATCH] 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 --- js/post-hider.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/js/post-hider.js b/js/post-hider.js index 0a2e3c1a..02a421fe 100644 --- a/js/post-hider.js +++ b/js/post-hider.js @@ -1,33 +1,37 @@ -function phGetCookieName(id) { - return "ph_hide_" + id; +function phGetCookieName(board, id) { + return "ph_hide_" + board + "_" + id; } -function phPostHidden(id) { - return (localStorage.getItem(phGetCookieName(id)) != null); +function phPostHidden(board, id) { + return (localStorage.getItem(phGetCookieName(board, id)) != null); } -function phPostToggle(id) { - if(phPostHidden(id)) { localStorage.removeItem(phGetCookieName(id)); } - else { localStorage.setItem(phGetCookieName(id),"yes"); } +function phPostToggle(board, id) { + if(phPostHidden(board, id)) { localStorage.removeItem(phGetCookieName(board, id)); } + else { localStorage.setItem(phGetCookieName(board, id),"yes"); } } -function phGetInnerText(id) { - if(phPostHidden(id)) { return "[+]"; } - else { return "[-]"; } +function phGetInnerText(board, id) { + if(phPostHidden(board, id)) { return "[+]"; } + else { return "[–]"; } } function phGetOpID(element) { 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) { var id = phGetOpID(element); + var board = phGetOpBoard(element); var preplies = element.children("div.post.reply"); var pbody = element.children("div.post.op").children("div.body"); var pimage = element.children("a:first").children("img"); var pbutton = element.children("div.post.op").children("p.intro").children("a.posthider"); 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("[+]"); } - else { element.removeClass("thread-hidden"); pomitted.show(); preplies.show(); pbody.show(); pimage.show(); 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("[–]"); } } $(document).ready(function(){ - $('div[id^="thread"]').each(function(index, element){ + $('form[name="postcontrols"] > div[id^="thread"]').each(function(index, element){ // Get thread ID. var pin = $(this).children("div.post.op").children("p.intro"); var tid = phGetOpID($(this)); @@ -35,7 +39,7 @@ $(document).ready(function(){ $("[?]").insertAfter(pin.children('a:last')).click(function(e) { var eO = $(e.target); var par = eO.parent().parent().parent(); - phPostToggle(phGetOpID(par)); + phPostToggle(phGetOpBoard(par), phGetOpID(par)); phPostHandle(par); return false; });