/    Sign up×
Community /Pin to ProfileBookmark

Removing span with Greasemonkey

I am trying to remove the following span:

<span style=”margin: 2px; margin-left: 10px; float: right; width:
301px; height: 251px; padding: 5px; background-color: #000000;”>

Here is my code:

window.addEventListener(‘load’,
function() {
var s;
var find;
find = ‘margin: 2px; margin-left: 10px; float: right; width:
301px; height: 251px; padding: 5px; background-color: #000000′;
s = document.getElementsByTagName(‘body’)
[0].getElementsByTagName(‘span style’)[0];
s.innerHTML = s.innerHTML.replace(find,””);},
true);

What do I need to change to make this work?

I’ve tried many other codes going about it, none seeming to work.

Currently, I have this:

window.addEventListener(‘load’,
function() {
var s;
var find;
find = ‘width: 301px; height: 251px’;
s = document.getElementsByTagName(‘body’)
[0].getElementsByTagName(‘span’)[0];
s.innerHTML = s.innerHTML.replace(find,””);},
true);

I’ve tried some others, but I’ve since deleted those entirely. I know very very little about the java language, so any help is appreciated. I get that it’s calling a function then it has the definitions, but the actual coding just really loses me. I’m too unfamiliar with the formatting and variables.

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@TiffanysauthorFeb 22.2008 — meep?
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 22.2008 — bump x.X
Copy linkTweet thisAlerts:
@LeeUFeb 22.2008 — You'll find that the focus of this forum is more Web development, than script development for greasemonkey.
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 22.2008 — You'll find that the focus of this forum is more Web development, than script development for greasemonkey.[/QUOTE]

Perhaps; but, the script itself is still java.

The script should perhaps be a bit more like this:

[code=php]var x=document.body.getElementsByTagName("span")[0];
x.parentNode.removeChild(x);[/code]


But, it's removing the incorrect span. Here's the entire span:

[code=php]<span style="margin: 2px; margin-left: 10px; float: right; width:
301px; height: 251px; padding: 5px; background-color: #000000;">

