Created
December 31, 2025 16:19
-
-
Save szhu/f3d862d8dc06b623ba3fc9f1ba32da91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Prevent Input Zoom (robust) | |
| // @match *://*/* | |
| // @run-at document-start | |
| // ==/UserScript== | |
| const VIEWPORT_CONTENT = | |
| "width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"; | |
| function upsertViewportMeta() { | |
| let [meta, ...others] = document.querySelectorAll('meta[name="viewport"]'); | |
| for (let otherMeta of others) { | |
| otherMeta.remove(); | |
| } | |
| if (!meta) { | |
| meta = document.createElement("meta"); | |
| meta.name = "viewport"; | |
| } | |
| if (meta.getAttribute("content") != VIEWPORT_CONTENT) { | |
| // alert(meta.getAttribute("content")); | |
| meta.setAttribute("content", VIEWPORT_CONTENT); | |
| } | |
| if (!meta.parent) { | |
| document.head.appendChild(meta); | |
| } | |
| } | |
| function debouncedUpsertViewportMeta() { | |
| clearTimeout(debouncedUpsertViewportMeta.timeout); | |
| debouncedUpsertViewportMeta.timeout = setTimeout(upsertViewportMeta, 50); | |
| } | |
| debouncedUpsertViewportMeta(); | |
| new MutationObserver(debouncedUpsertViewportMeta) // | |
| .observe(document.head, { | |
| childList: true, | |
| subtree: false, | |
| attributes: true, | |
| attributeFilter: ["content", "name"], | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment