Add-on [forum] New Posts (filtered)

DeletedUser

[box=black]Script Details
Available From: The-West forums
Script Version: 0.2
Works on Version: Forum software version 3.8.6 (as running on 2012-01-26), Firefox 9.0.1, Greasemonkey 0.9.13[/box]

So I created a small userscript/ugly-hack that allows you to mark some forums as read before searching for new posts.

It is very crude atm, and I don't really have any plans to work on it further, but ofc if a few people find it useful I might consider making it a bit more user friendly...

To use this script:
1. make sure you have greasemonkey installed
2. copy the contents of the above code-block to a text-file.
3. edit the file to exclude the forums you don't want to read regularly
4. save the file as 'whatever-you-like.user.js'
5. drag that file to an open Firefox window (might work in other browsers, but I don't think so)
6. enjoy!

Code:
// ==UserScript==
// @name          The West Forums - mark forums read utility
// @description	  On The West forums (vBulletin, version 3.8.6) it marks the selected forums as read with one click
// @include       http://forum.the-west.net/*
// ==/UserScript==
// Notes:
// 	You must edit the below variable to include all forums (by id) that you 
//	wish to mark as read before searching for new posts.
//
//	You can find the id by looking at the URL of a forum, for example the Off topic forum:
//	http://forum.the-west.net/forumdisplay.php?f=35 (so 35 is the id).
//
//	Put the id:s between the [] below, separated by commas, for example:
//	[8, 35, 51]
//	Would mark all the world forums, 'Off topic' and 'Debate & discussion' as read
//	before doing a search for new posts.

var forums_to_mark = [7, 52];




// Sript start here - don't touch this code unless you want to void your warrany!
//
//check if the previous sibling node is an element node
function get_previoussibling(n) {
	x=n.previousSibling;
	while (x.nodeType!=1) {
		x=x.previousSibling;
	}
	return x;
};
//check if the next sibling node is an element node
function get_nextsibling(n) {
	x=n.nextSibling;
	while (x.nodeType!=1) {
		x=x.nextSibling;
	}
	return x;
};

function mark_multiple_forums_read() {
	var security_token = get_nextsibling(document.getElementById('usercptools')).firstChild.href;
	security_token = security_token.slice(security_token.search('logouthash=')+11);

	var j = 0;
	for (i in forums_to_mark) {
		GM_xmlhttpRequest({
			method: 'POST',
			url: "http://forum.the-west.net/ajax.php?do=markread&f=" + forums_to_mark[i],
			headers: {
    				"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
				"X-Requested-With": "XMLHttpRequest"
			},
			data: "securitytoken=" + security_token + "&do=markread&forumid=" + forums_to_mark[i],
		});
	}
	window.location = "http://forum.the-west.net/search.php?do=getnew";
};

// inserting the html
var autoReadLink = document.createElement('a');
autoReadLink.href = '#';
autoReadLink.id = 'autoReadLink';
autoReadLink.appendChild(document.createTextNode('filtered'));

var navbarSearchTd = document.getElementById('navbar_search');
var newPostsTd = get_previoussibling(navbarSearchTd);
newPostsTd.appendChild(document.createTextNode(' '));
newPostsTd.appendChild(document.createTextNode('('));
newPostsTd.appendChild(autoReadLink);
newPostsTd.appendChild(document.createTextNode(')'));

// add a listener or two
document.getElementById('autoReadLink').addEventListener('click', mark_multiple_forums_read, false);

Have fun!

/Edlit
 
Last edited by a moderator:

Slygoxx

Well-Known Member
No offense, but pretty useless if it only marks some forums as read. If you double click on the
forum_new.gif
button, that particular forum part is marked as read. While this may automate it, it looks like a lot more work to actually insert the forums you want to exclude, than to double click on some buttons once in a while :p And manually clicking also makes sure you don't automatically ignore parts you do read, but not that often.
 

DeletedUser22685

I use Chrome and it seems to have worked for me. Thanks Edlit!
 

DeletedUser

Ok, I changed the code to do real ajax requests as the forums do by themselves, a bit more stable now.

@Slygoxx, you are correct, it doesn't do much - but for me that don't read the 'games' and 'CS' sections and like to keep my 'new posts'-searches clean this makes the forums better.

I might consider adding a way to edit the forums to mark by gui if there is enough feedback suggesting that would be a good thing.

/Edlit
 

Slygoxx

Well-Known Member
It's a nice script indeed, though I just mentioned a reason why I personally wouldn't use it. Anyway, you can make it into a userscript here, to make the installation part easier :)
 

DeletedUser

Slight update, moved the last call to where it belongs... (still no mail from userscript.org though)

/Edlit
 
Top