// ==UserScript== // @name Hide GitHub Flagged Organization Banner // @namespace https://github.com/Iamliuxiaozhen/Hide-GitHub-Flagged-Organization-Banner // @version 1.0.1 // @description Remove GitHub's flagged organization global error banner. // @author Oliver // @homepageURL https://github.com/Iamliuxiaozhen/Hide-GitHub-Flagged-Organization-Banner // @match https://github.com/* // @run-at document-start // @grant none // ==/UserScript== (function () { 'use strict'; const BANNER_SELECTOR = 'section[aria-label="Error"].flash.flash-full.js-notice.flash-error'; const FLAGGED_ORG_HEADING_PATTERN = /^the\s+.+\s+organization\s+has\s+been\s+flagged\.$/i; function isTargetBanner(element) { const heading = element.querySelector('h4'); if (!heading) { return false; } return FLAGGED_ORG_HEADING_PATTERN.test(heading.textContent.trim()); } function removeTargetBanners(root) { if (!root || (root.nodeType !== Node.ELEMENT_NODE && root.nodeType !== Node.DOCUMENT_NODE)) { return; } const candidates = []; if (root.nodeType === Node.ELEMENT_NODE && root.matches(BANNER_SELECTOR)) { candidates.push(root); } candidates.push(...root.querySelectorAll(BANNER_SELECTOR)); for (const candidate of candidates) { if (isTargetBanner(candidate)) { candidate.remove(); } } } removeTargetBanners(document); const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { for (const node of mutation.addedNodes) { removeTargetBanners(node); } } }); function startObserver() { if (!document.documentElement) { return; } removeTargetBanners(document); observer.observe(document.documentElement, { childList: true, subtree: true, }); } if (document.documentElement) { startObserver(); } else { document.addEventListener('DOMContentLoaded', startObserver, { once: true }); } })();