Go Back   Steam Users' Forums > Steam Discussions > Off Topic

Reply
 
Thread Tools Display Modes
Old 04-29-2011, 09:02 AM   #1
Kailieann
 
 
 
Join Date: Sep 2008
Reputation: 875
Posts: 6,351
JavaScript help

I'm trying to make a simple GreaseMonkey UserScript -- so simple, in fact, that I had wanted to make it as a Stylish UserStyle instead, but alas, the way the page in question is designed prohibits this approach.

At any rate, I only recently started teaching myself JavaScript -- then realized that most of my knowledge of HTML is over a decade old and decided I should brush up on that first.
I haven't quite gotten back to the actual JavaScript part of my studies yet, and basically all I know is document.write(""); and document.getElementById("").innerHTML="";, so I would appreciate it if anyone could help with the following.

Basically, what I need to do is search a page for ALL instances of a specific element with a specific attribute (eg: <div class="example">), which contains a specific string (eg: <a href="http://www.google.com/">), and then change the original element to have a different attribute (eg: <div class="example2">).

Shouldn't be too hard, I think. If I could use PHP it would just be a single preg_replace();.
Kailieann is offline  
Reply With Quote
Old 04-29-2011, 10:39 AM   #2
bessent
 
Join Date: Apr 2008
Reputation: 398
Posts: 671
Do you mean this:

Code:
var n = searchString.indexOf(stringToSearchFor);
if (n >= 0) {
    searchString = searchString.substring(0, n) + replacementString + searchString.substring(n + stringToSearchFor.length);
}

Last edited by bessent: 04-29-2011 at 10:54 AM.
bessent is offline   Reply With Quote
Old 04-29-2011, 10:54 AM   #3
Pebr
 
 
 
Join Date: Feb 2009
Reputation: 4261
Posts: 2,934
Yep, google tutorials and help for indexOf() - That will help you do what you need.
Pebr is offline   Reply With Quote
Reply

Go Back   Steam Users' Forums > Steam Discussions > Off Topic


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -7. The time now is 01:56 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2012, All Rights Reserved.