// ==UserScript== // @name 【通用-跳转】跳转电脑版 // @namespace http://tampermonkey.net/ // @version 1.2 // @description 用于一些网站自动跳转电脑版 // @author You // @match *://finance.sina.cn/* // @match *://k.sina.cn/* // @match *://news.sina.cn/* // @match *://*.sina.cn/* // @match *://m.pipaw.com/* // @match *://m.kalvin.cn/* // @match *://wap.gamersky.com/* // @match *://3g.ali213.net/* // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org // @grant none // @run-at document-start // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... let url = window.location.href; let domain = document.domain; let pcUrl = ""; function getPcUrl() { //新浪 //https://news.sina.cn/2023-08-21/detail-imzhycna5519710.d.html //https://news.sina.com.cn/gov/xlxw/2023-08-21/doc-imzhycna5519710.shtml ///["']?__webURL["']?:["']?(.*?)["']?/ if (domain.includes('sina.cn')) { console.log('[跳转电脑版] 新浪'); let webURL = ""; let scripts = document.getElementsByTagName('script'); for (let i = 0; i < scripts.length; i++) { let script = scripts[i]; let scriptText = script.innerHTML; console.log('scriptText的内容为:' + scriptText); // 判断是否包含__webURL if (scriptText && scriptText.includes('__webURL')) { // 提取__webURL的内容 /* let start = scriptText.indexOf('"__webURL":"') + 12; let end = scriptText.indexOf('","', start); webURL = scriptText.substring(start, end); */ //"__webURL":"https:\/\/news.sina.com.cn\/gov\/xlxw\/2023-08-21\/doc-imzhycna5519710.shtml", webURL = /["']?__webURL["']?\s*:\s*(.*?),/.exec(scriptText); console.log('__webURL的内容为:' + webURL[1]); break;//跳出循环 } else { console.log('无__webURL'); } } pcUrl = webURL[1] .replace(/\\/g, "") .replace(/\"/g, "") .replace(/\'/g, ""); } //琵琶网 //http://m.pipaw.com/xin/520410.html //http://www.pipaw.com/xin/520410.html else if (domain.includes('m.pipaw.com')) { console.log('[跳转电脑版] 琵琶网'); pcUrl = url .replace("m.pipaw.com","www.pipaw.com"); } //咖绿茵手游站 //https://m.kalvin.cn/gl/45240.html //https://www.kalvin.cn/gl/45240.html else if (domain.includes('m.kalvin.cn')) { console.log('[跳转电脑版] 咖绿茵手游站'); let urlA = window.location.href; pcUrl = urlA .replace('m.kalvin.cn','www.kalvin.cn'); } //游民星空 //https://wap.gamersky.com/news/Content-1635505.html //https://www.gamersky.com/news/202308/1635505.shtml else if (domain.includes('wap.gamersky.com')) { console.log('[跳转电脑版] 游民星空'); // 根据rel="canonical"查找link元素 var canonicalLinkYMXK = document.querySelector('head link[rel="canonical"]'); // 获取href属性的值 var hrefContentYMXK = canonicalLinkYMXK.getAttribute('href'); pcUrl = hrefContentYXW; } //游侠网 //https://3g.ali213.net/zt/affogato/news/ //https://www.ali213.net/zt/affogato/news/ else if (domain.includes('3g.ali213.net')) { console.log('[跳转电脑版] 游侠网'); // 根据rel="canonical"查找link元素 var canonicalLinkYXW = document.querySelector('head link[rel="canonical"]'); // 获取href属性的值 var hrefContentYXW = canonicalLinkYXW.getAttribute('href'); pcUrl = hrefContentYXW; } } console.log('[跳转电脑版] url:'+url); console.log('[跳转电脑版] pcUrl:'+pcUrl); function goPcUrl() { if (url !== pcUrl && pcUrl !== "") { window.location.replace(pcUrl); } else if (url !== pcUrl && pcUrl === ""){ getPcUrl(); } else if (pcUrl === ""){ console.log('[跳转电脑版] 获取pcUrl失败'); } } setInterval(goPcUrl, 1000); })();