简体   繁体   中英

Tampermonkey script to replace parts of an link

For example i have a link

https://somefilehostsite.com/file/asodhaisdbaisyd7 and i want a script to redirect it to https://somefilehostsite.com/FilePage2/asodhaisdbaisyd7

This is the script i tried but didn't work.

 // ==UserScript== // @name DLUpload Skip // @namespace http://tampermonkey.net/ // @version 0.1 // @description Skip Pages // @author Angelo Heide // @match https://onlinenepal.net/file/* // @exclude https://onlinenepal.net/FilePage2/* // @run-at document-start // ==/UserScript== location.replace = ("onlinenepal.net/FilePage2/*");

Just a if statement If current url is equal to https://somefilehostsite.com/file/* redirect to https://somefilehostsite.com/FilePage2/asodhaisdbaisyd7

var reg = new RegExp('https://somefilehostsite.com/file/(.*)')
if (reg.test(document.URL))
{
   window.location.replace = 'https://somefilehostsite.com/FilePage2/asodhaisdbaisyd7';
}

Link to regex https://regexr.com/5gqtt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM