Hidden Stickies - (Grease) Monkeying with Tip.it
Hey guys!
I recently read a post, http://forum.tip.it/topic/311258-hide-stickies/, requesting a way to hide stickies.
Since it seems we aren't going to get an official way to do this, I decided to write up a greasemonkey userscript for those people who are using FireFox or GoogleChrome.
This userscript will add an [x] next to each sticky which will let you hide it.
There is a counter above the stickies that tells you how many you have hidden on that page and gives you the option to display them.
If you want to unhide a sticky you need to click "[click to show]" above the list of stickies and then choose the "[+]" option for each individual sticky you want to unhide.
This userscript relies on the cookie named "hidden_stickies", so if you clean out your cookies often this script won't be much help.
If for some reason the script doesn't appear to be working properly, please disable it and let me know the issues you ran into.
If you use it, or have any questions, let me know. :)
// ==UserScript==
// @name hide stickies
// @namespace forum.tip.it
// @description Lets you choose to hide stickies once you have read them, to save space.
// @include http://forum.tip.it/forum/*
// @version 1
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
//Add the functions for cookie handling
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies.substr(0,ARRcookies.indexOf("="));
y=ARRcookies.substr(ARRcookies.indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
if(typeof(y) != "undefined"){
return unescape(y);
}else{
return "";
}
}else{
return "";
}
}
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/forum/";
document.cookie=c_name + "=" + c_value;
}
function setHiddenStickiesCookie(rowid,action)
{
contents = getCookie("hidden_stickies");
if(action == "add")
{
contents = contents.replace(rowid+";","");
contents = contents + rowid+";";
}
if(action == "remove")
{
contents = contents.replace(rowid+";","");
}
//Check if there are any stickies hidden, if not remove the cookie
if(contents != "")
{
setCookie("hidden_stickies", contents, 365);
} else {
setCookie("hidden_stickies", "", -1);
}
}
var howManyHiddenAnnouncements = 0;
var howManyHiddenPinned = 0;
my_jQuery = $.noConflict(true);
my_jQuery(document).ready(function($){
//Add our Announcements hidden counter
$(".header").find(".col_f_topic").each(function(){
$(this).append(" <span id='totalHiddenAnnouncements'>(hidden)</span> <span id='unhideAnnouncements'>[click to show]</span>");
$("#totalHiddenAnnouncements").hide();
$("#unhideAnnouncements").hide();
});
//Add our Pinned hidden counter
$("th:contains(Important Topics In This Forum)").each(function(){
$(this).append(" <span id='totalHiddenPinned'>(hidden)</span> <span id='unhidePinned'>[click to show]</span>");
$("#totalHiddenPinned").hide();
$("#unhidePinned").hide();
});
$(".topic_prefix").each(function(){
if($(this).html() == "Pinned" || $(this).html() == "Announcement"){
$theSticky = $(this).parent().parent();
$theSticky.addClass("aSticky");
$theSticky.addClass("visibleSticky");
if($(this).html() == "Pinned"){$theSticky.addClass("pinSticky");}
if($(this).html() == "Announcement"){$theSticky.addClass("announceSticky");}
$(this).append(" <span class='stickyremover'>[x]</span>");
$(this).append("<span class='stickyshower'>[+]</span>");
//$(".stickyremover").hide();
$(".stickyshower").hide();
}
});
$(".aSticky").each(function(){
if(rowIsHidden($(this).attr("id"))){
hideTheSticky("#" + $(this).attr("id"));
}else{
//showTheSticky("#" + $(this).attr("id"));
}
});
function rowIsHidden(id)
{
var hiddenThreads = getCookie("hidden_stickies");
if(hiddenThreads != null && hiddenThreads != ""){
var ARRstickies=hiddenThreads.split(";");
for (i=0;i<ARRstickies.length;i++)
{
threadId = ARRstickies;
if(threadId == id){return true;}
}
}
return false;
}
function hideTheSticky(selector){
$(selector).each(function(){
rowId = $(this).attr('id');
$("#"+rowId).hide().removeClass("visibleSticky").addClass("hiddenSticky");
$(this).find(".stickyremover").hide();
$(this).find(".stickyshower").show();
if($(this).hasClass("announceSticky")){
howManyHiddenAnnouncements++;
}
if($(this).hasClass("pinSticky")){
howManyHiddenPinned++;
}
if(howManyHiddenAnnouncements > 0){
$("#totalHiddenAnnouncements").html("(" + howManyHiddenAnnouncements + " hidden)").show();
$("#unhideAnnouncements").show();
}else{
$("#totalHiddenAnnouncements").html("(" + howManyHiddenAnnouncements + " hidden)").hide();
$("#unhideAnnouncements").hide();
}
if(howManyHiddenPinned > 0){
$("#totalHiddenPinned").html("(" + howManyHiddenPinned + " hidden)").show();
$("#unhidePinned").show();
}else{
$("#totalHiddenPinned").html("(" + howManyHiddenPinned + " hidden)").hide();
$("#unhidePinned").hide();
}
});
}
function showTheSticky(selector){
$(selector).each(function(){
rowId = $(this).attr('id');
$("#"+rowId).show().removeClass("hiddenSticky").addClass("visibleSticky");
$(this).find(".stickyremover").show();
$(this).find(".stickyshower").hide();
if($(this).hasClass("announceSticky")){
howManyHiddenAnnouncements--;
}
if($(this).hasClass("pinSticky")){
howManyHiddenPinned--;
}
if(howManyHiddenAnnouncements > 0){
$("#totalHiddenAnnouncements").html("(" + howManyHiddenAnnouncements + " hidden)").show();
$("#unhideAnnouncements").show();
}else{
$("#totalHiddenAnnouncements").html("(" + howManyHiddenAnnouncements + " hidden)").hide();
$("#unhideAnnouncements").hide();
}
if(howManyHiddenPinned > 0){
$("#totalHiddenPinned").html("(" + howManyHiddenPinned + " hidden)").show();
$("#unhidePinned").show();
}else{
$("#totalHiddenPinned").html("(" + howManyHiddenPinned + " hidden)").hide();
$("#unhidePinned").hide();
}
});
}
function showHidden(id){
$(".hiddenSticky").each(function(){
if($(this).hasClass(id)){
$(this).find(".stickyremover").hide();
$(this).find(".stickyshower").show();
$(this).show();
}else{
}
});
}
function confirmHide(target)
{
if(confirm("Are you sure you want to hide the sticky?\nPress [Ok] to confirm.")){
setHiddenStickiesCookie(target,"add");
hideTheSticky("#"+target);
}
}
function confirmShow(target)
{
if(confirm("Are you sure you want to unhide the sticky?\nPress [Ok] to confirm.")){
setHiddenStickiesCookie(target,"remove");
showTheSticky("#"+target);
}}
$(".stickyshower").click(function(){
confirmShow($(this).parent().parent().parent().attr('id'));
return false;});
$(".stickyremover").click(function(){
confirmHide($(this).parent().parent().parent().attr('id'));
return false;});
$("#unhidePinned").click(function(){
showHidden("pinSticky");
});
$("#unhideAnnouncements").click(function(){
showHidden("announceSticky");
});
});
}
// load jQuery and execute the main function
addJQuery(main);
2 Comments
Recommended Comments