// ==UserScript==
// @name vB New Topics
// @namespace http://userscripts.org/forums/2/topics/1801
// @description Open all forum new topics in tabs
// @include */forumdisplay.php*
// ==/UserScript==
/*
Created by Gollum from an idea/suggestion/request at us.o by @Seph_VIII
Expanded upon by @Mithrandir(us.o)
- with help from @Dr. Evil(de ff-user-group)
... max links to open, conditional button display, timeout delay, extra button styling, windowOpen fallback for GM_openInTabs
Gollum: added quick element check for vB board, plus x-browser support - tested in Opera(9.25) and IE7(IEPro), plus option to ignore timeout delay.
*/
(function (){
if (!document.getElementById('threadslist')) // early return for non-vB boards
return; // plus it's an Opera fix - ensure we're on the REAL document (wtf! something to do with cookie? setter??)
// configuration
var maxlnks = 0; // 0=open all new threads, 10=open first 10 new threads
var showBtnIf = 2; // 0=button will always be shown, 5=show only, if there are more than 4 new threads
var useTimeout = true; // don't attempt delay on thread-read cookie setting - YMMV - the timeout delay didn't work for me, so =false
var tOut = 3000; // set timeout in milliseconds for opening (cookies won't be stored if too low!)
var oMode = false; // =true: show first *unread* post, =false: show first post/beginning of thread
// end configuration
/* x-browser event register */
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; }
else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
else { elm['on' + evType] = fn; }
}
/* x-browser open tab */
function openTab(url) {
if (typeof GM_openInTab != 'undefined') GM_openInTab(url);
else if (typeof PRO_openInTab != 'undefined') PRO_openInTab(url,2);
else window.open(url);
}
var f = 0;
var newposts = new Array();
var lnks = document.getElementById('threadslist').getElementsByTagName('a');
for (var i=0; i < lnks.length; i++) {
if (/showthread.php\?goto=newpost/.test(lnks[i].href)) {
if (oMode) {
newposts.push(lnks[i].href);
} else {
newposts.push(lnks[i].href.replace(/goto=newpost&/, ""));
}
f++
if (f+1 > maxlnks && maxlnks > 0) break;
}
}
if (f >= showBtnIf) {
var btn = document.getElementById('inlinemodform').getElementsByTagName('td')[0].appendChild(document.createElement('button'));
btn.innerHTML = "Öffne " + f + " neue Beiträge"; // de-locale
// btn.innerHTML = "Open " + f + " new Posts";
btn.style.marginLeft = '4px';
btn.style.position = 'relative';
btn.style.top = '-7px';
btn.style.background='#DFE0E4';
btn.style.color='#02176D';
btn.style.fontWeight='bold';
btn.style.fontSize='0.9em';
addEvent(btn, "click",
function(e) {
if (maxlnks==0) this.style.display = 'none';
if (e && e.target) e.preventDefault();
else window.event.returnValue = false;
if (useTimeout) {
var i = -1;
function inner() {
if(++i < f) openTab(newposts[i]);
else clearInterval(timer);
}
var timer = setInterval(inner, tOut);
} else {
for (var i=0; i < newposts.length; i++)
openTab(newposts[i]);
}
}
, false);
}
})();