<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://
adserver.incgamers.com/www/delivery/ajs.php':'http://
adserver.incgamers.com/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=10");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" +
document.MAX_used);
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" +
escape(document.referrer));
if (document.context) document.write ("&context=" +
escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'></scr"+"ipt>");
//]]>--></script><noscript><a href='http://adserver.incgamers.com/www/
delivery/ck.php?n=a534bee8&amp;cb=INSERT_RANDOM_NUMBER_HERE'
target='_blank'><img src='http://adserver.incgamers.com/www/delivery/
avw.php?zoneid=10&amp;n=a534bee8' border='0' alt='' /></a></noscript>

</span> [/code]


I don't care so much that the ad is left; but, the span itself needs

to go, and if it's easier to simply remove both then that would be the

option to take I suppose. I could give you a link to the site it's

for, you'd need to register to see a post though. The span is embedded

in the 1st post of every page. Basically I'm trying to remove the big

black box.

The site in question is here: http://guildwars.incgamers.com/forums/showthread.php?t=474237

The span is visible at the first post of every page; though, I don't believe you can view threads without registering. Hopefully this is explained sufficiently.
Copy linkTweet thisAlerts:
@Declan1991Feb 22.2008 — [code=php]var x = document.getElementsByTagName("span")[17];
x.parentNode.removeChild(x);[/code]

[code=php]var x = document.getElementsByTagName("span")[16];
x.parentNode.removeChild(x);[/code]

[code=php]var x = document.getElementsByTagName("span")[15];
x.parentNode.removeChild(x);[/code]

I'm not sure which.

And if you are going to contradict members of this forum, please get the correct language. JavaScript is not Java.
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 22.2008 — [code=php]var x = document.getElementsByTagName("span")[17];
x.parentNode.removeChild(x);[/code]

[code=php]var x = document.getElementsByTagName("span")[16];
x.parentNode.removeChild(x);[/code]

[code=php]var x = document.getElementsByTagName("span")[15];
x.parentNode.removeChild(x);[/code]

I'm not sure which.

And if you are going to contradict members of this forum, please get the correct language. JavaScript is not Java.[/QUOTE]


Is that something to get so upset about? Scripting for Greasemonkey is done in Java[b]Script[/b], so I think it's appropriate.

Anyways, this one works:

[code=php]var x = document.getElementsByTagName("span")[16];
x.parentNode.removeChild(x);[/code]


Only problem is that it waits until after the page loads to do it's business.
Copy linkTweet thisAlerts:
@Declan1991Feb 23.2008 — Is that something to get so upset about? Scripting for Greasemonkey is done in Java[b]Script[/b], so I think it's appropriate.
[/QUOTE]

They are totally different languages, much more than simply a name difference. You would be surprised how many people do not know that and post Java here, despite the big red sign on the Java Forum.


Anyways, this one works:

[code=php]var x = document.getElementsByTagName("span")[16];
x.parentNode.removeChild(x);[/code]


Only problem is that it waits until after the page loads to do it's business.[/QUOTE]

That's what Greasemonkey does. If you want it to run before the page loads, either get Opera, or one of the Firefox extensions that does that sort of thing.
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 23.2008 — They are totally different languages, much more than simply a name difference. You would be surprised how many people do not know that and post Java here, despite the big red sign on the Java Forum.


That's what Greasemonkey does. If you want it to run before the page loads, either get Opera, or one of the Firefox extensions that does that sort of thing.[/QUOTE]


Tried Opera, but prefer Firefox. Which extension would you suggest?
Copy linkTweet thisAlerts:
@samliewFeb 23.2008 — I am trying to remove the following span:

<span style="margin: 2px; margin-left: 10px; float: right; width:

301px; height: 251px; padding: 5px; background-color: #000000;">[/QUOTE]


[CODE]var s=document.getElementsByTagName('span');
for(i=0;i<s.length;i++) {
if(s[i].style.margin=="2px" && s[i].style.marginLeft=="10px" && s[i].style.float=="right" && s[i].style.width=="301px" && s[i].style.height=="251px" && s[i].style.padding=="5px" && s[i].style.backgroundColor=="#000000") {
s[i].parentNode.removeChild(s[i]);
}
}[/CODE]
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 23.2008 — [CODE]var s=document.getElementsByTagName('span');
for(i=0;i<s.length;i++) {
if(s[i].style.margin=="2px" && s[i].style.marginLeft=="10px" && s[i].style.float=="right" && s[i].style.width=="301px" && s[i].style.height=="251px" && s[i].style.padding=="5px" && s[i].style.backgroundColor=="#000000") {
s[i].parentNode.removeChild(s[i]);
}
}[/CODE]
[/QUOTE]


While that makes sense, it doesn't seem to work at all; however, then again... Yesterday I noticed that the others stopped working the majority of the time as well.

Not doesn't work before load, but just doesn't work at all. But this is true with all of them now it seems, not just that one. So, I'm thinking "well what the hell? maybe they changed it..." But, nope... It's still the same. So, I have no clue what gives.
Copy linkTweet thisAlerts:
@samliewFeb 23.2008 — try removing all span tags first:
var s=document.getElementsByTagName('span');
for(i=s.length-1;i&gt;=0;i--) {
s[i].parentNode.removeChild(s[i]);
}
}
Copy linkTweet thisAlerts:
@TiffanysauthorFeb 23.2008 — try removing all span tags first:
var s=document.getElementsByTagName('span');
for(i=s.length-1;i&gt;=0;i--) {
s[i].parentNode.removeChild(s[i]);
}
}
[/QUOTE]


Nope... nothing.
Copy linkTweet thisAlerts:
@felgallFeb 23.2008 — You can't interact with a web page using a user JavaScript in the browser at all until the page actually finishes loading. The only way you might be able to get the effect sooner is if you can set up a user stylesheet to hide the field. The stylish extension for Firefox may be useful.
Copy linkTweet thisAlerts:
@samliewFeb 24.2008 — javascript:s=document.getElementsByTagName('span');for(i=s.length-1;i&gt;=0;i--){s[i].parentNode.removeChild(s[i]);}void(0);If you paste this in your address bar it will remove all span tags on your page. You just have to tweak it so that it runs in the script program and removes only the span tag you want.
Copy linkTweet thisAlerts:
@felgallFeb 24.2008 — No need to type in the address bar when you can use a Greasemonkey userscript to do exactly the same thing automatically. The problem is not how to remove the span, it is how to remove it before the page finishes loading and the only place JavaScript can do that is if the author attaches it.

A user stylesheet may work if you can uniquely identify which span the style is to apply to which should be possible using the more advanced style commands that Firefox supports.
×

Success!

Help @Tiffanys spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...