Skip to content

Instantly share code, notes, and snippets.

@soychicka
Last active December 29, 2018 23:42
Show Gist options
  • Save soychicka/d2f0221afd1d96c5f7f09144f283013e to your computer and use it in GitHub Desktop.
Save soychicka/d2f0221afd1d96c5f7f09144f283013e to your computer and use it in GitHub Desktop.
get crap out of your twitter timeline. there'll be an extension eventually.
var toggle_a = '<li><a href="#"><span class="Icon Icon Icon--retweeted Icon--large"></span><span id="';
var toggle_b = '" class="text">hide</span></a></li>';
var hide_junk_div = $(toggle_a + 'hide_junk_button_text'+toggle_b);
var hide_rt_div = $(toggle_a + 'hidert_button_txt'+toggle_b);
(function() {
var rt = ".js-activity-retweet";
var rt_quote = ".js-activity-quote"
var rt_mention = ".js-activity-retweeted_mention"
var response = ".js-activity-mention"
var like = ".js-activity-favorite"
var rt_liked = ".js-activity-favorited_retweet"
var liked_mention=".stream-item-favorited_mention"
var rt_rt =".js-activity-retweeted_retweet"
var rt_mention=".js-activity-retweeted_mention"
var ignore = [like, rt, rt_liked, liked_mention, rt_rt, rt_mention].join(", ")
var objType = ["retweet", "quote", "retweeted_mention", "mention", "favorite"]
var junk_visible = true;
var retweets_visible = true;
function hide_likes() {
var retweets = $(ignore).filter(':visible');
retweets.hide();
retweets.parents('.expanded-conversation').hide();
console.log('foo');
junk_visible = false;
}
function hide_retweets() {
var retweets = $('.js-retweet-text').parent().parent().parent().filter(':visible');
retweets.hide();
retweets.parents('.expanded-conversation').hide();
console.log('foo');
retweets_visible = false;
}
// select the target node
//var observer_target = document.querySelector('#stream-items-id');
var page_container = document.querySelector('#page-container');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
//console.log('observer fired, junk_visible=', junk_visible);
if (!junk_visible) {
hide_likes();
}
});
// configuration of the observer:
var observer_config = { attributes: false, childList: true, characterData: false, subtree:true };
observer.observe(page_container, observer_config);
$(hide_junk_div).click(function() {
//console.log('toggling retweets');
if (junk_visible) {
hide_likes();
$('#hide_junk_button_text').text('show');
//observer.observe(page_container, observer_config);
} else {
//observer.disconnect();
var retweets = $(ignore);
retweets.show();
retweets.parents('.expanded-conversation').show();
$('#hide_junk_button_text').text('hide');
junk_visible = true;
}
});
$(hide_rt_div).click(function() {
//console.log('toggling retweets');
if (retweets_visible) {
hide_retweets();
$('#hidert_button_txt').text('show');
//observer.observe(page_container, observer_config);
} else {
//observer.disconnect();
var retweets = $('.js-retweet-text').parent().parent().parent();
retweets.show();
retweets.parents('.expanded-conversation').show();
$('#hidert_button_txt').text('hide');
retweets_visible = true;
}
});
var nav_bar = $('#global-nav-home').parent();
$(nav_bar).find('.topics').hide(); //hide the discover button and replace with hide_junk_div
if (window.location.href.match('notifications')){
$(nav_bar).append(hide_junk_div); //show the hide retweets button
$(hide_junk_div).click()
}else{
$(nav_bar).append(hide_rt_div); //show the hide retweets button
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment