Welcome to MTurk Crowd

Work on Amazon Mechanical Turk, learn from the best, and have fun doing it. Join the crowd today!

Sign Up

script that turns text into a searchable link

Discussion in 'Userscripts, Extensions, and Software' started by Type2Work, Dec 26, 2017.

  1. Type2Work

    Type2Work
    Expand Collapse
    Active Member

    • Contributor
    Joined:
    Jan 19, 2016
    Messages:
    734
    Likes:
    1,003
    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?
     
  2. turkenator

    turkenator
    Expand Collapse
    ━╤デ╦︻(▀̿̿Ĺ̯̿̿▀̿ ̿)

    • Contributor
    Joined:
    Feb 5, 2016
    Messages:
    102
    Likes:
    175
    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>');