By Jordon Kalilich
Has 31 other scripts.
// MySpace Ignore Bulletins, a Greasemonkey user script
// Version 1.72 - March 2, 2008
// Copyright 2006-2008 Jordon Kalilich (http://www.theworldofstuff.com/)
// Released under the GPL version 3
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name MySpace Ignore Bulletins
// @namespace http://www.theworldofstuff.com/greasemonkey/
// @description Blacklists or whitelists bulletins from friends you specify.
// @include http://bulletins.myspace.com/*
// @include http://home.myspace.com/*?*fuseaction=user*
// @exclude http://bulletins.myspace.com/index.cfm?*fuseaction=bulletin.ShowMyBulletins*
// ==/UserScript==
/* CONFIGURATION:
After installing this script, you will see a set of controls on your bulletin page.
- Click "Config" or "Configure" to show and edit the IDs of the friends whose bulletins
you want to blacklist or whitelist.
- Click "W" or "White" to show only the bulletins from the users on the list (whitelist).
- Click "B" or "Black" to hide bulletins from the users on the list (blacklist).
- Click "A" or "All" to show all of the bulletins.
You can also add or remove individual friends from the list when reading their bulletins.
(Look for the link that says "Add to blacklist/whitelist.") */
// Only edit below this line if you know what you're doing.
// For compatibility with Home Auto-Update (http://userscripts.org/scripts/show/6365):
window.gm_ignoreBulletins = function() {
var location = window.location.host;
var url = window.location.href;
var isEnhancedBulletins = false;
if (url.indexOf('fuseaction=bulletin.read') == -1) { // if it's a list of bulletins
if (location.indexOf('bulletin') > -1) {
var bulletinTable = document.getElementById('bulletin_inbox');
}
else {
if (document.getElementById('home_bulletins')) { // classic view
var bulletinTable = document.getElementById('home_bulletins').getElementsByTagName('table')[0];
}
else { // new home skin
var bulletinTable = document.getElementById('tblbulletins');
if (bulletinTable.className.indexOf('hau_eBuls') > -1) isEnhancedBulletins = true;
}
}
if (!GM_getValue('friends')) {
GM_setValue('friends', 'nothing');
}
var friendsList = GM_getValue('friends', 'nothing').split(' ');
var friends = new Array();
var friendNames = new Array();
for (var i = 0; i < friendsList.length; i++) {
if (friendsList[i].indexOf(':') > -1) {
var explodedFriend = friendsList[i].split(':');
friendNames[i] = explodedFriend[0];
friends[i] = explodedFriend[1];
}
else {
friendNames[i] = '';
friends[i] = friendsList[i];
}
}
var show = GM_getValue('show', 'not_specified');
var hitRows = new Array();
var nonHitRows = new Array();
var rows = bulletinTable.rows;
function getRows() {
if (isEnhancedBulletins == false) {
for (var i = 1; i < rows.length; i++) {
var profileLink = rows[i].getElementsByTagName('a')[0].href.toLowerCase();
for (var j = 0; j < friends.length; j++) {
var key = 'friendid=' + friends[j];
if (profileLink.indexOf(key) > -1) {
hitRows[i] = '<tr>' + rows[i].innerHTML + '</tr>'; // add to HitRows
nonHitRows[i] = '0'; // keep 'em even
break;
}
// if this is the last loop-through and it's not a match
if (j == (friends.length - 1)) {
nonHitRows[i] = '<tr>' + rows[i].innerHTML + '</tr>';
hitRows[i] = '0';
}
}
}
}
else { // for enhanced bulletins
for (var i = 0; i < rows.length; i+=2) {
var profileLink = rows[i].getElementsByTagName('a')[0].href.toLowerCase();
for (var j = 0; j < friends.length; j++) {
var key = 'friendid=' + friends[j];
if (profileLink.indexOf(key) > -1) {
hitRows[i] = '<tr>' + rows[i].innerHTML + '</tr>'; // add to HitRows
hitRows[i+1] = '<tr>' + rows[i+1].innerHTML + '</tr>';
nonHitRows[i] = '0'; // keep 'em even
nonHitRows[i+1] = '0'; // keep 'em even
break;
}
// if this is the last loop-through and it's not a match
if (j == (friends.length - 1)) {
nonHitRows[i] = '<tr>' + rows[i].innerHTML + '</tr>';
nonHitRows[i+1] = '<tr>' + rows[i+1].innerHTML + '</tr>';
hitRows[i] = '0';
hitRows[i+1] = '0';
}
}
}
}
}
getRows();
showSelected();
} else { // if it's an individual bulletin
var bulletinFrom = document.getElementById('read_from');
var friendID = bulletinFrom.innerHTML.match(/\d+/);
var link = document.createElement('a');
link.href = '#';
var friendsList = GM_getValue('friends');
if (friendsList) {
friendsList = GM_getValue('friends').split(' ');
for (i = 0; i < friendsList.length; i++) {
if (friendsList[i].indexOf(friendID) > -1) {
link.innerHTML = '(Remove from blacklist/whitelist)';
link.id = 'removeFromList';
break;
}
}
}
if (!link.innerHTML) { // if there are no friends or they're just not on the list
link.innerHTML = '(Add to blacklist/whitelist)';
link.id = 'addToList';
}
var userName = bulletinFrom.getElementsByTagName('a')[bulletinFrom.getElementsByTagName('a').length - 1];
var br = document.createElement('br');
userName.parentNode.insertBefore(br, userName.nextSibling);
br.parentNode.insertBefore(link, br.nextSibling);
var addLink = document.getElementById('addToList');
if (addLink) {
addLink.addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
var friendName = window.prompt('Enter a name for this friend, or leave blank. (If you don\'t enter one, this person\'s friend ID, not their name, will be shown in the blacklist/whitelist.)');
if (friendName) {
friendName = friendName.replace(/:/g,'');
friendName = friendName.replace(/ /g,'_');
}
// now, if friendName wasn't obliterated...
if (friendName == null) { // if they hit cancel, it's null
return;
}
else if (friendName != '') {
if (GM_getValue('friends') != 'nothing') {
var friends = GM_getValue('friends') + ' ' + friendName + ':' + friendID;
}
else {
var friends = friendName + ':' + friendID;
}
}
else {
if (GM_getValue('friends') != 'nothing') {
var friends = GM_getValue('friends') + ' ' + friendID;
}
else {
var friends = friendID;
}
}
trimAndSubmit(friends);
}, true);
}
var removeLink = document.getElementById('removeFromList');
if (removeLink) {
removeLink.addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
var confirmRemoveFriend = confirm('Remove this friend from blacklist/whitelist?');
if (confirmRemoveFriend) {
for (i = 0; i < friendsList.length; i++) {
if (friendsList[i].indexOf(friendID) > -1) {
friendsList[i] = '';
break;
}
}
var friends = friendsList.join(' ');
trimAndSubmit(friends);
}
}, true);
}
}
// show rows of choice
function showSelected() {
if (isEnhancedBulletins == false) {
bulletinTable.innerHTML = '<thead><tr>' + rows[0].innerHTML + '</tr></thead>';
var showStartIndex = 1;
}
else {
bulletinTable.innerHTML = ''; // or else the rows will keep adding on over and over and over...
/* however, this might cause a bug where if you change variable "show" (it would have to be done
on the bulletins.myspace.com listing), after that, the bulletin list on the homepage will be empty,
and then when HAU updates it again, it will appear correctly with the new show value. */
var showStartIndex = 0;
}
if (show == 'not_specified') {
for (var i = showStartIndex; i < nonHitRows.length; i++) {
if (nonHitRows[i] != '0') {
bulletinTable.innerHTML += nonHitRows[i];
}
}
}
else if (show == 'only_specified') {
for (var i = showStartIndex; i < hitRows.length; i++) {
if (hitRows[i] != '0') {
bulletinTable.innerHTML += hitRows[i];
}
}
}
else if (show == 'all') {
for (var i = showStartIndex; i < nonHitRows.length; i++) {
if (nonHitRows[i] != '0') {
bulletinTable.innerHTML += nonHitRows[i];
}
else {
bulletinTable.innerHTML += hitRows[i];
}
}
}
// now add alternate coloring to rows for themes that support it
if (isEnhancedBulletins == false) {
for (i = 1; i < bulletinTable.rows.length; i++) {
if (i % 2 == 0) bulletinTable.rows[i].className = 'roweven';
else bulletinTable.rows[i].className = 'rowodd';
}
}
else {
for (i = 0; i < bulletinTable.rows.length; i+=2) {
if (i % 4 == 0) {
bulletinTable.rows[i].className = 'rowodd';
bulletinTable.rows[i+1].className = 'rowodd';
} else {
bulletinTable.rows[i].className = 'roweven';
bulletinTable.rows[i+1].className = 'roweven';
}
}
}
// fix firefox bug with enhanced bulletins; the thead and tbody tags lead to rowspan issues.
if (isEnhancedBulletins == true) bulletinTable.innerHTML = bulletinTable.innerHTML.replace(/<\/?t(head|body)>/ig,'');
if (isEnhancedBulletins == false) addListeners();
}
// add controls on top
function addListeners() {
if (location.indexOf('bulletin') > -1) {
var onlyLink = "White";
var hideLink = "Black";
var allLink = "All";
var configLink = "Configure";
}
else {
var onlyLink = "W";
var hideLink = "B";
var allLink = "A";
var configLink = "Config";
}
var bulletinTableHeaderShort = 'From (<a href="#" id="only_specified" title="Show bulletins only from specified friends (whitelist)" style="margin: 0px; display: inline">' + onlyLink + '</a>/<a href="#" id="not_specified" title="Hide bulletins from specified friends (blacklist)" style="margin: 0px; display: inline">' + hideLink + '</a>/<a href="#" id="all" title="Show bulletins from all friends" style="margin: 0px; display: inline">' + allLink + '</a>)<br /><div id="configContainer" style="display: inline; position: relative; z-index: 100; padding: 0px">';
var bulletinTableHeaderLong = bulletinTableHeaderShort + '<a href="#" id="config" title="Configure blacklist/whitelist" style="margin: 0px; padding: 0px; display: inline">' + configLink + '</a></div>'
bulletinTable.rows[0].cells[0].innerHTML = bulletinTableHeaderLong;
document.getElementById(show).style.backgroundColor = '#ff0';
document.getElementById('only_specified').addEventListener('click', function(event) {
event.stopPropagation(); // this line and the next prevent the default action (going to the link)
event.preventDefault();
GM_setValue('show', 'only_specified');
show = 'only_specified';
showSelected();
}, true);
document.getElementById('not_specified').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
GM_setValue('show', 'not_specified');
show = 'not_specified';
showSelected();
}, true);
document.getElementById('all').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
GM_setValue('show', 'all');
show = 'all';
showSelected();
}, true);
document.getElementById('config').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
configA = document.getElementById('config');
configTable = document.createElement('table');
configTable.style.position = 'absolute';
configTable.style.left = '30px';
configTable.style.backgroundColor = "#fff";
var row = document.createElement('tr');
var cellTitle = document.createElement('td');
cellTitle.style.fontWeight = 'bold';
cellTitle.innerHTML = 'Friends to show/hide';
cellTitle.style.overflow = 'visible';
cellTitle.style.padding = '5px';
row.appendChild(cellTitle);
var cellClose = document.createElement('td');
cellClose.style.width = '10px';
cellClose.innerHTML = '<a href="#" id="close" title="Close" style="display: inline">X</a>';
cellClose.style.overflow = 'visible';
cellClose.style.padding = '5px';
row.appendChild(cellClose);
configTable.appendChild(row);
var row = document.createElement('tr');
var cellFriends = document.createElement('td');
cellFriends.colSpan = '2';
cellFriends.id = 'friendCell';
if (friends[0] != 'nothing') {
for (var i = 0; i < friendsList.length; i++) {
if (friendNames[i] == '') {
cellFriends.innerHTML += '<a href="http://www.myspace.com/' + friends[i] + '" target="_blank" style="display: inline">' + friends[i] + '</a><br />';
}
else {
cellFriends.innerHTML += '<a href="http://www.myspace.com/' + friends[i] + '" target="_blank" style="display: inline">' + friendNames[i] + '</a><br />';
}
}
} else {
cellFriends.innerHTML = 'None';
}
cellFriends.style.overflow = 'visible';
cellFriends.style.padding = '5px';
row.appendChild(cellFriends);
configTable.appendChild(row);
var row = document.createElement('tr');
var cellEditButton = document.createElement('td');
cellEditButton.id = 'buttonRow';
cellEditButton.style.textAlign = 'center';
cellEditButton.colSpan = '2';
cellEditButton.innerHTML = '<input type="button" value="Edit" id="edit" />';
cellEditButton.style.overflow = 'visible';
cellEditButton.style.padding = '5px';
row.appendChild(cellEditButton);
configTable.appendChild(row);
configA.parentNode.insertBefore(configTable, configA.nextSibling);
document.getElementById('close').addEventListener('click', function(event2) {
event2.stopPropagation();
event2.preventDefault();
configTable.parentNode.removeChild(configTable);
addListeners();
}, true);
document.getElementById('edit').addEventListener('click', function(event2) {
event2.stopPropagation();
event2.preventDefault();
document.getElementById('friendCell').innerHTML = '';
var friendText = document.createElement('textarea');
friendText.style.fontFamily = 'verdana,arial,sans-serif,helvetica';
friendText.style.fontSize = '8pt';
friendText.rows = '5';
friendText.cols = '22';
friendText.id = 'friendText';
if (friends[0] != 'nothing') {
for (var i = 0; i < friendsList.length; i++) {
if (i < friendsList.length - 1) {
friendText.value += friendsList[i] + ' ';
} else {
friendText.value += friendsList[i];
}
}
}
document.getElementById('friendCell').innerHTML = '<span style="font-weight: normal">Separate each friend ID with a space. You can prefix each ID with a name and a colon (<i>Luke:42793928</i>) for convenience.</span><br />';
document.getElementById('friendCell').appendChild(friendText);
document.getElementById('buttonRow').innerHTML = '<input type="button" value="OK" id="ok" /> <input type="button" value="Cancel" id="cancel" />';
document.getElementById('ok').addEventListener('click', function(event3) {
var textareaValue = document.getElementById('friendText').value;
trimAndSubmit(textareaValue);
}, true);
document.getElementById('cancel').addEventListener('click', function(event3) {
configTable.parentNode.removeChild(configTable);
addListeners();
}, true);
}, true);
var configNonLink = document.createTextNode(configLink);
configA.parentNode.replaceChild(configNonLink, configA);
}, true);
}
function trimAndSubmit(input) {
input += ''; // ghetto way of converting a number to a string (in case it's just a number)
input = input.replace(/(^\s+|\s+$)/g,''); // trim spaces on ends
input = input.replace(/\s+/g,' '); // change multiple or weird spaces to single regular spaces
if (input != '') {
// test for other invalid characters
if (/^(([^\s:]+:)?\d+ )*([^\s:]+:)?\d+$/.test(input) == true) {
GM_setValue('friends', input);
window.location.reload();
}
else {
alert('Please check your formatting. Each friend ID should be separated by a space. Friend names (optional) may not contain spaces; try underscores (_) instead.');
}
}
else {
GM_setValue('friends', 'nothing');
window.location.reload();
}
}
} // end of function that does everything
gm_ignoreBulletins(); // call it
// UPDATE NOTIFIER (Version 7: January 14, 2008)
// (Inspired by UserScript Update Notification by Seifer: http://userscripts.org/scripts/show/12193)
var scriptName = "MySpace Ignore Bulletins";
var scriptID = '5618';
var scriptVersion = 1.72;
var scriptChanges = "Fixed formatting problems in the blacklist/whitelist."
var checkForUpdates = GM_getValue('checkForUpdates', true);
if (checkForUpdates == true) {
var lastCheck = GM_getValue('lastCheck', 0);
var d = new Date();
var currentTime = Math.round(d.getTime() / 1000); // Unix time in seconds
if (currentTime >= lastCheck + 1209600) { // (number of seconds in 2 weeks
GM_xmlhttpRequest({
method: 'GET',
url: 'http://userscripts.org/scripts/review/' + scriptID + '?format=txt',
headers: {'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey','Accept': 'text/plain',},
onload: function(responseDetails) {
var script = responseDetails.responseText;
var chooseToUpdate;
function createNotice(noticeText) {
var notice = document.createElement('div');
with (notice.style) { id = 'GMscriptnotice'; position = 'fixed'; top = '0px'; left = '0px'; width = '100%'; background = '#ffeb7c'; zIndex = '1000'; textAlign = 'center'; font = '12px sans-serif'; fontWeight = 'normal'; color = '#000'; padding = '5px 3px 5px 3px'; margin = '0px'; borderTop = '0px'; borderRight = '0px'; borderBottom = '1px solid #beaf5d'; borderLeft = '0px'; }
notice.innerHTML = noticeText;
document.getElementsByTagName('body')[0].appendChild(notice);
document.getElementById('upgradeLink').addEventListener('click', function(event) {
notice.parentNode.removeChild(notice);
}, true);
document.getElementById('waitLink').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
alert('You will be notified again after two weeks.');
notice.parentNode.removeChild(notice);
}, true);
document.getElementById('offLink').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
var confirmTurnOff = confirm('Are you sure you no longer want to be notified of updates to this script?');
if (confirmTurnOff) {
alert('You will no longer be notified of updates to ' + scriptName + '. You can change this preference in about:config.');
GM_setValue('checkForUpdates', false);
notice.parentNode.removeChild(notice);
}
}, true);
}
var linkStyle = 'color: #00f; text-decoration: underline; font: 12px sans-serif';
if (script.indexOf('var scriptVersion = ' ) > -1) {
var foo = script.match(/var scriptVersion = [\d\.]+/i) + ''; // makes it a string
var versionOnSite = foo.match(/[\d\.]+/);
if (versionOnSite != scriptVersion) {
var newScriptChanges = '';
foo = script.match(/var scriptChanges = "[^"]+"/i) + '';
if (foo) {
foo = foo.match(/"[^"]+"/) + '';
newScriptChanges = 'What\'s new in version ' + versionOnSite + ': ' + foo.replace(/"/g,'') + '<br />';
}
var noticeText = 'An update to the Greasemonkey user script "' + scriptName + '" is available. You are running version ' + scriptVersion + '.<br />' + newScriptChanges + '<a href="http://userscripts.org/scripts/source/' + scriptID + '.user.js" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">Upgrade to version ' + versionOnSite + ' now</a>, <a href="#" style="' + linkStyle + '; font-weight: normal" id="waitLink">wait until later</a>, or <a href="#" style="' + linkStyle + '; font-weight: normal" id="offLink">turn off these notifications</a>.';
createNotice(noticeText);
}
}
else { // if the new version of the script doesn't have this update mechanism
var noticeText = 'An update to the Greasemonkey user script "' + scriptName + '" is available.<br /><a href="http://userscripts.org/scripts/source/' + scriptID + '.user.js" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">Upgrade now</a>, <a href="#" style="' + linkStyle + '; font-weight: normal" id="waitLink">wait until later</a>, or <a href="#" style="' + linkStyle + '; font-weight: normal" id="offLink">turn off these notifications</a>.';
createNotice(noticeText);
}
}
});
GM_setValue('lastCheck', currentTime);
}
}
// END OF UPDATE NOTIFIER