讨论 » 开发

Ukrainian flag(Not every Chinese person supports Russia)

§
发布于:2025-12-28
编辑于:2025-12-28

// ==UserScript==
// @name Ukrainian flag(ctrl+shift+U)
// @namespace tampermonkey.net
// @version 12.0
// @description 左下角飄揚勳章。Ctrl+Shift+U 循環切換開啟/關閉。
// @author 邢智轩(from China)
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==

(function() {
'use strict';

let isTerminated = false; // 用於追蹤使用者是否手動關閉

// 1. 核心注入函數
function injectBadge() {
if (document.getElementById('ua-waving-badge-root')) return;

const host = document.createElement('div');
host.id = 'ua-waving-badge-root';
host.style.cssText = `
position: fixed !important;
bottom: 30px !important;
left: 30px !important;
z-index: 2147483647 !important;
pointer-events: none !important;
display: block !important;
transition: opacity 0.4s ease, transform 0.4s ease !important;
opacity: 0;
transform: translateY(20px);
`;
document.documentElement.appendChild(host);

const shadow = host.attachShadow({mode: 'closed'});

// SVG 資源
const tridentSvg = ``;
const shieldSvg = ``;

shadow.innerHTML = `

${tridentSvg}
${shieldSvg}

`;

// 入場動畫
requestAnimationFrame(() => {
host.style.opacity = '1';
host.style.transform = 'translateY(0)';
});
}

// 2. 快捷鍵切換邏輯 (Ctrl + Shift + U)
window.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.shiftKey && e.code === 'KeyU') {
const root = document.getElementById('ua-waving-badge-root');
if (root) {
// 執行關閉
root.style.opacity = '0';
root.style.transform = 'translateY(20px)';
setTimeout(() => {
root.remove();
isTerminated = true;
}, 400);
} else {
// 執行開啟
isTerminated = false;
injectBadge();
}
}
}, true);

// 3. 強制置頂與自癒校驗 (每 1.5 秒一次)
function enforce() {
if (isTerminated) return;

const root = document.getElementById('ua-waving-badge-root');
if (!root || !document.documentElement.contains(root)) {
injectBadge();
} else {
// 層級檢查
if (root.parentElement !== document.documentElement) {
document.documentElement.appendChild(root);
}
if (root.style.zIndex !== '2147483647') {
root.style.setProperty('z-index', '2147483647', 'important');
}
}
}

// 初始啟動
injectBadge();
setInterval(enforce, 1500);
const observer = new MutationObserver(enforce);
observer.observe(document.documentElement, { childList: true, subtree: true });

})();

§
发布于:2025-12-29
编辑于:2025-12-29

https://greasyfork.org.cn/zh-CN/scripts/560536-ukrainian-flag-ctrl-shift-u

💙💛💙💛 update 12.2 add icon for tampermonkey

发布留言

登录以发布留言。