所以我知道可以通過將 JavaScript 存盤在瀏覽器的書簽(又名書簽)中來運行 JavaScript,但我不確定是否可以使用書簽來自動編輯當前 URL(然后將您帶到新的 URL) .
我正在嘗試做的事情:
在 URL 中,替換字串之前(包括)的所有內容
/image/thumb/
和
https://a1.mzstatic.com/us/r1000/0/
并洗掉(包括)最后一個之后的所有內容
/
例如,以下 URL:
https://is2-ssl.mzstatic.com/image/thumb/Music/v4/4e/61/09/4e610911-7e0e-d348-8246-11ef6ffe00ab/886443607118.jpg/540x540bb.webp
應該成為(并重定向到)
https://a1.mzstatic.com/us/r1000/0/Music/v4/4e/61/09/4e610911-7e0e-d348-8246-11ef6ffe00ab/886443607118.jpg
用JavaScript點擊書簽后。
更多示例:
https://is2-ssl.mzstatic.com/image/thumb/Features122/v4/b0/26/80/b0268001-9527-3477-1df2-c68f02271a9f/ffe8be4a-2798-4a68-b691-9a91edb1c177.png/216x216sr.webp
應該成為(并重定向到)
https://a1.mzstatic.com/us/r1000/0/Features122/v4/b0/26/80/b0268001-9527-3477-1df2-c68f02271a9f/ffe8be4a-2798-4a68-b691-9a91edb1c177.png
https://is4-ssl.mzstatic.com/image/thumb/Video124/v4/ac/c2/b0/acc2b0a3-8105-2f22-2b0d-ea274223e959/Jobe81235fa-44f7-43f8-a7d6-421093c13e0b-110141253-PreviewImage_preview_image_nonvideo_sdr-Time1616098999993.png/300x300.jpg
應該成為(并重定向到)
https://a1.mzstatic.com/us/r1000/0/Video124/v4/ac/c2/b0/acc2b0a3-8105-2f22-2b0d-ea274223e959/Jobe81235fa-44f7-43f8-a7d6-421093c13e0b-110141253-PreviewImage_preview_image_nonvideo_sdr-Time1616098999993.png
uj5u.com熱心網友回復:
用于String.prototype.match(regExp)獲取您想要的 url 部分,然后將 url 部分與您的 url 前綴結合起來。
function replaceUrl(url) {
const prefix = 'https://a1.mzstatic.com/us/r1000/0';
const lastPart = url.split("/image/thumb/")[1];
const match = lastPart ? lastPart.slice(0, lastPart.lastIndexOf("/")) : null;
const targetUrl = match ? `${prefix}/${match}` : url;
return targetUrl;
}
const targetUrl = replaceUrl('https://is2-ssl.mzstatic.com/image/thumb/Music/v4/4e/61/09/4e610911-7e0e-d348-8246-11ef6ffe00ab/886443607118.jpg/540x540bb.webp');
添加一個書簽,書簽的腳本是這樣的:
javascript:(function(){
function replaceUrl(url) {
const prefix = 'https://a1.mzstatic.com/us/r1000/0';
const lastPart = url.split("/image/thumb/")[1];
const match = lastPart ? lastPart.slice(0, lastPart.lastIndexOf("/")) : null;
const targetUrl = match ? `${prefix}/${match}` : url;
return targetUrl;
}
const targetUrl = replaceUrl(location.href);
window.open(targetUrl,"_blank");
})()
這location.href是當前選項卡的 url,您可以將其更改為您需要的任何內容(可能是當前頁面鏈接的 url 等)。的第二個引數window.open()可以是_blank(在新選項卡中_self打開)或(在當前選項卡中打開)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/483952.html
標籤:javascript 网络 网址 浏览器 小书签
上一篇:等待幾分鐘以檢查URL是否回應
下一篇:將帶有斜杠的變數傳遞給nginx
