// ==UserScript==
// @name HideThread
// @namespace http://angerdanger.com
// @version 0.2
// @description Hides MR threads with the click of a button.
// @author AngerDanger
// @match https://forums.macrumors.com/*
// @grant none
// ==/UserScript==
var blockedTitles;
window.onload = function(){
var threads = document.getElementsByClassName('discussionListItem');
if (retrieve_cookie('hiddenThreads'))
blockedTitles = retrieve_cookie('hiddenThreads').split('*');
else
blockedTitles = [];
for (var i = 0; i < threads.length; i++){
for (var j = 0; j < blockedTitles.length; j++){
if (threads[i].getElementsByClassName('title')[0].getElementsByClassName('PreviewTooltip')[0].innerHTML == blockedTitles[j]){
threads[i].parentElement.removeChild(threads[i]);
threads[i] = '';
i--;
break;
}
}
}
for (var i = 0; i < threads.length; i++){
var hide = document.createElement('span');
hide.innerHTML = "X";
hide.onclick = function (){
blockedTitles.push(this.parentElement.parentElement.getElementsByClassName('title')[0].childNodes[1].innerHTML);
create_cookie('hiddenThreads', blockedTitles.join('*'), 30, "/");
this.parentElement.parentElement.parentElement.removeChild(this.parentElement.parentElement);
};
//threads[i].childNodes[1].innerHTML = "X" + threads[i].childNodes[1].innerHTML;
threads[i].childNodes[1].insertBefore(hide, threads[i].childNodes[1].firstChild);
}
};
function create_cookie(name, value, days2expire, path) {
var date = new Date();
date.setTime(date.getTime() + (days2expire * 24 * 60 * 60 * 1000));
var expires = date.toUTCString();
document.cookie = name + '=' + value + ';' +
'expires=' + expires + ';' +
'path=' + path + ';';
}
function retrieve_cookie(name) {
var cookie_value = "",
current_cookie = "",
name_expr = name + "=",
all_cookies = document.cookie.split(';'),
n = all_cookies.length;
for(var i = 0; i < n; i++) {
current_cookie = all_cookies[i].trim();
if(current_cookie.indexOf(name_expr) === 0) {
cookie_value = current_cookie.substring(name_expr.length, current_cookie.length);
break;
}
}
return cookie_value;
}