
把麻将、斗地主牌桌铺满浏览器视口,地址栏和标签页都保留,不进入原生全屏。页面上的全屏按钮改为网页内全屏切换,快捷键 Alt + F 同样可用,进入页面默认全屏,隐藏滚动条。
// ==UserScript== // @name sb.sb 麻将 / 斗地主 / 牛牛 网页内全屏 // @namespace https://sb.sb/ // @version 3.0.0 // @description 将烧饼麻将、斗地主、牛牛游戏区域铺满网页视口;页面上的全屏按钮改为网页内全屏(Alt+F 同样可切换) // @match https://sb.sb/games/mahjong/ // @match https://sb.sb/games/dou-dizhu/ // @match https://sb.sb/games/niuniu/ // @run-at document-start // @grant none // ==/UserScript== (function () { 'use strict'; // 各游戏的面板与舞台选择器 const PANELS = [ '.form-panel.wheel-panel[data-mj]', // 麻将 '.form-panel.wheel-panel[data-ddz]', // 斗地主 '.form-panel.wheel-panel[data-nn]' // 牛牛 ]; const STAGES = ['.mj-stage', '.ddz-stage', '.nn-stage']; const FS_BTN = '[data-game-fs]'; const STYLE_ID = 'sb-page-fullscreen-style'; const ROOT_CLASS = 'sb-page-fs'; const R = `html.${ROOT_CLASS}`; const panelSel = PANELS.map(p => `${R} ${p}`).join(',\n'); const stageSel = PANELS.flatMap(p => STAGES.map(s => `${R} ${p} ${s}`)).join(',\n'); const css = ` /* 隐藏页面滚动条 */ ${R}, ${R} body { overflow: hidden !important; scrollbar-width: none !important; -ms-overflow-style: none !important; } ${R}::-webkit-scrollbar, ${R} body::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; } /* 游戏面板铺满网页视口 */ ${panelSel} { position: fixed !important; inset: 0 !important; width: 100vw !important; height: 100vh !important; height: 100dvh !important; max-width: none !important; max-height: none !important; margin: 0 !important; padding: 0 !important; border-radius: 0 !important; z-index: 999999 !important; background: #000 !important; overflow: hidden !important; box-sizing: border-box !important; } /* 牌桌舞台跟随面板大小 */ ${stageSel} { width: 100% !important; height: 100% !important; max-width: none !important; max-height: none !important; } `; function injectStyle() { if (document.getElementById(STYLE_ID)) return; const style = document.createElement('style'); style.id = STYLE_ID; style.textContent = css; (document.head || document.documentElement).appendChild(style); } function isEnabled() { return document.documentElement.classList.contains(ROOT_CLASS); } function setEnabled(on) { document.documentElement.classList.toggle(ROOT_CLASS, on); // 通知页面重新计算布局 window.dispatchEvent(new Event('resize')); } injectStyle(); setEnabled(true); // 默认进入网页内全屏;想默认关闭就改成 false // 拦截页面上的全屏按钮:捕获阶段处理,并阻止网站原有的原生全屏逻辑 document.addEventListener('click', (e) => { const btn = e.target instanceof Element ? e.target.closest(FS_BTN) : null; if (!btn) return; e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); setEnabled(!isEnabled()); }, true); // Alt + F 切换网页内全屏 document.addEventListener('keydown', (e) => { if (e.altKey && !e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'f') { e.preventDefault(); setEnabled(!isEnabled()); } }); })();- 收藏支持 1反对打赏

顶一个

顶一下

顶一个

