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&amp;asin=123456789&amp;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:

  1. look @ url. make note of number after 'asin='. (forget before , after that)
  2. 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]);     } } 

demo: http://jsfiddle.net/louisbros/l8epl/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -