I'm trying to use a jquery userscript on chrome in tampermonkey on a pc. I found a script on here and tried to modify it to linkify the contents of a table. I think the reason it's not working is because I need to specify that inputText is the link on the webpage. The link is always the 2nd child of the same table. The table doesn't have an id or class so I think I have to get to t the parent/child way. How can I specify that is what I want to be linkified? It is the restaurant name on each webpage, always in the same place on the webpage, and it's supposed to search google for that. https://www.mturk.com/mturk/return?groupId=35DNGIKWRF46YCSNYBRS2YNM4DY173&requesterId=&hitId=39O5D9O87TSA1G1HKT8DKE5ZXMMC3H&externalHit=true&canAccept=
//var $inputText= $(t).children('td').eq(1);
function linkify(inputText) {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
return replacedText;
}
Thank you very much but I can't get the right object. The table doesn't have an id or class. It is the first table in a section that has an id. Here are two of the things I have tried with the answerer's code below. var $element = $('#Other').find('t').eq(1).find('tr').eq(1).find('td').eq(1); var $element = $('#Other').find('tr').eq(1).find('td').eq(1);
It's still not working with the 2nd answer below. Could someone please go the link and look at it? I can't post code now here for some reason.