Home > Mobile >  Convert url in address bar to localhost in Chrome
Convert url in address bar to localhost in Chrome

Time:04-25

i need to create a marker in my web browser, to be faster in my job. I need to convert some url like: https://www.myTest.com/section/the-new-section/ to localhost/pf/section/the-new-section/ Maybe then i will need to add something after the address like ?_website=mypageSite, or something. but is secondary. The thing is the first part.

I try to use this code like model to make main, but i can not achieve any result:

javascript:u=u=window.location.href.replace(/^https?:\/\/[^\/] /, '').replace(/(\?|#).*$/, '');d=window.location.href.match(/^(?:https?:\/\/)?(?:[^@\n] @)?(?:www\.)?([^:\/\n?] )/)[1];a='https://' d '/pf/api/v3/content/fetch/content-api-v4?query={"website_url":"' u '"}';x=new XMLHttpRequest();x.open('GET',a,false);x.send(null);o=JSON.parse(x.responseText);if(o && o._id){window.location.href = 'https://diarioas.arcpublishing.com/composer/edit/' o._id '/';}else{'Story URL not found';}

i need similar to do that i comment before. Some help for me. Thanks

CodePudding user response:

Just use the URL API.

const str = 'https://www.mytest.com/section/the-new-section/';

const url = new URL(str);

console.log(`localhost/pf${url.pathname}`);

CodePudding user response:

There are two cases for this question,
First is when you are at that pagehttps://www.mytest.com/section/the-new-section/ then you then you can just use window.location.pathname to get the parameters and to get stuff like ?search=stackoverflow you can use window.location.search

console.log( "http://localhost" window.location.pathname window.location.search)

Second Interpretation is that you need a custom function to do this for a set of url's you provide... This is also similar to the above approach.

var url = "https://www.mytest.com/section/the-new-section/?search=stackoverflow"
var urlt = new URL(url)
console.log("http://localhost"   urlt.pathname   urlt.search)

  • Related