By aboyd
Has 6 other scripts.
// ==UserScript==
// @name Digg Done That
// @namespace http://www.outshine.com/
// @description Been there, done that? On Digg, this removes articles you've read.
// @include *digg.com/*
// ==/UserScript==
/*
Script by Tony Boyd.
Authored on 2008-04-13.
Updated on 2008-04-13.
Version: 1.0.0
*/
function getRealElement(item) {
while (item.nodeType !== 1) {
item = item.nextSibling;
}
return item;
}
function handleBegone(e) {
divAbout = this.parentNode.parentNode.parentNode.getAttribute("about");
var doneThatString = GM_getValue('diggDoneThat');
if (doneThatString === "" || doneThatString === null || doneThatString === false) {
var doneThatArray = new Array();
doneThatArray[0] = divAbout;
}
else {
doneThatArray = doneThatString.split(/, */);
doneThatArray.unshift(divAbout);
if (doneThatArray.length > 250) {
doneThatArray.length = 250;
}
}
tempDoneThatString = doneThatArray.toString();
GM_setValue('diggDoneThat', tempDoneThatString);
this.parentNode.parentNode.parentNode.setAttribute('style', 'display: none;');
}
function handleReset(e) {
if (confirm('All the stories marked "read" will reappear if you do this. OK?')) {
GM_setValue('diggDoneThat', '');
this.setAttribute('style', 'font-family: inherit; font-size: 85%; font-weight: bold; padding: 4px 10px 4px 32px; color: gray;');
this.removeEventListener("click", handleReset, false);
alert('Done!');
}
}
mainDiv = document.getElementById('wrapper');
if (document.location.pathname.indexOf('/settings') === 0) {
divArray = mainDiv.childNodes;
for (var i = divArray.length - 1; i > -1; i--) {
if (divArray[i].nodeType == 1) {
if (divArray[i].className.indexOf('sidebar') != -1) {
divElement = document.createElement('li');
divElement.setAttribute('style', 'font-family: inherit; font-size: 85%; font-weight: bold; padding: 4px 10px 4px 32px; cursor: pointer; color: #105CB6;');
divLink = 'Clear your read stories';
divElement.innerHTML = divLink;
divElement.addEventListener("click", handleReset, false);
divFirstChild = getRealElement(divArray[i].firstChild);
divFinalDestination = getRealElement(divFirstChild.nextSibling);
divFinalDestination.appendChild(divElement);
}
}
}
}
else {
tempNodes = mainDiv.childNodes;
for (var x = 0; x < tempNodes.length; x++) {
if (tempNodes[x].nodeType == 1) {
if (tempNodes[x].className.indexOf('main') != -1) {
divArray = tempNodes[x].childNodes;
}
}
}
/*
If we remove an element, the array is modified mid-loop! So we count backwards.
That way, if the array changes, it only affects elements we're done with.
*/
for (var i = divArray.length - 1; i > -1; i--) {
/*
The nodeType of 1 verifies we're working with an element (like a div).
*/
if (divArray[i].nodeType == 1) {
if (divArray[i].className.indexOf('news-summary') != -1) {
/*
The "about" attribute is a unique identifier of the news block we want.
*/
divAbout = divArray[i].getAttribute('about');
divRegEx = '(,|^)' + divAbout + '(,|$)';
var pattern1 = new RegExp(divRegEx, 'i');
filterWords = GM_getValue('diggDoneThat');
/*
If the unique identifier is in our list of taboo identifiers, kill it.
Otherwise, give it a kill button.
*/
if (pattern1.test(filterWords)) {
divArray[i].parentNode.removeChild(divArray[i]);
}
else {
divElement = document.createElement('span');
divElement.setAttribute('class', 'tool');
divElement.setAttribute('style', 'font-weight: bold; padding: 5px 0px 0px 32px; cursor: pointer; color: #105CB6;');
divLink = '(Mark this read)';
divElement.innerHTML = divLink;
divElement.addEventListener("click", handleBegone, false);
newsArray = divArray[i].getElementsByTagName('div');
for (var j = newsArray.length - 1; j > -1; j--) {
if (newsArray[j].nodeType == 1) {
if (newsArray[j].className.indexOf('news-details') != -1) {
newsArray[j].appendChild(divElement);
}
}
}
}
}
}
}
}