Universal Governor Suite

Unified browser & script governor with media optimization, idle-aware scheduling, and network spike control for improved stability across dynamic web apps.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Universal Governor Suite
// @namespace    ultralean.universal.browser.script.governor
// @version      2.4.3
// @description  Unified browser & script governor with media optimization, idle-aware scheduling, and network spike control for improved stability across dynamic web apps.
// @author       Michael Stutesman
// @match        *://*/*
// @run-at       document-start
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(() => {
'use strict';

if (window.__UGS__) return;
window.__UGS__ = 1;

/* =========================================================
   🧿 PHANTOM-STYLE SITE EXCLUSIONS (FULL SYSTEM)
========================================================= */

const HOST = location.hostname.toLowerCase();
const EXCLUSION_KEY = "ugb_excluded_sites";

/* load list safely */
const excluded = GM_getValue(EXCLUSION_KEY, []) || [];

/* HARD EXIT (must run BEFORE anything else) */
if (excluded.includes(HOST)) return;

/* ---------------- MENU COMMANDS ---------------- */

GM_registerMenuCommand("🚫 Exclude this site (UGS)", () => {
    const list = GM_getValue(EXCLUSION_KEY, []) || [];

    if (!list.includes(HOST)) {
        list.push(HOST);
        GM_setValue(EXCLUSION_KEY, list);
    }

    location.reload();
});

GM_registerMenuCommand("✅ Re-enable this site (UGS)", () => {
    let list = GM_getValue(EXCLUSION_KEY, []) || [];
    list = list.filter(x => x !== HOST);

    GM_setValue(EXCLUSION_KEY, list);
    location.reload();
});

GM_registerMenuCommand("🧹 Clear all exclusions (UGS)", () => {
    GM_setValue(EXCLUSION_KEY, []);
    location.reload();
});

/* =========================================================
   🧠 CORE STATE (single source of truth)
========================================================= */

const U = {
H: HOST,
K: EXCLUSION_KEY,

S: { d:new Set(), q:[], r:[], e:[], h:0, a:0 },

L: Date.now(),
I: 0,

C: { m:7, b:14, bd:9, base:1, heavy:30000, idle:700 },

/* =========================================================
   🚫 INIT + EXCLUSIONS + CSS
========================================================= */

init(){

/* 🎨 visual simplifier */
GM_addStyle(`
*{
backdrop-filter:none!important;
-webkit-backdrop-filter:none!important;
filter:none!important;
box-shadow:none!important;
text-shadow:none!important
}
video,canvas,img{
transform:translateZ(0);
will-change:transform,opacity
}
img{content-visibility:auto}
`);

/* 🌙 activity signals */
onmousemove=onscroll=onkeydown=()=>{this.L=Date.now();this.I=1};
document.addEventListener("visibilitychange",()=>{this.L=Date.now();this.I=1});

/* =========================================================
   🌐 NETWORK LAYER
========================================================= */

const E = f => new Promise((r,e)=>{
this.S.q.push(f);
this.S.r.push(r);
this.S.e.push(e);
});

fetch = ((fn)=>(...a)=>E(()=>fn(...a)))(fetch);

const o = XMLHttpRequest.prototype.open,
      s = XMLHttpRequest.prototype.send;

XMLHttpRequest.prototype.open=function(...a){
this.__u=a[1];
return o.apply(this,a);
};

XMLHttpRequest.prototype.send=function(...a){
const x=this;
return E(()=>new Promise((r,e)=>{
x.onload=()=>r(x);
x.onerror=()=>e(x);
s.apply(x,a);
}));
};

/* =========================================================
   🎥 MEDIA LAYER
========================================================= */

const PRECONNECT_CACHE = new Set();

this.v = (v) => {
if(!v || v.__t) return;
v.__t = 1;

try { v.load?.(); } catch {}

v.setAttribute("decoding", "async");
v.preload = (v.muted || v.hasAttribute("autoplay")) ? "auto" : "metadata";
v.playsInline = true;

v.style.contentVisibility = "auto";
v.style.containIntrinsicSize = "480px 270px";
v.style.backgroundColor = "#000";

if(!v.hasAttribute("poster")){
v.poster = "data:image/gif;base64,R0lGODlhAQABAAAAACw=";
}

v.disablePictureInPicture = false;
v.disableRemotePlayback = false;

if("fetchPriority" in v){
v.fetchPriority = v.hasAttribute("autoplay") ? "high" : "low";
}

try{
const src = v.currentSrc || v.src;
if(src){
const url = new URL(src);
if(!PRECONNECT_CACHE.has(url.origin)){
PRECONNECT_CACHE.add(url.origin);
const l = document.createElement("link");
l.rel = "preconnect";
l.href = url.origin;
document.head.appendChild(l);
}
}
}catch{}

if(!v.__p){
v.__p = 1;
queueMicrotask(() => {
try { v.load?.(); } catch {}
});
}

if(!v.__o){
v.__o = 1;
this.O.observe(v);
}
};

/* =========================================================
   🌱 DOM PROCESSOR
========================================================= */

this.d = (n) => {
if(!n || n.nodeType!==1) return;
if(n.tagName==="VIDEO") return this.v(n);

const v = n.getElementsByTagName?.("video");
if(v) for(let i=0;i<v.length;i++) this.v(v[i]);
};

/* =========================================================
   👁 INTERSECTION OBSERVER
========================================================= */

this.O = new IntersectionObserver(e=>{
for(const x of e){
const v = x.target;

if(v.tagName==="VIDEO"){
v.dataset.visible = x.isIntersecting ? 1 : 0;

if(x.isIntersecting){
try{ v.load?.(); }catch{}
}

this.L = Date.now();
this.I = 1;
}
}
},{rootMargin:"300px"});

/* =========================================================
   🧠 HEARTBEAT ENGINE
========================================================= */

this.tick = () => {

let p = this.S.q.length - this.S.h,
    d = this.C.base;

if(p >= this.C.b) d += this.C.bd;
if(this.I) this.I = 0;

if(Date.now() - this.L > this.C.heavy) this.I = 0;

if(this.S.d.size){
for(const n of this.S.d) this.d(n);
this.S.d.clear();
}

if(this.S.a < this.C.m && this.S.h < this.S.q.length){
this.S.a++;
const i = this.S.h++;

setTimeout(()=>{
this.S.q[i]().then(this.S.r[i], this.S.e[i]);
this.S.a--;
}, d);
}

setTimeout(()=>this.tick(), this.I ? 80 : this.C.idle);
};

/* =========================================================
   🚀 STARTUP
========================================================= */

document.querySelectorAll("video").forEach(v=>this.v(v));

this.tick();

}
};

/* =========================================================
   🌱 MUTATION OBSERVER
========================================================= */

new MutationObserver(m=>{
for(const x of m)
for(const n of x.addedNodes)
if(n?.nodeType===1){
U.S.d.add(n);
U.L = Date.now();
U.I = 1;
}
}).observe(document.documentElement,{
childList:1,
subtree:1
});

/* =========================================================
   🚀 BOOT
========================================================= */

U.init();

})();