greasemonkey - On-the-fly modifications of the links according to a set of rules (Greasekit / Javascript) -
i have html page loads of entries this:
<a href="https://www.example.co.uk/gp/wine/product?ie=utf8&asin=123456789&tab=uk_default" class="prmrybtnmed"
i want replace links instead are:
https://www.example.co.uk/gp/wine/order?ie=utf8&asin=1233456789
so, it's quite complicated search , replace. these instructions human:
- look @ url. make note of number after 'asin='. (forget before , after that)
- then, form new url, using asin. start this:
https://www.example.co.uk/gp/wine/order?ie=utf8&asin=
with number stuck on end form:
https://www.example.co.uk/gp/wine/order?ie=utf8&asin=123456789
kindly note
- rather modifying existing buttons, acceptable add new button [or link] near original buttons
- both original , new links point same domain
- i'm using greasekit on ssb called fluidapp, can switch greasemonkey on firefox.
i've watched 40 javascript tutorial videos - man language hard! seems extremely difficult. hugely appreciate help/pointers.
something might work:
// new base url var base = ' https://www.example.co.uk/gp/wine/order?ie=utf8&asin='; // links classname 'prmrybtnmed' var links = document.getelementsbytagname('a'); for(var = 0;i < links.length;i++){ // check each link 'asin' value var result = /asin=([\d\w]+)/.exec(links[i].getattribute('href')); if(result){ // make new url using 'base' , 'asin' value links[i].setattribute('href', base+result[1]); } }
Comments
Post a Comment