If so, it should find ‘url=’ from this address and take everything after it: http://blocked.com-default.ws/?oI=10932090785&type=chromium-m&url=example.com
Then, it url decodes it(in this example it would be decoding ‘example.com’), like this: https://www.url-encode-decode.com/
Next, it Base64 encodes it, like this: https://www.base64encode.org/
Then, it adds that string to the end of this url and redirects you: http://openweb.gdn/index.php?q=
If not, it should take the whole url/address.
Then, it should Base64 encode it, like this: https://www.base64encode.org/
Then, it adds that string to the end of this url and redirects you: http://openweb.gdn/index.php?q=
Requirements:
Must function as a bookmarklet
Must work on Chrome
Ah okay. Well you can get specific search values by creating an URLSearchParams object; this is certainly cleaner than using your own regular expression or something, and it works in chrome:
const params = new URLSearchParams(window.location.search)
// Get the url value, otherwise take the complete current location
const url = params.get('url') || window.location.href
You can then convert that url to base 64 with btoa() and do the redirect:
Okay, I understand that part now. Could you explain what the top section does?
const params = new URLSearchParams(window.location.search)
// Get the url value, otherwise take the complete current location
const url = params.get('url') || window.location.href
Did you follow the link I gave you? It creates an URLSearchParams object from the query string part of the current location… then from that object it gets the url value, or if this value does not exist, it takes the full location instead.
Okay, I made a fiddle to lay this out. https://jsfiddle.net/samgurdus/koyb3eeb/ The part I don’t understand, is how it finds everything after url= EDIT: Also, where does it do the url decode?
// Creates an URLSearchParams object from the query string part of the current location
const params = new URLSearchParams(window.location.search)
// Get the part after url=
const urlValue = params.get('url')
// If there is a match, decode it; otherwise just take the current location
const url = urlValue ? decodeURIComponent(urlValue) : window.location.href
// Redirect to openweb.gdn and append the Base64-encoded URL
window.location.href = 'http://openweb.gdn/index.php?q=' + btoa(url)
I want to modify this script a little, but am not sure the best way. I want to get the url param, and if there is one, add http in front of it, and if there isn’t then just take the whole address, before redirecting. I like the solution to just use the | | instead of a full ‘if else,’ so I was wondering how I could adapt it.
I want it to check if there is a url param in the window location, and if so, add http:// to the beginning and set it as a variable, address. If not, it should just take the whole location and set it as a variable, address.