[英]I want to change .jpg or .png to .jpg:orig or .png:orig with greasemonkey
我想用油滑猴ex將.jpg或.png更改為.jpg:orig或.png:orig。 https://pbs.twimg.com/media/DMU-nlSV4AAom3a.jpg到https://pbs.twimg.com/media/DMU-nlSV4AAom3a.jpg:orig
// ==UserScript==
// @name Twitter Orig jpg
// @namespace jirat
// @include https://pbs.twimg.com/*
// @include https://pbs.twimg.com/media/*
// @version 1
// @grant none
// ==/UserScript==
document.location.replace(document.location.href.replace(/.jpg/,'.jpg:orig'));
但是當它運行時,它不會停止。 像這樣不斷補充
[.jpg:orig:orig:orig:orig]
我怎樣才能解決這個問題。
檢查:orig
已經存在
let href = document.location.href;
if(href.includes('.jpg') && !href.includes(':orig')){
document.location.href = href.replace(/.jpg/,'.jpg:orig');
}
使用/\\.jpg$/
作為正則表達式,使其僅在URL末尾匹配。
設置.jpg或.png的位置網址
function setLocationUrl(){
let href = document.location.href;
if(href.lastIndexOf(':orig') == -1 && (href.lastIndexOf('.jpg') || href.lastIndexOf('.png'))){
let location = href.replace(/.jpg/,'.jpg:orig');
document.location = location;
}
}
setLocationUrl();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.