UserScripts
TamperMonkey関連
x.com
code:delete-for-you-tab.js
// ==UserScript==
// @name Delete "For You" from x.com
// @namespace http://tampermonkey.net/
// @version 2024-10-11
// @description x.comのオススメタブ削除
// @author You
// @match https://x.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant none
// ==/UserScript==
// from: https://github.com/typefully/minimal-twitter/blob/4c70df8805ea8057109c40cd174d14fab0e69995/content-scripts/src/modules/options/timeline.js#L333
// オススメタブが選択されていたら Following タブに強制的に切り替える
function changeFollowingTimeline() {
const tablist = document.querySelector("divdata-testid='ScrollSnap-List'role='tablist'");
const selectedTab = document.querySelector("divdata-testid='ScrollSnap-List'role='tablist' ahref='/home'aria-selected='true'");
// Check if there's a selected tab
if (!tablist || !selectedTab) return;
// Get localized "Following" text (it's the second tab)
const forYouTabText = tablist.querySelector("divrole='presentation':nth-of-type(1) span").textContent.toLowerCase();
const selectedTabText = selectedTab.querySelector("divdir='ltr' > span").textContent.toLowerCase();
if (selectedTabText === forYouTabText) {
const secondTab = tablist.querySelector("divrole='presentation':nth-child(2) a");
secondTab.click();
}
return; // Already on the "Following" tab
};
(function() {
'use strict';
// 特定のrole属性を持つdiv要素を非表示にする関数
function hideUnnecessaryDivs() {
const homeTimelineDiv = document.querySelector('divaria-label="Home timeline"');
if (window.location.pathname.startsWith('/home') && homeTimelineDiv) {
// 最初の <div role="presentation"> を見つけて非表示にする
const presentationDiv = homeTimelineDiv.querySelector('divrole="presentation"');
if (presentationDiv) {
presentationDiv.style.display = 'none'; // 非表示にする
} else {
console.log('No presentation div found.');
}
}
const jobLink = document.querySelector('ahref="/jobs"');
if (jobLink) {
jobLink.style.display = 'none';
}
changeFollowingTimeline(); // オススメタブを選択されないようにする
}
// 初回実行
hideUnnecessaryDivs();
// MutationObserverで動的に追加される要素も監視
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0) {
hideUnnecessaryDivs(); // 新しく追加された要素にも対応
}
});
});
// DOM全体を監視
observer.observe(document.body, { childList: true, subtree: true });
})();
code:dont_display_muted_person.js
// ==UserScript==
// @name X mute the muted
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Muteしたアカウントの投稿を表示しない
// @author https://gist.github.com/vfonic/6d834a2e3ef2fb799081cdafbba01cd2
// @match https://x.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant none
// ==/UserScript==
(function () {
'use strict'
const muteTheMuted = () => {
const elements = document.evaluate(
"//*contains(text(), 'This Post is from an account you muted.')",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null,
)
for (var i = 0; i < elements.snapshotLength; i++) {
elements.snapshotItem(i).parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.display = 'none'
}
}
new MutationObserver(function (mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
muteTheMuted()
return
}
}
}).observe(document, { childList: true, subtree: true })
})()
全ドメイン
code:add-notranslate-class-to-code-related-tags.js
// ==UserScript==
// @name Add notranslate class to code related tags
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description add notranslate class to code related tags
// @author zenwerk
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==
function addNoTranslateClass(tags) {
for(const tag of tags) {
tag.classList.add('notranslate');
}
}
(function () {
'use strict';
// Markdown や AsciiDoc のソースコードハイライト部分は翻訳しない
var preTags = document.getElementsByTagName('pre');
addNoTranslateClass(preTags);
var codeTags = document.getElementsByTagName('code');
addNoTranslateClass(codeTags);
// Doxygen
var fragmentDivs = document.getElementsByClassName('fragment');
addNoTranslateClass(fragmentDivs);
// Sphinx
var sigTags = document.getElementsByClassName('sig sig-object highlight');
addNoTranslateClass(sigTags);
var sigNames = document.getElementsByClassName('sig-name');
addNoTranslateClass(sigNames);
// tableの先頭tdは翻訳しない方が良い場合が多い
const trRows = document.querySelectorAll('table tbody tr');
trRows.forEach((tr) => {
const firstTd = tr.querySelector('td');
firstTd.classList.add('notranslate');
});
})();
Github
code:add-notranslate-class-to-code-related-tags-at-github.js
/// ==UserScript==
// @name Add notranslate class to code related tags at github
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description add notranslate class to code related tags at github
// @author zenwerk
// @match *://github.com/*
// @match *://gist.github.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
// ファイルリスト表示部分は翻訳しない
var fileListDiv = document.querySelector('div.Box.mb-3');
fileListDiv.classList.add('notranslate');
/* インラインのコード部分は翻訳しない
var codeTags = document.getElementsByTagName('code');
for (const codeTag of codeTags) {
var newDiv = document.createElement('div');
newDiv.classList.add('notranslate');
var parent = codeTag.parentNode;
parent.replaceChild(newDiv, codeTag);
newDiv.appendChild(codeTag);
}
*/
})();
Neat-reader
code:add-notranslate-class-to-code-related-tags-at-neat-reader.js
// ==UserScript==
// @name Add notranslate class to code related tags at Meat Reader
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description add notranslate class to code related tags at neat-reader
// @author zenwerk
// @match https://*.neat-reader.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @run-at document-idle
// ==/UserScript==
const setNoTranslateClass = () => {
// ソースコード部は翻訳しない
var preTags = document.getElementsByTagName('pre');
for (var i = 0; i < preTags.length; i++) {
preTagsi.classList.add('notranslate');
}
// tableの先頭tdは翻訳しない方が良い場合が多い
const trRows = document.querySelectorAll('table tbody tr');
trRows.forEach((tr) => {
const firstTd = tr.querySelector('td');
firstTd.classList.add('notranslate');
});
}
(function () {
'use strict';
var viewerNode = document.getElementById('neat-epub-viewer');
// (変更を監視する) オブザーバーのオプション
const config = { childList: true, subtree: true };
// 変更が発見されたときに実行されるコールバック関数
const callback = function (mutationsList, observer) {
// Use traditional 'for loops' for IE 11
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
// notranslateタグを付与する
setNoTranslateClass();
}
}
};
// コールバック関数に結びつけられたオブザーバーのインスタンスを生成
const observer = new MutationObserver(callback);
// 対象ノードの設定された変更の監視を開始
observer.observe(viewerNode, config);
// 右クリック有効化
document.addEventListener('contextmenu', (event) => {
event.stopImmediatePropagation();
}, true);
})();
livebook.manning.com
code:manning.js
// ==UserScript==
// @name Add notranslate class to code related tags at livebook.manning.com
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description add notranslate class to code related tags at livebook.manning.com
// @author zenwerk
// @match https://livebook.manning.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=manning.com
// @grant none
// @run-at document-idle
// ==/UserScript==
const setNoTranslateClass = () => {
// ソースコード部は翻訳しない
var preTags = document.getElementsByTagName('pre');
for (var i = 0; i < preTags.length; i++) {
preTagsi.classList.add('notranslate');
}
// tableの先頭tdは翻訳しない方が良い場合が多い
const trRows = document.querySelectorAll('table tbody tr');
trRows.forEach((tr) => {
const firstTd = tr.querySelector('td');
firstTd.classList.add('notranslate');
});
}
(function () {
'use strict';
var viewerNode = document.getElementById('main-page-content');
// (変更を監視する) オブザーバーのオプション
const config = { childList: true, subtree: true };
// 変更が発見されたときに実行されるコールバック関数
const callback = function (mutationsList, observer) {
// Use traditional 'for loops' for IE 11
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
// notranslate class を付与する
setNoTranslateClass();
}
}
};
// コールバック関数に結びつけられたオブザーバーのインスタンスを生成
const observer = new MutationObserver(callback);
// 対象ノードの設定された変更の監視を開始
observer.observe(viewerNode, config);
// 右クリック有効化
document.addEventListener('contextmenu', (event) => {
event.stopImmediatePropagation();
}, true);
})();
git-books
code:add-notranslate-class-to-code-related-tags-at-gitbooks.js
// ==UserScript==
// @name Add notranslate class to code related tags at git-books
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description add notranslate class to code related tags at gitbooks.io
// @author zenwerk
// @match https://*.gitbooks.io/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @require https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js
// ==/UserScript==
(function () {
'use strict';
waitForKeyElements('#book-search-results', node => {
node.find('pre').each((_, pre) => {
pre.classList.add('notranslate');
});
});
})();
Tcl/Tk
code:tcltkのmanページ向けnotranslate.js
// ==UserScript==
// @name tcl/tk のドキュメント向け notranslate
// @namespace http://tampermonkey.net/
// @version 1.0
// @description tcl/tk のドキュメント向け notranslate
// @author Your Name
// @match https://tcl.tk/*
// @match https://*.tcl.tk/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// name属性がLまたはMで始まる<a>タグにnotranslateクラスを追加する関数
function addNotranslateClass() {
// すべての<a>タグを取得
const links = document.querySelectorAll('aname');
links.forEach(link => {
const nameValue = link.getAttribute('name');
// name属性がLまたはMで始まるかチェック
if (nameValue && (nameValue.startsWith('L') || nameValue.startsWith('M'))) {
link.classList.add('notranslate'); // クラスを追加
console.log('Added notranslate class to:', link);
}
});
}
// 初回実行
addNotranslateClass();
// 動的に追加される要素にも対応するため、MutationObserverを使用
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length > 0) {
addNotranslateClass(); // 新しく追加された要素にも対応
}
});
});
// DOM全体を監視
observer.observe(document.body, { childList: true, subtree: true });
})();
DeepWiki.com
code:deepwiki.js
// ==UserScript==
// @name DeepWiki notranslation tag (safe version)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Prevent excessive MutationObserver loops on DeepWiki
// @match https://deepwiki.com/*
// @author ChatGPT
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==
function setNoTranslateClass() {
// pre要素すべてに notranslate
document.querySelectorAll('pre:not(.notranslate)').forEach(pre => {
pre.classList.add('notranslate');
});
// tableごとに処理
document.querySelectorAll('table').forEach(table => {
const thead = table.querySelector('thead');
const tbody = table.querySelector('tbody');
if (!thead || !tbody) return;
const headerRow = thead.querySelector('tr');
if (!headerRow) return;
const ths = headerRow.querySelectorAll('th');
if (ths.length < 2) return;
const secondThText = ths1.textContent.trim().toLowerCase();
if (secondThText === 'Type' || secondThText === 'type') {
tbody.querySelectorAll('tr').forEach(tr => {
const tds = tr.querySelectorAll('td');
if (tds.length >= 2 && !tds1.classList.contains('notranslate')) {
tds1.classList.add('notranslate');
}
});
}
});
// tbody の各 tr の最初の td にも notranslate(元の仕様)
document.querySelectorAll('table tbody tr').forEach(tr => {
const firstTd = tr.querySelector('td');
if (firstTd && !firstTd.classList.contains('notranslate')) {
firstTd.classList.add('notranslate');
}
});
}
(function() {
'use strict';
const targets = document.querySelectorAll('div.container.relative');
// 処理済み要素を記録して無限ループ防止
const processedSet = new WeakSet();
/*function setNoTranslateClass() {
document.querySelectorAll('pre:not(.notranslate)').forEach(pre => {
pre.classList.add('notranslate');
});
document.querySelectorAll('table tbody tr').forEach(tr => {
const firstTd = tr.querySelector('td');
if (firstTd && !firstTd.classList.contains('notranslate')) {
firstTd.classList.add('notranslate');
}
});
}*/
function addNotranslateToGRoot() {
document.querySelectorAll('g.root p').forEach(p => {
if (!processedSet.has(p)) {
p.classList.add('notranslate');
processedSet.add(p);
}
});
setNoTranslateClass();
}
const observer = new MutationObserver((mutationsList) => {
observer.disconnect(); // 一時停止(無限ループ対策)
addNotranslateToGRoot();
observerReconnect(); // 少し遅らせて再開
});
function observerReconnect() {
setTimeout(() => {
targets.forEach(target => {
observer.observe(target, {
attributes: true,
childList: true,
subtree: true,
});
});
}, 100); // 最小限のディレイを入れることで暴走抑制
}
// 初期化
addNotranslateToGRoot();
observerReconnect();
})();
Deprecated
vim-vixen
https://github.com/ueokande/vim-vixen/issues/1424#issuecomment-1191818598
code:fix-vim-vixen-white-bar.js
// ==UserScript==
// @name Vim Vixen Vix
// @namespace Violentmonkey Scripts
// @match *://*/*
// @grant GM_addStyle
// @run-at document-start
// @version 1.1
// @author -
// @description Fixes white bottom bar on dark themed web pages when using Vim Vixen
// ==/UserScript==
GM_addStyle(".vimvixen-console-frame {height: 0px; color-scheme: light !important;}");