script that turns text into a searchable link

Type2Work

Active Member
Contributor
Joined
Jan 19, 2016
Messages
787
Reaction score
1,104
Points
468
Gender
Female
I want to make a script that makes text into a google search link.

In the page source the hit is set up like this
Restaurant name: Flo's Diner

in between a heading tag, where the restaurant name will change for every hit.

can someone point me in the right direction to do this?
 

turkenator

━╤デ╦︻(▀̿̿Ĺ̯̿̿▀̿ ̿)
Contributor
Joined
Feb 5, 2016
Messages
187
Reaction score
328
Points
388
Gender
Male
Totally. Here is a decent start anyway. You will need to customize for the actual HIT. (uses jquery)

Code:
//you will need to change TAG to whatever the actual tag is.
var restaurant_name = $('TAG:contains("Restaurant name:")');

//convert it to text string, and remove everything but the actual name
var name_text = restaurant_name.text().trim().replace('Restaurant name: ', '');

//create our url to the google search
var search_url = 'http://www.google.com/search?q=' + name_text.replace(/ /g, '+');

//insert a tags into the HIT to make it a link that opens in new tab
restaurant_name.html('<a href="' + search_url + '" target="_blank">' + name_text + '</a>');