Last active
March 22, 2021 15:42
-
-
Save yatt/50e9e1b8c4b87d9c9c4c82ff3f24d376 to your computer and use it in GitHub Desktop.
Twitter おすすめトピック 無効化 非表示 除去 tampermonkey script to disable topic suggestions 2021-03-21(experimental)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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