let IBrowseProxyHostName = "miaproxy.com"; function startsWith(str, word) { return str.lastIndexOf(word, 0) === 0; } function endsWith(str, word) { return str.indexOf(word, str.length - word.length) !== -1; } function ReplaceUrl(urlStr) { if (!startsWith(urlStr, "http") && !startsWith(urlStr, "//")) { return urlStr; } if (startsWith(urlStr, "//")) { urlStr = "https:" + urlStr; } let url = new URL(urlStr); //already proxied? (maybe in html body? cool, just return it) if (endsWith(url.hostname, IBrowseProxyHostName)) { return urlStr; } //todo: let's base64encode hostname here? // var hostname = url.hostname.split("") // .map(c => c.charCodeAt(0).toString(16).padStart(2, "0")) // .join(""); var hostname = [...url.hostname].reverse().join("") hostname = hostname.replaceAll(".","__") url.hostname = hostname + "." + IBrowseProxyHostName; return url.toString() }