') === -1) {
log("No known posting (callbackThreadNew): " + url);
return;
}
var mtchs = txt.match(postingRegExp);
if(mtchs === null) {
div.innerHTML = "
Could not load comment (new forum)";
return;
}
var html = mtchs[1];
div.innerHTML = html;
var replyLinks = txt.match(/
]*>[\s]*Antworten[\s]*<\/a>/);
var replyLink = (replyLinks !== null) ? replyLinks[1] : "";
processMessageDiv(div, url, replyLink);
}
catch(e)
{
log('Error processing post (callbackThreadNew): ' + e);
}
}
function processMessageDiv(div, messageUrl, replyLink) {
if(isNewForum) {
processMessageDivNew(div, messageUrl, replyLink);
return;
}
// link username to search
var userI = xpath1(".//div[@class='user_info']/i", div);
var userName;
if(userI != null)
{
userName = userI.innerHTML.replace(/^(.*?), .*$/, "$1");
userI.innerHTML = "" + userI.innerHTML + "";
userI.innerHTML += getPosterScoreBarCode(userName);
}
else
{
userName = "?";
log("Could not find username div!");
}
// colorize quote
var quotes = xpath(".//p/span[@class='quote']", div);
for(var i = 0; i < quotes.snapshotLength; i++) {
var e = quotes.snapshotItem(i);
var patternLength = 10;
var m = e.innerHTML.match(/^((?:> )+)/);
if(m != null) {
var color = getQuoteColor(m[0].length / patternLength);
if(color != "")
e.innerHTML = "
" + e.innerHTML + "";
}
}
// set the reply links
if(replyLink != "") {
replyLink = ensureAbsoluteUrl(replyLink);
replyLinkInline = "
iReply";
replyLink = "
Beantworten";
if(userI != null)
userI.innerHTML += " --- " + replyLink + (enableIReply ? " / " + replyLinkInline : "");
}
// link posting title to posting
var postingSubject = xpath1(".//h3[@class='posting_subject']", div);
if(postingSubject != null)
postingSubject.innerHTML = "
" + postingSubject.innerHTML + "";
else
log("Posting subject not found!");
// relink voting buttons
if(enableQuickVote) {
var voteLinks = xpath(".//div[@class='tovote_links']/a", div);
for(var i = 0; i < voteLinks.snapshotLength; i++) {
var voteLink = voteLinks.snapshotItem(i);
var url = voteLink.href;
voteLink.removeAttribute("href");
voteLink.addEventListener("click",
quickVoteFunctionBuilder(voteLink, url, userName), true);
voteLink.setAttribute("onclick", "sendVote(this, '" + url + "');");
}
}
}
function processMessageDivNew(div, messageUrl, replyLink) {
// link username to search
var userI = xpath1(".//span[@class='realname']|.//span[@class='pseudonym']/a|.//span[@class='pseudonym']", div);
var userName;
if(userI !== null) {
userName = userI.textContent;
userI.innerHTML = "
" + userI.innerHTML + "";
userI.innerHTML += getPosterScoreBarCode(userName);
}
else {
userName = "?";
log("Could not find username div! (processMessageDivNew)");
}
/*
// colorize quote
// not necessary any more
var quotes = xpath(".//blockquote", div);
for(var i = 0; i < quotes.snapshotLength; i++) {
var e = quotes.snapshotItem(i);
var patternLength = 10;
var lineLength = 80;
var m = e.innerHTML;
if(m != null) {
var colorNumber = parseInt((m.length % lineLength) / patternLength);
var color = getQuoteColor(colorNumber);
if(color != "") {
// add @grant GM_addStyle to UserScript header !!!
GM_addStyle(".quotecolor" + colorNumber + " { border-left:2px solid "+color+ "; color: " + color + " }");
e.setAttribute("className", "quotecolor"+colorNumber);
}
}
}*/
// set the reply links
if(replyLink !== "") {
replyLink = ensureAbsoluteUrl(replyLink);
replyLinkInline = "
iReply";
replyLink = "
Beantworten";
if(userI !== null)
userI.innerHTML += " --- " + replyLink + (enableIReply ? " / " + replyLinkInline : "");
}
// link posting title to posting
var postingSubject = xpath1(".//h1[@class='thread_title']", div);
if(postingSubject !== null)
postingSubject.innerHTML = "
" + postingSubject.innerHTML + "";
else
log("Posting subject not found!(processMessageDivNew)");
// remove vote buttons when not logged in
var votebuttonLoggedOutSpan = xpath1(".//span[contains(@class, 'rate_post')][@title='Bitte loggen Sie sich ein, um den Beitrag zu bewerten.']", document.getElementById("forum_wrap"));
if(votebuttonLoggedOutSpan !== null) {
var votebuttonWrapper = xpath1(".//div[@class='posting_options_wrapper']", div);
votebuttonWrapper.parentNode.removeChild(votebuttonWrapper);
}
// relink voting buttons
else if(enableQuickVote) {
var voteLinks = xpath(".//a[contains(@class, 'rate_posts')]", div);
for(var i = 0; i < voteLinks.snapshotLength; i++) {
var voteLink = voteLinks.snapshotItem(i);
var url = voteLink.href;
voteLink.removeAttribute("href");
voteLink.addEventListener("click",
quickVoteFunctionBuilder(voteLink, url, userName), true);
voteLink.setAttribute("onclick", "sendVote(this, '" + url + "');");
}
}
}
function quickVoteFunctionBuilder(voteLink, url, author) {
if(isNewForum)
return quickVoteFunctionBuilderNew(voteLink, url, author);
return function() {
log("voted for author: " + author);
// mark as voted
voteLink.style.backgroundColor = "yellow";
// extract score
var matches = url.match(/postvote-(-?\d)/);
if(!matches) return;
var score = parseInt(matches[1]);
log("score: " + score);
// score the author
scorePoster(author, score);
};
}
function quickVoteFunctionBuilderNew(voteLink, url, author) {
return function() {
log("voted for author (New): " + author);
// mark as voted
voteLink.style.backgroundColor = "yellow";
// extract score
var matches = url.match(/\/rate\((positive|negative)\/$/);
if(!matches) return;
var score = 0;
if( matches[1] === "postive") score = 1;
else if(matches[1] === "negative") score = -1;
log("score: " + score);
// score the author
scorePoster(author, score);
};
}
function getPosterScoreBarCode(author) {
var absScore = getPosterScore(author);
if (absScore === undefined) return "";
// TODO: think about making it logarithmical
var score = absScore * posterScoreScaleFactor;
score += 5;
if(score >= 4 && score <= 6) return "";
score = Math.min(score, 10);
score = Math.max(score, 0);
score += 1;
score = Math.round(score);
return "

";
}
function getPosterScore(author) {
return getLocalValue("score_" + author, 0);
}
function scorePoster(author, score) {
var oldScore = getPosterScore(author);
setLocalValue("score_" + author, oldScore + score);
}
function countLevel(el)
{
if(isNewForum) {
return countLevelNew(el);
}
var lvl = 1;
// limit loop, just to be sure
for(var i=0; i < 10000; i++) {
var par = el.parentNode;
el = par;
if(par == null) break;
if(par.className == "thread_tree") break;
if(par.className == "nextlevel" ||
par.className == "nextlevel_line")
lvl++;
}
return lvl;
}
function countLevelNew(el)
{
var lvl = 1;
// limit loop, just to be sure
for(var i=0; i < 10000; i++) {
var par = el.parentNode;
el = par;
if(par === null) break;
if(!par.className) continue;
if(par.className === "tree_thread_list") break;
if(par.className.indexOf("posting_element") === 0)
lvl++;
}
return lvl;
}
function insertPostStart(url, nr)
{
if(isNewForum)
return url.replace(/\/page-\d+/, "/page-" + nr);
else {
var eall = "";
if(document.location.href.match(/\/e-all/)) eall = "/e-all";
return url.replace(/(\/(list|foren)\/hs)-\d+/, "$1-" + nr + eall);
}
}
function extractPostStart(url)
{
var matches;
if(isNewForum) {
matches = url.match(/\/page-(\d+)/);
if(!matches) {
matches = url.match(/\?forum_page=(\d+)/);
}
}
else {
matches = url.match(/\/hs-(\d+)/);
}
if(!matches) return -1;
return parseInt(matches[1]);
}
function joinOverviewPages()
{
if(isNewForum) {
joinOverviewPagesNew();
return;
}
showOverviewPosterScores(document);
var pageNrUls = getElementsByClassName(document, "ul", "forum_navi");
var threadTrees = getElementsByClassName(document, "ul", "thread_tree");
if(threadTrees.length == 0)
threadTrees = getElementsByClassName(document, "ul", "fora_list");
if(pageNrUls.length == 0 ||
threadTrees.length == 0) {
log("no forum_navi or thread_tree");
return;
}
var firstPageURL = "";
var lastPageURL = "";
// find the first and last of the page URLs
var pageLinks = pageNrUls[0].getElementsByTagName("li");
for(var i = 0; i < pageLinks.length; i++) {
var pageLink = pageLinks[i];
if(pageLink.innerHTML.match(/>Neuere)) break;
if(pageLink.innerHTML.match(/^\d+$/)) firstPageURL = "";
// find the URL
var url = grepTitleLinkURL(pageLink.innerHTML);
if(!url) continue;
if(firstPageURL == "")
firstPageURL = url;
lastPageURL = url;
}
if(firstPageURL == "" || lastPageURL == "") {
log("found no page URLs");
return;
}
// extract the post numbers
var firstPostNr = extractPostStart(firstPageURL);
var lastPostNr = extractPostStart(lastPageURL);
if(firstPostNr == -1 || lastPostNr == -1) {
log("found no post numbers");
return;
}
// limit pages to users setting
var limited = false;
if(lastPostNr - firstPostNr > maxJoinedPosts) {
lastPostNr = firstPostNr + maxJoinedPosts;
limited = true;
}
// add list items and load the overview pages into them
var threadTree = threadTrees[0];
for(var j = firstPostNr; j <= lastPostNr; j += overviewPagePostCount) {
var url = ensureAbsoluteUrl(insertPostStart(lastPageURL, j));
var li = document.createElement('li');
li.innerHTML = "
Beiträge ab Nr. " + j + "";
threadTree.appendChild(li);
li = document.createElement('li');
li.innerHTML = "
Lade...";
threadTree.appendChild(li);
requestHTML(url, callbackOverviewPage, j, li);
}
// add links to navigate
if(firstPostNr > overviewPagePostCount) {
var li = document.createElement('li');
li.innerHTML = "
Vorwärts...";
threadTree.insertBefore(li, threadTree.childNodes[0]);
}
if(limited) {
var li = document.createElement('li');
li.innerHTML = "
Weiter...";
threadTree.appendChild(li);
}
}
function joinOverviewPagesNew()
{
showOverviewPosterScores(document);
var pageNrElmFirst = xpath1(".//span[@class='seiten']/a[position()=1]", document.getElementById("thread_sortierung"));
var pageNrElmLast = xpath1(".//span[@class='seiten']/a[position()=last()]", document.getElementById("thread_sortierung"));
if(pageNrElmFirst === null)
pageNrElmFirst = xpath1(".//a[@class='page'][starts-with(@href, '?forum_page=')][position()=1]", document.getElementById("forum_wrap"));
if(pageNrElmLast === null)
pageNrElmLast = xpath1(".//a[@class='page'][starts-with(@href, '?forum_page=')][position()=last()]", document.getElementById("forum_wrap"));
// only one page, nothing to join
if(pageNrElmFirst === null || pageNrElmLast === null)
return;
var threadTree = document.getElementById("tree_thread_list");
if(!threadTree)
var threadTree = xpath1(".//div[@class='inner_forum_list']/ul[@class='forum_list']", document.getElementById("forum_wrap"));
if(threadTree === null) {
log("no tree_thread_list or forum_list (joinOverviewPagesNew)");
return;
}
var firstPageURL = "";
var lastPageURL = "";
// find the first and last of the page URLs
firstPageURL = ensureAbsoluteUrl(pageNrElmFirst.getAttribute("href"));
lastPageURL = ensureAbsoluteUrl(pageNrElmLast.getAttribute("href"));
if(firstPageURL == "" || lastPageURL == "") {
log("found no page URLs (joinOverviewPagesNew)");
return;
}
// extract the post numbers
var firstPostNr = extractPostStart(firstPageURL);
var lastPostNr = extractPostStart(lastPageURL);
if(firstPostNr == -1 || lastPostNr == -1) {
log("found no post numbers (joinOverviewPagesNew)");
return;
}
// limit pages to users setting
var limited = false;
if(lastPostNr - firstPostNr > maxJoinedPosts) {
lastPostNr = firstPostNr + maxJoinedPosts;
limited = true;
}
// add list items and load the overview pages into them
for(var j = firstPostNr; j <= lastPostNr; j ++) {
var url = ensureAbsoluteUrl(insertPostStart(lastPageURL, j));
var li = document.createElement('li');
li.innerHTML = "
Beiträge ab Seite " + j + "";
threadTree.appendChild(li);
li = document.createElement('li');
li.innerHTML = "
Lade...";
threadTree.appendChild(li);
requestHTML(url, callbackOverviewPage, j, li);
}
// add links to navigate
if(firstPostNr > overviewPagePostCount) {
var li = document.createElement('li');
li.innerHTML = "
Vorwärts...";
threadTree.insertBefore(li, threadTree.childNodes[0]);
}
if(limited) {
var li = document.createElement('li');
li.innerHTML = "
Weiter...";
threadTree.appendChild(li);
}
}
function callbackOverviewPage(txt, nr, startli, url)
{
if(isNewForum) {
callbackOverviewPageNew(txt, nr, startli, url);
return;
}
var matches = txt.match(/
([\s\S]*)<\/ul>[\s\S]*?/i);
if(!matches) {
startli.innerHTML = "Fehler beim Laden";
return;
}
var lis = matches[2];
lis = lis.replace(/\/read(?!\/showthread-1)/g, "/read/showthread-1");
startli.innerHTML = "";
showOverviewPosterScores(startli);
}
function callbackOverviewPageNew(txt, nr, startli, url)
{
var matches = txt.match(/([\s\S]*)<\/ol>[\s\S]*?[\s\S]*?/i);
if(!matches)
matches = txt.match(/
\s*(- /i);
if(!matches) {
startli.innerHTML = "Fehler beim Laden der Seite";
return;
}
var lis = matches[1];
startli.innerHTML = "" + lis + "";
showOverviewPosterScores(startli);
}
function showOverviewPosterScores(root) {
if(isNewForum)
var userdivs = xpath(".//span[@class='written_by_user']", root);
else
var userdivs = xpath(".//div[@class='thread_user']", root);
for(var i = 0; i < userdivs.snapshotLength; i++) {
var div = userdivs.snapshotItem(i);
div.innerHTML += getPosterScoreBarCode(div.innerHTML.trim());
}
}
function cleanUpReplyPage()
{
if(isNewForum) {
cleanUpReplyPageNew();
return;
}
if(enableAutoQuote && document.getElementsByName("message")[0].value == "") {
// select the right button the ultra hacky way
document.getElementsByName("quote")[0].click();
return;
}
var form = xpath1("//div[@class='forum_content' or @id='mitte_forum']");
var html = form.innerHTML;
// messy but working
html = html.replace(/(?:Unsere Foren|Dieses Forum)[\s\S]*