/    Sign up×
Community /Pin to ProfileBookmark

Replacing parts of source

Hi I want to replace some of the HTML code of the current document with Javascript (Greasemonkey in Firefox). The problem is, that it is not just one tag.

Here is the source:

[code]Cheaterhossie</a></b><br /><br />
<img src=’./avatare/leet.gif’ alt=’Leet’ border=0 />[/code]

Now I want to replace that “leet.gif” with another image, but [u]only[/u] when the username is indeed “Cheaterhossie” like above. Also mind that newline and spaces in the source.

My basic approach

[code]var oldbody = document.body.innerHTML;
var newbody = oldbody.replace(“/xxx/”, “xxx”);
window.addEventListener(
‘load’,
function() { document.body.innerHTML = newbody; },
true);[/code]

didn’t work.

Can anybody help? ?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@CharlesMay 29.2005 — What you want to do is pretty easy, but I need a little more mark up. If you had &lt;div&gt;&lt;a&gt;Cheaterhossie&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;
&lt;img src='./avatare/leet.gif' alt='Leet' border=0 /&gt;&lt;/div&gt;
Then you might use (function () {
var e, i = 0;
while (e = document.getElementsByTagName ('img')[i++]) {if (/leet.gif$/.test (e.src) &amp;&amp; e.parentNode.getElementsByTagName ('a')[0].firstChild.data == 'Cheaterhossie') e.src = 'other.png'}
})()
Copy linkTweet thisAlerts:
@HossieauthorMay 29.2005 — Yeah I can't edit the page, it's not mine.

Here is the rest of the source:

&lt;b&gt;&lt;a href='javascript:void(0);' onClick='openProfile("58350","here_is_the_current_random_sessionid")' class='onblue'&gt;Cheaterhossie&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;
&lt;img src='./avatare/leet.gif' alt='Leet' border=0 /&gt;


This is embedded in a td...
Copy linkTweet thisAlerts:
@CharlesMay 29.2005 — That's still not quite enough, but you should be able to use or adapt what I've posted above.
Copy linkTweet thisAlerts:
@HossieauthorMay 29.2005 — &lt;table border=0 cellpadding=3 cellspacing=0 width='100%' height='100%'&gt;
&lt;tr&gt;&lt;td align='left' vAlign='top'&gt;
&lt;a name='reply_ID_goes_here'&gt;&lt;/a&gt;&lt;font color='#EFEFEF'&gt;
&lt;b&gt;&lt;a href='javascript:void(0);' onClick='openProfile("58350","_randon_session_id_here")' class='onblue'&gt;Cheaterhossie&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;
&lt;img src='./avatare/leet.gif' alt='Leet' border=0 /&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


I hope thats enough of the code ?
Copy linkTweet thisAlerts:
@CharlesMay 29.2005 — Give a try to my example above.
Copy linkTweet thisAlerts:
@HossieauthorMay 29.2005 — It really worked. Thank you SO MUCH for your help! ?
×

Success!

Help @Hossie 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.18,
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,
)...