By Nemanja Avramović
Has 3 other scripts.
// ==UserScript==
// @name Ad Slicer for MySpace 2
// @namespace http://www.myspace.com/avramovic
// @include http://myspace.com/*
// @include http://www.myspace.com/*
// @include http://profile.myspace.com/*
// @description Removes all the ads, and the space they leave behind. Based on script by Adrian - http://www.myspace.com/adrian232
// ==/UserScript==
// Last Modified: January 31, 2007
var adS = document.getElementById('srch');
if (adS) {
adS.parentNode.removeChild(adS);
}
html = document.body.innerHTML.replace(/MySpace. All Rights Reserved./, "<a href='http://www.avramovic.info/'>avramovic.info</a>. All Rights Stolen :)");
document.body.innerHTML = html;
(function() {
var frames = document.getElementsByTagName('iframe');
var scripts = document.getElementsByTagName('script');
var images = document.getElementsByTagName('img');
var tables = document.getElementsByTagName('table');
var remove = null, modify = null; // reusable objects
var header = null, topnav = null;
// first, extract them from the new "Home" page
remove = document.getElementById('squareAd');
if (remove) destroy(remove);
remove = document.getElementById('advert');
if (remove) destroy(remove);
remove = document.getElementById('leaderboardRegion');
if (remove) destroy(remove);
remove = document.getElementById('ctl00_Main_ctl00_InfoBar1_pnlAdSpot');
if (remove) destroy(remove);
// resize a few things, just in case it gets stuck
topnav = document.getElementById('topnav');
header = document.getElementById('header');
if (header) header.style['height'] = '40px';
modify = document.getElementById('home_infoBar');
if (modify) modify.style['width'] = '94%';
modify = document.getElementById('header_search');
if (modify) {
modify.style['marginLeft'] = '200px';
modify.style['marginTop'] = '-2em';
}
for (var y = 0; y < images.length; y++) {
if (images[y].parentNode && (images[y].className == 'googleLogo' || images[y].getAttribute('alt') == 'Powered by Google')) {
var google = images[y].parentNode;
/* It's just too much hassle to try to manipulate this, so... Destroy! */
destroy(google);
//google.style['marginTop'] = '-54px';
//googlw.style['marginLeft'] = '54px';
}
}
/* re-justify the right-floating links in header */
/* This never seemed to work right...
if (header) {
//alert('header found!');
for (var y = 0; y < header.childNodes.length; y++) {
var t = header.childNodes[y];
if (t.style && t.className.indexOf('right') != -1) {
t.style['margin-top'] = '-20px';
}
}
}
*/
// loop thru all SCRIPT tags that load ads
for (var y = 0; y < scripts.length; y++) {
var t = scripts[y];
var n = scripts[y].nextSibling;
//t.className = "1"; // debug
/* There are 2 kinds of scripts MySpace uses:
* 1) <script src="blahblah.js"></script> (this one has src defined)
* 2) <script> some.javascript.here(); </script> (this one doesn't)
*/
// ignore any of type 2 that don't contain the oas_ad() function
if (!t.src && t.text.indexOf('oas_ad(') == -1)
continue;
//t.className = "2"; // debug
// ignore all valid myspace scripts
if (t.src.indexOf('x.myspace.com') != -1 ||
t.src.indexOf('cache.static.userplane.com') != -1 // chat script
)
continue;
//t.className = "3"; // debug
// if the next sibling is a script, then stop here
if (!n || n.nodeName == "SCRIPT")
continue;
//t.className = "4"; // debug
// destroy the next sibling
destroy(n);
destroyParent(t);
//t.className = "5"; // debug
}
// the "advertisement" image is a dead giveaway
for (var y = 0; y < images.length; y++) {
if (images[y].src.indexOf('advertisement') != -1) {
destroyParent(images[y]);
destroy(images[y]);
}
}
// destroy all frames, JIC
for (var y = 0; y < frames.length; y++)
destroy(frames[y]);
// un-hide special nodes
for (y = 0; y < tables.length; y++) {
var t = tables[y];
if (t.className == "sidenav") { // for the side navbar in mail
for (var p = t.parentNode; p; p = p.parentNode) {
if (p.nodeName == "TABLE") {
unhide(p);
unhide(p.parentNode);
if (p.previousSibling) // the blank table before it, too
unhide(p.previousSibling.previousSibling);
break;
}
}
}
}
// destroy the parent node
function destroyParent(node) {
var p = node.parentNode;
if (p&& p.id != "content" && // exclusions JIC
p.id != "contentWrap" &&
p.id != "main" &&
p.id != "body" &&
p.id != "aspnetForm" && // form for picture comments
p.nodeName != "BODY" && // don't destroy the BODY tag
p.parentNode && // or any child of the BODY
p.parentNode.nodeName != "BODY" &&
p.parentNode.nodeName.id != "body")
destroy(p);
}
// destroy the node and all its children
function destroy(node) {
for (var y = 0; y < node.childNodes.length; y++) {
var p = node.childNodes[y];
if (p.style)
p.style['display'] = 'none';
}
if (node.style)
node.style['display'] = 'none';
}
function unhide(node) {
if (node && node.style) {
if (node.nodeName == "TABLE")
node.style['display'] = 'table';
else if (node.nodeName == "TD")
node.style['display'] = 'table-cell';
else if (node.nodeName == "TR")
node.style['display'] = 'table-row';
else
node.style['display'] = 'block';
}
}
})();