Greasy Fork is available in English.
Modify all V2EX links to use global.v2ex.co
由于当前V2EX改版,需要注册后才能浏览帖子,而注册必须要在闲鱼花十块钱买号老号一金币邀请才能注册,因此,FUXX V2EX || V2EX REDIRECT 旨在为无号/喜欢匿名的小伙伴提供免登录浏览帖子的功能,通过将网页上所有包含 *.v2ex.com
或 v2ex.com
的链接重定向到global.v2ex.co
,以此实现匿名看帖/使用sov2ex搜索帖子而不是google
*.v2ex.com
和 v2ex.com
链接。创建一个新脚本,并将以下代码粘贴到编辑器中:
// ==UserScript==// @name V2EX Link Modifier// @namespace http://tampermonkey.net/// @version 0.2// @description Modify all V2EX links to use global.v2ex.co// @author Your Name// @match *://*/*// @grant none// @run-at document-end// ==/UserScript==(function() {'use strict';const DEBUG_MODE = true;// 检查并修改链接function modifyLinks() {// 获取所有链接let links = document.querySelectorAll('a[href*="v2ex.com"]');// 遍历所有链接links.forEach(function(link) {// 如果链接包含 .v2ex.com 或 v2ex.com,则替换为 global.v2ex.coif (/v2ex\.com/.test(link.href)) {let newHref = link.href.replace(/:\/\/(.*\.)?v2ex\.com/, '://global.v2ex.co');if (DEBUG_MODE) {console.log(`Modifying link: ${link.href} to ${newHref}`);}link.href = newHref;}});}// 初始修改modifyLinks();// 监听DOM变化,动态修改新增的链接let observer = new MutationObserver(function(mutations) {mutations.forEach(function(mutation) {if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {modifyLinks();}});});observer.observe(document.body, { childList: true, subtree: true });})();
保存并启用脚本。
脚本会在页面加载时自动运行,并修改所有符合条件的链接。你可以通过浏览器的开发者工具控制台查看调试信息(如果调试模式已开启)。
假设页面上有以下链接:
https://www.v2ex.com/t/123456
http://subdomain.v2ex.com/member/username
https://another.subdomain.v2ex.com/following
https://v2ex.com/t/855539
在运行脚本后,这些链接将被修改为:
https://global.v2ex.co/t/123456
http://global.v2ex.co/member/username
https://global.v2ex.co/following
https://global.v2ex.co/t/855539
你可以通过设置 DEBUG_MODE
变量来启用或禁用调试模式。当调试模式开启时,脚本会在控制台输出每个被修改的链接信息:
const DEBUG_MODE = true;
欢迎对该脚本进行改进和扩展。如有建议或问题,请通过 GitHub 提交 issue 或 pull request。
此脚本遵循 MIT 许可证。详情请参阅 LICENSE 文件。
部分代码参考自[开源替代重定向器]{https://greasyfork.org/zh-CN/scripts/437291-open-source-alternative-redirector}