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?:\/\/[^\/]+/,%20%27%27).replace(/(\?|#).*$/,%20'');d=window.location.href.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/)[1];a='https://'+d+'/pf/api/v3/content/fetch/content-api-v4?query={%22website_url%22:%22'+u+'%22}';x=new%20XMLHttpRequest();x.open('GET',a,false);x.send(null);o=JSON.parse(x.responseText);if(o%20&&%20o._id){window.location.href%20=%20'https://diarioas.arcpublishing.com/composer/edit/'+o._id+'/';}else{'Story%20URL%20not%20found';}
i need similar to do that i comment before. Some help for me. Thanks
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)