rendered paste body// ==UserScript==
// @include http://forums.somethingawful.com/*
// ==/UserScript==
// by moho
(function(){
var saName = "ColdPie";
var colorForumView = true;
var quoteRegExp = new RegExp("^"+saName+" posted:$");
var sl = new StreamLoader(fix,1000);
sl.start();
addStyleSheet("\
.cloneop tr.altcolor2 td { background-color: #F1DEF8 !important; }\
.cloneop tr.altcolor1 td { background-color: #F1DEF8 !important; }\
.cloneop tr.seen2 td { background-color: #F1DEF8 !important; }\
.cloneop tr.seen1 td { background-color: #F1DEF8 !important; }\
.cloneop dt.author { color: #620EAD; }\
.cloneop .clonespan { content:'Thread Author'; display: block; font-size: 60%; color: #620EAD; font-weight: bold; }\
\
.clonequoter.clonequoter tr.altcolor2 td { background-color: #e3cebd !important; }\
.clonequoter.clonequoter tr.altcolor1 td { background-color: #f3decd !important; }\
.clonequoter.clonequoter tr.seen2 td { background-color: #e3cebd !important; }\
.clonequoter.clonequoter tr.seen1 td { background-color: #f3decd !important; }\
\
.cloneme.cloneme.cloneme tr.altcolor2 td { background-color: #c5e3bd !important; }\
.cloneme.cloneme.cloneme tr.altcolor1 td { background-color: #d4f3cd !important; }\
.cloneme.cloneme.cloneme tr.seen2 td { background-color: #c5e3bd !important; }\
.cloneme.cloneme.cloneme tr.seen1 td { background-color: #d4f3cd !important; }\
\
tr.new_posts > td { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADACAYAAADFoQmYAAAALklEQVQoU2OqW/g0k4mBgYGRMMFEWIyJMItiCWLV4WQR6xkiCAZU1igxStCXAAD27gREAbZstgAAAABJRU5ErkJggg==') !important; background-position: top left; background-repeat: repeat-x; }\
tr.no_new_posts > td { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADACAYAAADFoQmYAAAALklEQVQ4y2PYv39/JhMDAwMjYYKJsBgTYRbFEqQbgN+l+MXwEwyorFFilKAvAQDFMgR7ua/RWgAAAABJRU5ErkJggg==') !important; background-position: top left; background-repeat: repeat-x; }\
\
");
function fix () {
var view = window.cloneview
if (!view) {
var locm = window.location.href.match(/showthread.php|forumdisplay.php/);
if (!locm) { sl.stop(); return; }
else {
view = window.cloneview = locm[0];
}
}
if (view == "showthread.php") {
fixThread();
}
else if ((view == "forumdisplay.php") && (colorForumView)) {
fixForum();
}
}
function fixForum () {
var postxp = xpathFind("//tr[@class='thread']");
for (var i = 0; i < postxp.snapshotLength; i++) {
var tr = postxp.snapshotItem(i);
if (tr.doneclone) { continue; }
if (!hasFollowers(tr)) { break; }
var xp = xpathFindContext(tr,".//div[@class='lastseen']");
if (xp.snapshotLength) {
if (xpathFindContext(tr,".//a[@class='count']").snapshotLength) {
tr.className += " new_posts";
}
else {
tr.className += " no_new_posts";
}
}
tr.doneclone = true;
// post loop end
}
}
function fixThread () {
var postxp = xpathFind("//table[@class='post']");
for (var i = 0; i < postxp.snapshotLength; i++) {
var pt = postxp.snapshotItem(i);
if (pt.doneclone) { continue; }
if (!hasFollowers(pt)) { break; }
var xp = xpathFindContext(pt,".//dt[contains(@class,' op')]");
if (xp.snapshotLength) {
var dt = xp.snapshotItem(0);
var span = document.createElement("SPAN");
span.className = "clonespan";
dt.appendChild(span);
pt.className += " cloneop";
}
var xp = xpathFindContext(pt,".//dt[contains(@class,'author')]");
if (xp.snapshotLength) {
var dt = xp.snapshotItem(0);
if (dt.firstChild.data == saName) {
pt.className += " cloneme";
}
}
var qbs = xpathFindContext(pt,".//div[@class='bbc-block']/h4/text()");
for (var j = 0; j < qbs.snapshotLength; j++) {
var text = qbs.snapshotItem(j).data;
if (text.match(quoteRegExp)) {
pt.className += " clonequoter";
break;
}
}
pt.doneclone = true;
// post loop end
}
}
function hasFollowers (node) { var o = xpathFindContextSingle(node,"following::*").singleNodeValue; if (o) { return true; } return false; }
function xpathFind (query) { return document.evaluate(query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); }
function xpathFindContext (context, query) { return document.evaluate(query, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); }
function xpathFindContextSingle (context, query) { return document.evaluate(query, context, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null); }
function addStyleSheet (stylestring) {
try {
var ss = document.createElement("style");
ss.type = "text/css";
ss.appendChild(document.createTextNode(stylestring));
document.getElementsByTagName("head")[0].appendChild(ss);
}
catch (e) { return false; }
return ss;
}
function StreamLoader (func, delay) {
var self = this;
var timer = null;
var timerStop = false;
this.runs = 0;
this.stub = function (onload, e) {
if (timerStop) { return; }
self.runs++;
if (onload) { self.stop(); func(true); }
else {
func(false);
if (!timerStop) { timer = setTimeout(function () { self.stub(false); }, delay); }
}
}
this.start = function () {
window.addEventListener('DOMContentLoaded',function(e){ self.stub(true,e); }, false);
self.stub(false);
}
this.stop = function () { timerStop = true; clearTimeout(timer); }
this.doLast = function () { self.stub(true,{}); }
}
})();