My userscript is designed to modify the href of specific links on an IP-direct Google search page:
// ==UserScript==
// @name _Modify select Google search links
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @include http://62.0.54.118/*
// ==/UserScript==
var qLinks = document.querySelectorAll ("a[href*='?q=']");
for (var J = qLinks.length - 1; J >= 0; --J) {
var oldHref = qLinks[J].getAttribute ('href');
var newHref = oldHref.replace (/\?q=/, "?&q=");
//console.log (oldHref + "\n" + newHref);
qLinks[J].setAttribute ('href', newHref);
}
Although it functions properly on the initial page, when navigating through pagination links, the script ceases to work due to AJAX loading subsequent pages.
@Brock Adams suggested using waitForKeyElements()
, but I struggled to implement it.
I have come across discussions like stackoverflow.com/questions/10888326/executing-javascript-script-after-ajax-loaded-a-page-doesnt-work, but integrating them has been challenging.
Is there a way to adapt this script to modify links on an AJAX page such as:
http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0#filter=0&q=42&start=10