寻找一种方法使用油脂/tampermonkey来替换页面上的部分网址

问题描述

所以我经常访问一个使用 ouo.io 的网页,试图通过链接赚取一些广告费。幸运的是,该特定的重定向器服务不会以任何方式更改或隐藏原始 url,所以我想也许有可能(我猜是使用篡改/greasemonkey 脚本)自动从 url 中删除 ouo 部分>

网址是这样的 https://ouo.io/qs/pRqHNWPK?s=https://destination.url/ (协议和 ouo 部分之间的空格是故意的,因为没有它,这个链接会触发 URL-shortener 警告,因此不允许我发帖)

任何人都有可以适应这种情况的篡改脚本?我试着自己乱七八糟写一些东西,但没有奏效(或者根本不做任何事情lmao)。

解决方法

这是一个示例代码,向您展示如何完成...
(去掉ouo前的多余空格)

基于新页面的 location.href 重定向

// ==UserScript==
// @name          Remove Redirect
// @match         https:// ouo.io/qs/*
// @grant         none
// @version       1.0
// run-at         document-start
// ==/UserScript==


const redirect = location.search.match(/http.+/);  // find redirect URL
if (redirect) {
  window.stop();                                   // stop loading the page
  location.href = decodeURIComponent(redirect[0]);
}

您还可以更改页面上的链接。由于它必须在每个页面上运行,因此它占用的资源要多得多,因此不推荐。这是一个例子......

// ==UserScript==
// @name          Remove Redirect Link
// @match         *://*/*
// @grant         none
// @version       1.0
// ==/UserScript==

document.querySelectorAll('a[href^="https:// ouo.io/qs/"]').forEach(item => {
  const redirect = item.search.match(/http.+/);   // find redirect URL
  if (redirect) {
   item.href = decodeURIComponent(redirect[0]);
  }
}):