There are 6 previous versions of this script.
// ==UserScript==
// @name bgu.co.il Forum Tweaker
// @namespace agmonm@gmail.com
// @description Tweaks bgu.co.il forums
// @version 0.0.8.5
// @include http://forum.bgu.co.il/*
// ==/UserScript==
// We don't want to mess around with different
// kind of forum pages (maybe old links)
// It is best to leave this function as is
if (window.location.search.match("act=SF"))
{
window.location.replace(window.location.href.replace(/http:\/\/forum.bgu.co.il\/index.php\?act=SF\&s=\&f=/, "http://forum.bgu.co.il/index.php?showforum="));
}
// General functions begins here - better not
// messing with them if you don't know how
function doEval(what)
{
return document.evaluate(
what,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
}
function isForumPage()
{
var a = doEval("//script[@src='jscripts/ipb_forum.js']");
return a.snapshotLength;
}
function removeElementById(element_id)
{
var a = document.getElementById(element_id);
if (a) {
a.parentNode.removeChild(a);
}
}
function getForumNumber()
{
if (isForumPage()){
var a = doEval("//input[@name='forums']");
return a.snapshotItem(0).value;
}
else
return null;
}
function plantCSS(css){
if (typeof GM_addStyle != "undefined") {
GM_addStyle(css);
}
else if (typeof addStyle != "undefined") {
addStyle(css);
}
else {
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
var node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
heads[0].appendChild(node);
}
}
}
// Forum spesific functions begins here
function removeLeftAd()
{
var all = doEval("//td[@width='124']");
var a;
if(all.snapshotLength){
a = all.snapshotItem(0);
a.parentNode.removeChild(a);
}
}
function removeCopyright()
{
var b, a = doEval("//div[@class='copyright']");
a = a.snapshotItem(0);
b = a.nextSibling;
while (b) {
if (b.nodeName=='DIV') {
b = b.nextSibling;
b.parentNode.removeChild(b.previousSibling);
}
else
b = b.nextSibling;
}
a.parentNode.removeChild(a);
}
function showonlynewposts()
{
var all, a;
all = doEval("//img[@src='style_images/resources/f_norm_no.gif'] | //img[@src='style_images/resources/f_norm_no_dot.gif'] | //img[@src='style_images/resources/f_hot_no.gif'] | //img[@src='style_images/resources/f_hot_no_dot.gif'] | //img[@src='style_images/resources/f_poll_no.gif'] | //img[@src='style_images/resources/f_poll_no_dot.gif'] | //img[@src='style_images/resources/f_closed.gif'] | //img[@src='style_images/resources/f_moved.gif']");
for (var i=0;i<all.snapshotLength;i++) {
a = all.snapshotItem(i);
if (!a.nextSibling) {
a = a.parentNode;
a = a.parentNode;
a.parentNode.removeChild(a);
}
}
var b = document.getElementById('showhide');
b.setAttribute("value", "Show old threads");
b.setAttribute("alt", "Show old threads");
b.addEventListener('click',showAllPosts,true);
}
function showAllPosts()
{
window.location.reload(false);
}
function markPostsAsRead()
{
var i = getForumNumber();
window.location.href = 'http://forum.bgu.co.il/index.php?act=Login&CODE=04&f=' + [i] +'&fromforum=' + [i];
}
function putButtons()
{
var all, a;
var button1 = document.createElement("input");
button1.setAttribute("value", "Hide old threads");
button1.setAttribute("id", "showhide");
button1.setAttribute("alt", "Hide old threads");
button1.setAttribute("type", "button");
button1.addEventListener('click',showonlynewposts,true);
var button2 = document.createElement("input");
button2.setAttribute("value", "Mark posts as read");
button2.setAttribute("alt", "Mark posts as read");
button2.setAttribute("type", "button");
button2.addEventListener('click',markPostsAsRead,true);
if(isForumPage()) {
all = doEval("//img[@src='style_images/resources/t_new.gif']");
if(all.snapshotLength) {
a = all.snapshotItem(0);
a = a.parentNode;
a = a.parentNode;
a.parentNode.insertBefore(button1, a);
a.parentNode.insertBefore(button2, a);
}
}
}
function moveSubForums()
{
var a, b, i = getForumNumber();
a = document.getElementById('fo_'+[i]);
if (a) {
b = doEval("//form[@name='search']");
if (b.snapshotLength) {
b = b.snapshotItem(0).parentNode;
while (b) {
if (b.nodeName=='DIV' && b.className=='borderwrap') break;
b = b.parentNode;
}
a.parentNode.removeChild(a);
b.parentNode.insertBefore(a, b.nextSibling);
}
}
}
function collapseSubForumsBox()
{
var i = getForumNumber();
if (isForumPage()) {
var a = document.getElementById('fo_' + [i]);
if (a) {
a.style.cssText = 'display: none';
a = document.getElementById('fc_' + [i]);
a.style.cssText = '';
}
}
}
function expandSubForumsBox()
{
var i = getForumNumber();
if (isForumPage()) {
var a = document.getElementById('fc_' + [i]);
if (a) {
a.style.cssText = 'display: none';
a = document.getElementById('fo_' + [i]);
a.style.cssText = '';
}
}
}
function addSubForumsEventListener()
{
var i = getForumNumber();
if (isForumPage()) {
var a = document.getElementById('fo_' + [i]);
if (a) {
a = a.firstChild.nextSibling;
a.addEventListener('click',collapseSubForumsBox,false)
a = document.getElementById('fc_' + [i]);
a.addEventListener('click',expandSubForumsBox,false)
}
}
}
function removeForumHeadMessage()
{
var all, a;
all = doEval("//div[@class='borderwrap']");
if(all.snapshotLength) {
for (var i=0; a=all.snapshotItem(i); i++) {
if (a.innerHTML.match("<h3>"))
a.parentNode.removeChild(a);
}
}
}
function removeBrLines()
{
if (isForumPage()) {
var a = document.getElementById('ipbwrapper');
var b = a.firstChild;
while (b) {
if (b.nodeName=='BR') {
b = b.nextSibling;
b.parentNode.removeChild(b.previousSibling);
}
else
b = b.nextSibling;
}
}
}
// The following function is a small remake of the code taken from Hampei's script
// http://userscripts.org/scripts/show/15326
function removeSignatureImages()
{
var imgs = doEval("//div[@class='signature']//img");
for (var i=0, img; img = imgs.snapshotItem(i); i++)
img.parentNode.removeChild(img);
}
function removeSignatureVideo()
{
var objects = doEval("//div[@class='signature']//object");
for (var i=0, object; object = objects.snapshotItem(i); i++)
object.parentNode.removeChild(object);
}
function removePinnedSeperator()
{
var all = doEval("//td[@class='darkrow1']");
for (var i=0, a; a=all.snapshotItem(i); i++) {
if (a.innerHTML.match("<b>")) {
if (a.innerHTML.length<=20)
a.parentNode.parentNode.removeChild(a.parentNode);
}
}
}
function maximizeWidth()
{
var ipbwrapper = document.getElementById('ipbwrapper');
ipbwrapper.style.margin = '0pt';
ipbwrapper.style.width = '100%';
}
function changeForumLinks()
{
var all = doEval("//form[@name='jumpmenu']");
if (all.snapshotLength) {
var a = all.snapshotItem(0);
a.action = a.action.replace(/act=SF/, "");
var b = a.firstChild;
while (b) {
if (b.nodeName=='INPUT' && b.type=='hidden') {
b = b.nextSibling;
b.parentNode.removeChild(b.previousSibling);
}
else if (b.nodeName=='SELECT' && b.name=='f') {
b.name = "showforum";
b = b.nextSibling;
}
else
b = b.nextSibling;
}
}
}
function addNewSearchBox()
{
if (isForumPage()) {
var a = document.getElementById('forummenu-options');
var b = doEval("//form[@name='search']").snapshotItem(0);
var newcell = document.createElement("td");
newcell.innerHTML = '<td><form action="http://forum.bgu.co.il/index.php?" method="post" name="search2">' +
b.innerHTML +
'</form></td>';
a.parentNode.parentNode.firstChild.nextSibling.width='60%';
a.parentNode.parentNode.insertBefore(newcell, a.parentNode);
}
}
function highlightTopic(){
var css = "@namespace url(http://www.w3.org/1999/xhtml); .row1:hover { background-color: rgb(255,255,210) !important;}";
plantCSS(css);
}
function moveCurrentUsers()
{
if (isForumPage()) {
var all = doEval("//div[@class='activeusers']");
var a = all.snapshotItem(0);
var b = a.previousSibling.previousSibling.previousSibling;
b.parentNode.removeChild(b);
a = document.getElementById('ipbwrapper');
a.insertBefore(b, a.firstChild);
}
else if (window.location.search) {
var all = doEval("//div[@class='borderwrap']");
for (var i=0, b; b=all.snapshotItem(i); i++) {
if (b.innerHTML.match("formsubtitle"))
break;
}
b.parentNode.removeChild(b);
var a = document.getElementById('ipbwrapper');
a.insertBefore(b, a.firstChild);
}
}
function fixeFiltersForm()
{
var i = getForumNumber();
if (isForumPage()) {
var all = doEval("//form[@action='http://forum.bgu.co.il/index.php?act=SF&f=" + i + "&st=0&changefilters=1']");
if(all.snapshotLength) {
var a = all.snapshotItem(0);
a.action = "http://forum.bgu.co.il/index.php?showforum=" + i + "&changefilters=1";
}
}
}
function addCustomFilters()
{
var i = getForumNumber();
if (isForumPage()) {
var all = doEval("//th[@width='50%']");
if(all.snapshotLength==1) {
var a = all.snapshotItem(0);
a = a.nextSibling.nextSibling;
a.innerHTML = '<form method="post" action="http://forum.bgu.co.il/index.php?showforum=' + i + '&changefilters=1"><input type="hidden" name="sort_key" value="posts"><input class="button" type="submit" value="תגובות"></form>';
a = a.nextSibling.nextSibling;
a = a.nextSibling.nextSibling;
a.innerHTML = '<form method="post" action="http://forum.bgu.co.il/index.php?showforum=' + i + '&changefilters=1"><input type="hidden" name="sort_key" value="views"><input class="button" type="submit" value="צפיות"></form>';
a = a.nextSibling.nextSibling;
a.innerHTML = '<form method="post" action="http://forum.bgu.co.il/index.php?showforum=' + i + '&changefilters=1"><input type="hidden" name="sort_key" value="last_post"><input class="button" type="submit" value="פעולה אחרונה"></form>';
}
}
}
function alertGM(a, firstPost){
a.innerHTML = '<div style="float: left;"><input type="button" value="Preview"></div>' + a.innerHTML + firstPost;
}
function putPreviewButtons()
{
if (isForumPage()) {
var all = doEval("//td[@class='row1']");
if(all.snapshotLength) {
for(var i=0, a; a = all.snapshotItem(i); i++) {
if (a.innerHTML.match("float: right;")) {
var beginTopicNumber = (a.innerHTML.indexOf('<span id="tid-span-'));
var endTopicNumber = (a.innerHTML.indexOf('">', beginTopicNumber));
var topicNumber = a.innerHTML.substring(beginTopicNumber+19, endTopicNumber);
var urlToFetch = 'http://forum.bgu.co.il/index.php?showtopic=' + topicNumber;
GM_xmlhttpRequest({
method:"GET",
url:urlToFetch,
headers:{
"User-Agent":"Mozilla/5.0",
"Accept":"text/xml"
},
onload:function(response) {
var beginDiv = (response.responseText.indexOf('<div class="postcolor"'));
var endDiv = (response.responseText.indexOf('</div>', beginDiv));
var firstPost = response.responseText.substring(beginDiv, endDiv+6);
alertGM(a, firstPost);
}
});
}
}
}
}
}
// This is a counter measure for preventing the forum
// from jumping to unwanted pages (with unknown formatting)
// It is best to leave this function as is !
changeForumLinks();
// This will remove the top logo strip and the ad next to it
removeElementById('logostrip');
// This will remove the left side ad and its wasted width
removeLeftAd();
// This will maximize the board width to 100%
maximizeWidth();
// This will remove the announcement (head message) from some forums
removeForumHeadMessage();
// This will remove some redundant <br> lines
removeBrLines();
// This will move the subforums section to the bottom
//moveSubForums();
// Change behaviour of subforums box - this is very useful regardless the other functions
addSubForumsEventListener();
// Collapse the subforms box on page load
//collapseSubForumsBox();
// This will create a "hide old threads" button on forum pages
putButtons();
// This will remove the seperator between pinned & regular threads
//removePinnedSeperator();
// This will remove the footer bar (rss, style, language)
removeElementById('gfooter');
// This will remove the bottom IPB copyright lines and bottom links
removeCopyright();
// This will remove all images from the signatures - leaving only text
removeSignatureVideo();
removeSignatureImages();
// This will add another search-box at the top
addNewSearchBox();
// This will move the "active users" box to the top
//moveCurrentUsers();
// This function is not working yet, don't uncomment this unless
// you know what you're doing
highlightTopic();
// Need to fix the action of the filter. Otherwise, causes infinite loop
fixeFiltersForm();
// Replace regular columns text labels with filter-buttons
addCustomFilters();
// Experimental - NOT WORKING YET! DO NOT ENABLE!
//putPreviewButtons();
