|
本帖最后由 Kaicneg 于 2025-2-18 07:30 编辑
大家都知道现在用手机登入页面会变成空白,虽然用Chrome可以勾选桌面版网站,但我因为要用Tampermonkey而转用了Firefox,可惜手机版Firefox就算转网页版隔一阵子就自动跳回来,每次手动真的很麻烦。
所以用ai写了这个代码,暂时用了没甚麽问题(  ̄▽ ̄)σ
这个是只针对Gamemale,所以其他网页应该不受影响
更新一下发现有bug,所以直接强硬每个网址加上mobile=no

// ==UserScript==
// @Name 自动切换桌面版
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 智能处理所有页面强制桌面版
// @author Kaicneg
// @match https://www.gamemale.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 设备检测白名单
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(navigator.userAgent);
if (!isMobile) return;
// 智能URL处理
const enforceDesktop = () => {
const url = new URL(window.location.href);
let modified = false;
// 处理没有查询参数的URL(如 /thread-xxx-1-1.html)
if (!url.search) {
url.search = '?mobile=no';
modified = true;
}
// 处理已有参数但没有mobile的情况
else if (!url.searchParams.has('mobile')) {
url.searchParams.append('mobile', 'no');
modified = true;
}
// 替换现有移动端参数
else if (url.searchParams.get('mobile') !== 'no') {
url.searchParams.set('mobile', 'no');
modified = true;
}
// 避免锚点丢失
if (modified) {
const newUrl = url.toString().replace(/#.*$/, '') + (url.hash || '');
if (newUrl !== window.location.href) {
window.location.replace(newUrl);
return true;
}
}
return false;
};
// 初始执行
if (!enforceDesktop()) {
// 监听动态加载(适用于SPA)
new MutationObserver((mutations) => {
if (!window.location.href.includes('mobile=no')) {
enforceDesktop();
}
}).observe(document.body, {
childList: true,
subtree: true
});
}
// 额外清除移动端cookie
document.cookie = "mobile=no; path=/; domain=.gamemale.com; max-age=" + 60*60*24*30;
document.cookie = "mobiletype=0; path=/; domain=.gamemale.com; max-age=" + 60*60*24*30;
})();

感觉不错可以追随一下(๑•̀ᄇ•́)و
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|