Skip to content

Instantly share code, notes, and snippets.

@yatt
Last active March 22, 2021 15:42
Show Gist options
  • Save yatt/50e9e1b8c4b87d9c9c4c82ff3f24d376 to your computer and use it in GitHub Desktop.
Save yatt/50e9e1b8c4b87d9c9c4c82ff3f24d376 to your computer and use it in GitHub Desktop.
Twitter おすすめトピック 無効化 非表示 除去 tampermonkey script to disable topic suggestions 2021-03-21(experimental)
// ==UserScript==
// @name Twitter おすすめトピック 除去 (disable topic suggestions for twitter japan)
// @namespace https://gist.github.com/yatt/
// @version 0.1
// @description おすすめトピックを除去する.
// @author yatt
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var config = {childList: true, subtree: true};
function removeTopic() {
var lst = document.querySelectorAll('span');
lst.forEach(span => {
if (span.innerText === 'おすすめトピック'){
var div = span.parentElement.parentElement.parentElement.parentElement.parentElement;
// 余白
var margin1 = div.previousSibling;
// "おすすめトピック"
var title = div;
// 本体
var mainContent = title.nextSibling;
// "その他のトピック"
var furtherDetail = mainContent.nextSibling;
// 予約
var margin2 = furtherDetail.nextSibling;
console.log('削除対象');
console.log(margin1);
console.log(title);
console.log(mainContent);
console.log(furtherDetail);
console.log(margin2);
margin1.style.visibility ="hidden";
margin1.style.height = "1px";
title.style.visibility ="hidden";
title.style.height = "1px";
mainContent.style.visibility ="hidden";
mainContent.style.height = "1px";
furtherDetail.style.visibility ="hidden";
furtherDetail.style.height = "1px";
margin2.style.visibility ="hidden";
margin2.style.height = "1px";
// removeするとパジネーションの際にエラーが発生する
//margin1.remove();
//title.remove();
//mainContent.remove();
//furtherDetail.remove();
//margin2.remove();
}
});
}
var observer = new MutationObserver((rs, observer) => {
// おすすめトピックの本体を見つけたら処理して終了
for (var i = 0; i < rs.length; i++) {
rs[i].addedNodes.forEach(node => {
if (node.querySelectorAll) {
var lst = node.querySelectorAll('[aria-label="タイムライン: Carousel"]')
if (lst.length > 0) {
removeTopic();
// スクロールすると復活するので止められない
//observer.disconnect();
}
}
});
}
});
observer.observe(document, config);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment