Skip to content

Instantly share code, notes, and snippets.

@onteria
Last active June 20, 2021 13:52
Show Gist options
  • Save onteria/6847678 to your computer and use it in GitHub Desktop.
Save onteria/6847678 to your computer and use it in GitHub Desktop.
リツイートのふぁぼ・RTをWeb公式で非表示にするChromeユーザースクリプト。インストール方法は( http://egyo.hateblo.jp/entry/20101022/1287713022 )。
// ==UserScript==
// @match https://twitter.com/i/connec*
// @author onteria_
// @version 2.0
// ==/UserScript==
// Author: @onteria_
// This is a script that is meant to hide recently
// added "retweet of retweet" and "favorite of retweet"
// which have no options to disable and can get rather
// noisy
// Variables
// Tweets container div id
var timeline_id = "timeline"
// * of Retweet class
var retweet_action_classes = [
"js-activity-favorited_retweet",
"js-activity-retweeted_retweet"]
var new_tweet_bar_class = "js-new-tweets-bar"
function hide_node_if_class_match(node, class_list) {
for (var i = 0; i < class_list.length; i++) {
var check_class = class_list[i]
var node_classes = node.className.split(' ')
if ( node_classes.indexOf(check_class) != -1 ) {
node.style.display = 'none'
break
}
}
}
function check_new_tweets_bar(node, bar_class_name) {
var node_classes = node.className.split(' ')
if( node_classes.indexOf(bar_class_name) != -1 ) {
node.click()
}
}
var stream_container = document.getElementById(timeline_id);
var stream_items = stream_container.getElementsByTagName('li')
for (var i = 0; i < stream_items.length; i++) {
hide_node_if_class_match(stream_items[i], retweet_action_classes)
}
// This part checks for infinite scroll changes
// or tweets added by clicking on the new tweet bar
// it uses MutationObserver to handle these changes
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
for ( var i = 0; i < mutation.addedNodes.length; i++) {
hide_node_if_class_match(mutation.addedNodes[i], retweet_action_classes)
check_new_tweets_bar(mutation.addedNodes[i], new_tweet_bar_class)
}
});
});
// Only listen for stream mutations to save resources
observer.observe(stream_container, { childList: true });
@Korb
Copy link

Korb commented Jun 20, 2021

Chrome user script that hides retweet favorites and RTs

Chrome only, not Mozilla Firefox?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment