// ==UserScript== // @name 强制缩放与桌面模式 // @author 酷安@耗子Sky // @description 竖屏时浏览器ua为手机ua时启用强制缩放,浏览器ua非手机ua时启用桌面模式,横屏时默认桌面模式 // @match *://*/* // @grant none // @version 4.0 // @run-at document-end // @author - // @namespace https://greasyfork.org/users/452911 // @downloadURL none // ==/UserScript== (()=>{ const 竖屏 = 0.4, 横屏 = 0.7, 强制缩放 = 1.0, 网页宽度 = 700, meta = document.querySelector('meta[name=viewport]'), ori = screen.orientation.type, ua = navigator.userAgent; function changeScale(x) { meta.setAttribute( 'content', `width=device-width,initial-scale=${x},maximum-scale=10.0,user-scalable=1`); }; function autoChangeScale() { if (ori.indexOf('landscape')==0) { changeScale(横屏); } else { if (ua.indexOf('Mobile')<0) { changeScale(竖屏); } else if (window.innerWidth<网页宽度) { changeScale(强制缩放); } } } // 刚打开 autoChangeScale(); // 用户改变 screen.orientation.onchange = autoChangeScale; })();