您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
浏览器ua为手机ua时启用强制缩放,浏览器ua非手机ua时启用桌面模式,脚本菜单可以单独设置桌面模式宽度
当前为
// ==UserScript== // @name 强制缩放与桌面模式 // @author Lemon399 // @description 浏览器ua为手机ua时启用强制缩放,浏览器ua非手机ua时启用桌面模式,脚本菜单可以单独设置桌面模式宽度 // @match *://*/* // @exclude https://sj.qq.com/* // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @version 8.6 // @run-at document-end // @namespace http://greasyfork.icu/users/452911 // ==/UserScript== const domain = window.location.hostname; let viewportWidth = GM_getValue(`viewportWidth_${domain}`, 1080); let userAgent = navigator.userAgent; function setViewportWidth(width) { viewportWidth = width; GM_setValue(`viewportWidth_${domain}`, width); // 将视口宽度与域名关联存储 autoChangeScale(); // 更新视口宽度后自动调整缩放比例 } function autoChangeScale() { const metaTag = document.querySelector('meta[name=viewport]'); if (metaTag) { const isMobile = userAgent.indexOf('Mobile') < 0 && userAgent.indexOf('SymbianOS') < 0 && userAgent.indexOf('SearchCraft') < 0; metaTag.setAttribute('content', isMobile ? `width=${viewportWidth}` : 'width=device-width,initial-scale=1.0,maximum-scale=10.0,user-scalable=1'); } } autoChangeScale(); //监听url变化执行 history.pushState = ( f => function pushState(){ var ret = f.apply(this, arguments); window.dispatchEvent(new Event('pushstate')); window.dispatchEvent(new Event('urlchange')); return ret; })(history.pushState); history.replaceState = ( f => function replaceState(){ var ret = f.apply(this, arguments); window.dispatchEvent(new Event('replacestate')); window.dispatchEvent(new Event('urlchange')); return ret; })(history.replaceState); window.addEventListener('popstate',()=>{ window.dispatchEvent(new Event('urlchange')) }); window.addEventListener('urlchange', function(event) { window.setTimeout(autoChangeScale, 250); }); //延时执行 window.setTimeout(autoChangeScale, 250); document.addEventListener('touchmove', function(e) { if (e.touches.length > 1) { autoChangeScale(); } }); // 添加菜单命令 GM_registerMenuCommand('设置视口宽度', function() { const inputWidth = prompt('请输入视口宽度:', viewportWidth); if (inputWidth) { const parsedWidth = parseInt(inputWidth, 10); if (!isNaN(parsedWidth)) { setViewportWidth(parsedWidth); } else { alert('输入的宽度无效,请输入一个有效的数字!'); } } });