Jason
Jason

Reputation: 3

Chrome Extension Help: Replace URL string on page load

I have this problem. Specific website, I have visited literally thousands of pages in it. I have enabled css visited links highlighting so I don't waste my time going back to pages I have already seen then ... the website changes its url structure

it used to be: http://www.blah.com/example.phtml?blah&bleh&hit=10&fromsearch now it became http://www.blah.com/example.phtml?blah&bleh&hit=10&fromsearch&hit_id=10

which messes up visited pages.

Now the Visited Pages file chrome uses is encrypted so I can't inject "hit_id=10" into all my browsing history and be done with so I am wondering if I can do the reverse with an extension. Ie strip all instances of "hit_id=10" from all the links as the page is rendered. I can figure out the js

< script type="text/javascript" >
document.body.innerHTML = document.body.innerHTML.replace(new RegExp("&hit_id=10", "g"), "");
< /script >

What I can't figure out is how to get to execute (if it can) on all pages it loads from a specific domain

PS yes &hit_id=10 is completely redundant as a field

Any/all help appreciated

Upvotes: 0

Views: 2100

Answers (1)

serg
serg

Reputation: 111325

This would remove it from the links only:

content_script.js:

var el = document.getElementsByTagName("a");
for(var i=0;i<el.length;i++){
    el[i].href = el[i].href.replace("&hit_id=10", "");
}

manifest.json:

{
  ...
  "content_scripts": [
    {
      "matches": ["http://www.blah.com/*"],
      "js": ["content_script.js"]
    }
  ],
  ...
}

Upvotes: 4

Related Questions