User:Void Singer/SL Forum Ignore
Jump to navigation
Jump to search
SL Forum Ignore
Features:
- requires FireFox 3.mumble
- requires Greasemonkey some-version-or-another
User Script
// ==UserScript==
// @name SL Forum Ignore
// @namespace Private
// @description Adds Ignore Links to User Posts on SL Forum Discussions/Questions (And Make Linden Names RED)
// @include https://blogs.secondlife.com/thread/*
// @include https://blogs.secondlife.com/message/*
// ==/UserScript==
//-- Inject links, mark posts, and hide already ignored posts
function uSetupPage(){
var vColDivs, vObjDiv, vObjLink, vStrUserName, vStrLinkText, vStrPostStyle;
vColDivs = //-- grab the divs we need from the DOM, don't worry they ARE in page order
document.evaluate( "(//div[@class='jive-thread-post-body-container'] | //div[@class='jive-thread-reply-body-container'] | //div[@class='jive-username-link-wrapper'])",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null );
//-- loop through the divs in order
for (var vIntCounter = 0; vIntCounter < vColDivs.snapshotLength; vIntCounter++){
vObjDiv = vColDivs.snapshotItem( vIntCounter ); //-- grab first div, AKA user name
vStrUserName = vObjDiv.childNodes.item( 1 ).href; //-- unsafe, needs rewritten
vStrUserName = vStrUserName.substring( vStrUserName.lastIndexOf( "/" ) + 1 ); //-- grab the user name
if (vStrUserName.indexOf( "Linden" ) == -1){ //-- thou shalt not bite the hand that feeds you
if (GM_getValue( vStrUserName, 0 ) == 1){ //-- is this user already on ignore?
//-- set ignore button text and blank post attributes
vStrLinkText = 'UnIgnore';
vStrPostStyle = 'display:none;';
}else{
//-- set ignore button text attribute
vStrLinkText = 'Ignore';
vStrPostStyle = '';
}
//-- create, watch, and insert ignore link after user name
vObjLink = document.createElement( 'a' );
vObjLink.setAttribute( 'name', vStrUserName );
vObjLink.setAttribute( 'href', 'javascript:void( 0 );' );
vObjLink.setAttribute( 'style', 'color:orange;' );
vObjLink.setAttribute( 'onclick', "uIgnore( '" + vStrUserName + "');" );
vObjLink.textContent = vStrLinkText;
vObjLink.addEventListener( 'click', uPersist, true ); //-- this makes the magic work
vObjDiv.appendChild( document.createElement( 'br' ) );
vObjDiv.appendChild( vObjLink );
//-- jump to next div, AKA post body, insert name and style
vObjDiv = vColDivs.snapshotItem(++vIntCounter);
vObjDiv.setAttribute( 'name', vStrUserName + '.post' );
vObjDiv.setAttribute( 'style', vStrPostStyle );
}else{
vObjDiv.childNodes.item( 1 ).setAttribute( 'style', 'color:red' ); //-- unsafe, needs rewritten
vIntCounter++; //-- twas a Linden, skip the post body
}
}
}
//-- create and insert script object into page to handle ignore status changes
function uInjectStatusHandler(){
var vInject = document.createElement( 'script' );
vInject.setAttribute( 'type', 'application/javascript' );
vInject.textContent =
//-- this injected scriplet function will parse all posts / ignore links to change them when switching modes
"\nuIgnore = function( vStrName ){" +
"\n var vColLinks, vColPosts, vStrLinkText, vStrPostStyle;" +
"\n vColLinks = document.getElementsByName( vStrName );" + //-- collect all this names ignore links
"\n vColPosts = document.getElementsByName( vStrName + '.post' );" + //-- collect all this names posts
"\n vStrLinkText = vColLinks[0].textContent;" + //-- get action to preform from link text
"\n if (vStrLinkText == 'Ignore'){" + //-- preset ignored attributes for links/posts
"\n vStrLinkText = 'UnIgnore';" +
"\n vStrPostStyle = 'display:none;';" +
"\n }else{" + //-- preset unignored attributes for links/posts
"\n vStrLinkText = 'Ignore';" +
"\n vStrPostStyle = '';" +
"\n }" +
"\n for (var vIntCounter = vColLinks.length - 1; vIntCounter > -1; vIntCounter --){" + //-- loop through and set attributes
"\n vColLinks[vIntCounter].textContent = vStrLinkText;" +
"\n vColPosts[vIntCounter].setAttribute( 'style', vStrPostStyle );" +
"\n }" +
"\n}\n";
document.body.appendChild( vInject ); //-- inject scriptlet so it can run in the page context
}
//-- magic to persist ignore settings, runs in sandbox context
function uPersist(){
if (this.textContent == "UnIgnore"){ //-- has the person been ignored?
GM_setValue( this.name, 1 ); //-- store the name for future pages
if (this.name == "Void.Singer"){ //-- should probably remove this if statement..... Naaaaah =P
alert( "Well isn't that gratitude for ya\nYa know I wrote this ignore script... right?\n\n=p thppppppt! " );
}
}else{
if (GM_getValue( this.name ) == 1){ //-- delete names that aren't on ignore any more
GM_deleteValue( this.name );
}
}
}
uInjectStatusHandler(); //-- inject status changer
uSetupPage(); //-- format the page
/*//-- License Text --//*/
/*// Free to copy, use, modify, distribute, or sell, with attribution. //*/
/*// (C)2009 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*// All usages must contain a plain text copy of the previous 2 lines. //*/
/*//-- --//*/