lainchan/js/post-hider.js

46 lines
1.7 KiB
JavaScript
Raw Normal View History

2012-12-24 07:03:07 -05:00
function phGetCookieName(id) {
return "ph_hide_" + id;
}
function phPostHidden(id) {
2012-12-24 07:16:12 -05:00
return (localStorage.getItem(phGetCookieName(id)) != null);
2012-12-24 07:03:07 -05:00
}
function phPostToggle(id) {
2012-12-24 07:16:12 -05:00
if(phPostHidden(id)) { localStorage.removeItem(phGetCookieName(id)); }
else { localStorage.setItem(phGetCookieName(id),"yes"); }
2012-12-24 07:03:07 -05:00
}
function phGetInnerText(id) {
if(phPostHidden(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 phPostHandle(element) {
var id = phGetOpID(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");
2012-12-24 07:17:54 -05:00
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("[-]"); }
2012-12-24 07:03:07 -05:00
}
$(document).ready(function(){
$('div[id^="thread"]').each(function(index, element){
// Get thread ID.
var pin = $(this).children("div.post.op").children("p.intro");
var tid = phGetOpID($(this));
if(tid != NaN) {
2012-12-24 07:36:56 -05:00
$("<a href='javascript:;' class='posthider'>[?]</a>").insertAfter(pin.children('a:last')).click(function(e) {
2012-12-24 07:03:07 -05:00
var eO = $(e.target);
var par = eO.parent().parent().parent();
phPostToggle(phGetOpID(par));
phPostHandle(par);
2012-12-24 07:36:56 -05:00
return false;
2012-12-24 07:03:07 -05:00
});
phPostHandle($(this));
}
});
});