Scattered Javascripts
跳转到导航
跳转到搜索
I don’t know JavaScript, truly, it has exceeded my capability. Thus, all these scripts were written by AI.
Eliminate Emoji
eliminate-emoji.user.js
// ==UserScript==
// @name Eliminate Emoji
// @namespace Boreas
// @version 1.1
// @description Eliminate all the disgusting Emoji except regional flags.
// @author Boreas
// @match *://*/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
const r = /([\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2B00}-\u{2BFF}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}])/gu;
function isEditableContext(el) {
while (el && el.nodeType === 1) {
const t = el.tagName;
if (t === 'INPUT' || t === 'TEXTAREA') return true;
if (el.isContentEditable) return true;
const ce = el.getAttribute && el.getAttribute('contenteditable');
if (ce !== null && ce !== 'false') return true;
const role = el.getAttribute && el.getAttribute('role');
if (role === 'textbox') return true;
el = el.parentElement;
}
return false;
}
function shouldSkipTextNode(n) {
const p = n.parentElement;
if (!p) return true;
const t = p.tagName;
if (t === 'SCRIPT' || t === 'STYLE' || t === 'TEXTAREA' || t === 'TITLE' || t === 'INPUT') return true;
if (isEditableContext(p)) return true;
return false;
}
function p(d) {
if (!d || ![1, 9, 11].includes(d.nodeType)) return;
const w = document.createTreeWalker(d, NodeFilter.SHOW_TEXT);
let n;
while (n = w.nextNode()) {
if (shouldSkipTextNode(n)) continue;
const v = n.nodeValue;
if (!v || !r.test(v)) continue;
r.lastIndex = 0;
n.nodeValue = v.replace(r, '$&\uFE0E');
}
}
p(document.body);
const o = new MutationObserver(l => l.forEach(m => m.addedNodes.forEach(n => p(n))));
if (document.body) {
o.observe(document.body, {
childList: true,
subtree: true
});
}
window.addEventListener('beforeunload', () => o.disconnect());
})();
Google Logo Replacer
google-logo-replacer.user.js
// ==UserScript==
// @name Google Logo Replacer
// @namespace Boreas
// @version 2.1
// @description Replace the ugly Google Logo with the prettier one
// @author Boreas
// @match https://www.google.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function isTargetSVG(svgElement) {
return svgElement.outerHTML.startsWith('<svg aria-hidden="true" height="30" viewBox="0 0 92 30" width="92" xmlns="http://www.w3.org/2000/svg">') ||
svgElement.outerHTML.startsWith('<svg class="lnXdpd" aria-label="Google" height="92" role="img" viewBox="0 0 272 92" width="272" xmlns="http://www.w3.org/2000/svg">');
}
document.querySelectorAll('svg').forEach(svgElement => {
if (isTargetSVG(svgElement)) {
const imgElement = document.createElement('img');
imgElement.src = "https://upload.wikimedia.org/wikipedia/commons/c/c9/Google_logo_%282013-2015%29.svg";
imgElement.width = svgElement.getAttribute('width') === '272' ? 272 : 87.33;
imgElement.height = svgElement.getAttribute('height') === '92' ? 92 : 30;
svgElement.replaceWith(imgElement);
}
});
})();
Hide ‘Dynamic’, ‘x86’, ‘ARM64’, ‘22h2’, or ‘23h2’ updates on Microsoft Update Catalogue
msuc-hide-rows.user.js
// ==UserScript==
// @name Hide ‘Dynamic’, ‘x86’, ‘ARM64’, ‘22h2’, or ‘23h2’ updates on Microsoft Update Catalogue
// @namespace Boreas
// @version 1.0
// @description Hide rows of ‘Dynamic’, ‘x86’, ‘22h2’, ‘23h2’, or ‘ARM64’ on the Microsoft Update Catalogue.
// @author Boreas
// @match https://www.catalog.update.microsoft.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function hideRows() {
const rows = document.querySelectorAll('tr');
rows.forEach(row => {
const link = row.querySelector('td a');
if (link) {
if (/(dynamic|x86|arm64|22h2|23h2)/i.test(link.textContent)) {
row.style.display = 'none';
row.style.visibility = 'hidden';
}
}
});
}
const observer = new MutationObserver(hideRows);
observer.observe(document.body, {childList: true, subtree: true});
hideRows();
})();
Hide ‘siteNotice’ divs on Wikimedia sites
wiki-hide-sitenotice.user.js
// ==UserScript==
// @name Hide siteNotice on Wiki Sites
// @namespace Boreas
// @version 1.0
// @description Hide siteNotice divs on Wikimedia sites
// @author Boreas
// @match http://*.org/*
// @match https://*.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const regex = /^http[s]?:\/\/[a-z0-9-]*\.(media)?wik[i]?([a-gikm-wy]{4,9})?\.org\/.*$/;
if (regex.test(window.location.href)) {
const siteNotice = document.getElementById('siteNotice');
if (siteNotice) {
siteNotice.style.display = 'none';
}
}
})();
Or, alternatively, use the following userstyle with Stylus instead—
wiki_hide_sitenotice.css
@-moz-document regexp("^http[s]?:\\/\\/[a-z0-9-]*\\.(media)?wik[i]?([a-gikm-wy]{4,9})?\\.org\\/.*$") {
#siteNotice {
display: none !important;
}
}
Scroll horizontally
Change the default behaviour of scrolling by mouse from vertically to horizontally to scroll right-to-left vertical pages. Reference this script by including <script src="path/to/hs.js"></script> in the <head>…</head> section to use it.
hs.js
(function () {
function scrollHorizontally(e) {
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
document.documentElement.scrollLeft -= (delta * -30);
document.body.scrollLeft -= (delta * -30);
e.preventDefault();
}
if (window.addEventListener) {
window.addEventListener("mousewheel", scrollHorizontally, false);
window.addEventListener("DOMMouseScroll", scrollHorizontally, false);
} else {
window.attachEvent("onmousewheel", scrollHorizontally);
}
})();
V2EX 國曆化
v2ex-arify.user.js
// ==UserScript==
// @name V2EX 國曆化
// @namespace http://tampermonkey.net/
// @version 2.0
// @description 將 V2EX 上的相對時間還原為絕對時間並使用國曆。
// @author Boreas
// @match https://www.v2ex.com/*
// @match https://v2ex.com/*
// @match http://www.v2ex.com/*
// @match http://v2ex.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @run-at document-idle
// ==/UserScript==
(()=>{'use strict';
let g=GM_getValue('gmt',false),s=GM_getValue('sec',true);
let r=/(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})\s+([+-]\d{2}:\d{2})/;
let z=n=>(''+n).padStart(2,'0');
let fmt=d=>{
let Y=g?d.getUTCFullYear():d.getFullYear(),M=(g?d.getUTCMonth():d.getMonth())+1,D=g?d.getUTCDate():d.getDate(),H=g?d.getUTCHours():d.getHours(),I=g?d.getUTCMinutes():d.getMinutes(),S=g?d.getUTCSeconds():d.getSeconds();
return(Y-1911)+'-'+z(M)+'-'+z(D)+' '+z(H)+':'+z(I)+(s?':'+z(S):'');
};
let fa=e=>{
if(e.dataset.v2at)return;
let a=e.getAttribute('title')||e.getAttribute('data-original-title');if(!a)return;
let m=(''+a).match(r);if(!m)return;
let d=new Date(m[1]+'T'+m[2]+m[3]);if(isNaN(d))return;
e.textContent=fmt(d);
e.dataset.v2at='1';
};
let fg=e=>{
if(e.dataset.v2ag)return;
let q=false;
e.childNodes.forEach(n=>{
if(n.nodeType!==3)return;
let t=n.nodeValue,m=t&&t.match(r);if(!m)return;
let d=new Date(m[1]+'T'+m[2]+m[3]);if(isNaN(d))return;
n.nodeValue=t.replace(m[0],fmt(d));
q=true;
});
if(q)e.dataset.v2ag='1';
};
let run=()=>{
document.querySelectorAll('span[title],span[data-original-title]').forEach(fa);
document.querySelectorAll('span.gray').forEach(fg);
};
let p=n=>{
if(!n)return;
if(n.nodeType===1){
if(n.matches('span[title],span[data-original-title]'))fa(n);
if(n.matches('span.gray'))fg(n);
n.querySelectorAll&&n.querySelectorAll('span[title],span[data-original-title],span.gray').forEach(m=>{if(m!==n){if(m.matches('span.gray'))fg(m);else fa(m)}});
}
};
GM_registerMenuCommand('GMT '+(g?'on':'off'),()=>{GM_setValue('gmt',!g);location.reload()});
GM_registerMenuCommand('seconds '+(s?'on':'off'),()=>{GM_setValue('sec',!s);location.reload()});
run();
let t=null;
new MutationObserver(m=>{
if(t)return;
t=setTimeout(()=>{t=null;m.forEach(x=>{
if(x.type==='childList'){x.addedNodes&&x.addedNodes.forEach(p)}
else if(x.type==='characterData'){let pe=x.target&&x.target.parentElement;if(pe&&pe.matches('span.gray'))fg(pe)}
})},100);
}).observe(document.body||document.documentElement,{childList:true,subtree:true,characterData:true});
})();
維基辭典台陸別音詞讀音提取
wikt-grab.user.js
// ==UserScript==
// @name 維基辭典台陸別音詞讀音提取
// @namespace Boreas
// @version 1.0
// @description 於台陸別音詞條目頁面上顯示 ‘grab’ 按鈕並在按下後按照詞\t台灣讀音\t大陸讀音的方式提取台陸別音詞的讀音
// @author Boreas
// @match https://en.wiktionary.org/wiki/*
// @grant GM_setClipboard
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
function main() {
var h2 = document.querySelector('h2#Chinese');
if (!h2) return;
var sibling = h2.parentElement.nextElementSibling;
while (sibling && sibling.querySelector('h2') === null) {
if (sibling.querySelector('h3') && sibling.querySelector('h3').textContent.trim().startsWith('Pronunciation')) {
var h3 = sibling.querySelector('h3');
var pronunciationDiv = sibling.nextElementSibling;
if (pronunciationDiv && (pronunciationDiv.classList.contains('zhpron') || pronunciationDiv.classList.contains('toccolours'))) {
var vsHideDiv = pronunciationDiv.querySelector('.vsHide');
if (!vsHideDiv) {
vsHideDiv = pronunciationDiv;
}
var liMandarin = vsHideDiv.querySelector('li > a[title="w:Mandarin Chinese"]');
if (liMandarin) {
var liMandarinParent = liMandarin.parentElement;
var lisUnderMandarin = liMandarinParent.querySelectorAll('ul > li');
var liMainland = null;
var liTaiwan = null;
lisUnderMandarin.forEach(function(li) {
var text = li.textContent;
if (text.includes('standard in Mainland; variant in Taiwan')) liMainland = li;
else if (text.includes('Standard Chinese, Mainland')) liMainland = li;
else if (text.includes('Standard Chinese, Taiwan')) liTaiwan = li;
else if (text.includes('standard in Mainland')) liMainland = li;
else if (text.includes('standard in Taiwan')) liTaiwan = li;
});
if (liMainland && liTaiwan) {
var button = document.createElement('button');
button.textContent = 'grab';
button.style.marginLeft = '10px';
h3.appendChild(button);
button.addEventListener('click', function() {
var h1 = document.querySelector('h1').textContent.trim();
var t = h1 + '\t';
var z1 = '', p1 = '', p2 = '', z2 = '';
var l1 = liTaiwan.querySelectorAll('li');
l1.forEach(function(item) {
var text = item.textContent.trim();
if (text.startsWith('Zhuyin:')) z1 = text.replace('Zhuyin:', '').trim();
else if (text.startsWith('Hanyu Pinyin:')) p1 = text.replace('Hanyu Pinyin:', '').trim();
});
var l2 = liMainland.querySelectorAll('li');
l2.forEach(function(item) {
var text = item.textContent.trim();
if (text.startsWith('Hanyu Pinyin:')) p2 = text.replace('Hanyu Pinyin:', '').trim();
else if (text.startsWith('Zhuyin:')) z2 = text.replace('Zhuyin:', '').trim();
});
t += z1 + '\t' + p1 + '\t' + p2 + '\t' + z2;
GM_setClipboard(t);
});
}
}
}
}
sibling = sibling.nextElementSibling;
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', main);
} else {
main();
}
})();