0

I need to add a bookmarklet or something in Chrome browser to replace the protocol of a site to a local file.

Example URL:

https://st-test.com/folder/file.html

Becomes after clicking on the Javascript bookmarklet and it auto-reloads the page to:

file:///E:/st-test.com/folder/file.html

So it replaces "https://" with "file:///E:/" in the url and reload the page automatically.

I have found some suggestions here and there, using history.pushState or tampermonkey, but it seems they just can change the text of the url after the '/' but not the protocol.

Mike
  • 2,051
  • 4
  • 28
  • 46
  • I don't think this is feasible for security reasons, see https://stackoverflow.com/a/14052517/1418049 – Maluen Nov 19 '17 at 09:58
  • @Maluen Thanks for the reply. I already got the local files opening normally in Chrome, I just want the option for the bookmarklet to replace th protocol in the url, and then the page would load normally from my computer. – Mike Nov 19 '17 at 11:36

1 Answers1

0

Sorry if it might seem trivial, and if you tried this already then I probably didn't understand your problem. I tried: setTimeout(function(){ window.location.href = window.location.href.replace('https', 'file') }, 2500) And it worked fine. Hope it helps

DSCH
  • 2,146
  • 1
  • 18
  • 29
  • Thanks for the reply. I tried this but it didn't work: javascript:setTimeout(function(){window.location.href = window.location.href.replace('https', 'file')}, 2500); ---- am I adding it wrong? – Mike Nov 19 '17 at 09:02
  • Hi Try adding this, and click on the H1, it works for me. If it is still not working for you maybe you can add a code snippet please? – DSCH Nov 19 '17 at 09:11
  • I think you are getting me wrong.. I want to add that to the bookmarks bar (as a bookmark), so when I open the https page and then click on that bookmarks, it replaces the "https://" with "file:///E:/" – Mike Nov 19 '17 at 09:18
  • Just to make sure I get you right this time - Do you want the bookmarked url to be saved with 'file' instead of 'https'? – DSCH Nov 19 '17 at 09:24
  • Let us say I opened a site called "https://anysite.com", what I need is to click in a bookmark in the Chrome bookmarks bar, so it reloads the page with the following url: "file:///E:/anysite.com" – Mike Nov 19 '17 at 09:27