Created
December 24, 2022 00:05
-
-
Save MattArnold/efd773432385b5a932bdeb7474ad3a2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Hide Twitter Trending Now and view counts | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Hide Twitter Trending Now and view counts | |
// @author You | |
// @match https://twitter.com/* | |
// @icon https://www.google.com/s2/favicons?domain=twitter.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function bodyCallback (mutations) { | |
tryToFindSidebar(); | |
tryToFindTimeline(); | |
} | |
function sidebarCallback () { | |
tryToHideTrendingTopics(); | |
} | |
function timelineCallback () { | |
tryToHideViewCounts(); | |
} | |
let bodyObserver = new MutationObserver(bodyCallback); | |
const bodyTargetNode = document.querySelector('body'); | |
bodyObserver.observe( | |
bodyTargetNode, | |
{ | |
childList: true, | |
subtree: true, | |
} | |
); | |
const tryToFindSidebar = () => { | |
const sidebarTargetNode = document.querySelector('[data-testid="sidebarColumn"]'); | |
if (sidebarTargetNode) { | |
console.log(`sidebar is present.`); | |
let sidebarObserver = new MutationObserver(sidebarCallback); | |
sidebarObserver.observe( | |
sidebarTargetNode, | |
{ | |
childList: true, | |
subtree: true, | |
} | |
); | |
} else { | |
console.log(`sidebar is not present.`); | |
} | |
} | |
const tryToHideTrendingTopics = () => { | |
let trending = document.querySelector('[aria-label*="Trending now"]'); | |
if (trending) { | |
console.log(`hiding Trending Topics pane.`); | |
trending.style.display = 'none'; | |
} else { | |
console.log(`Trending Topics pane not rendered yet.`); | |
} | |
} | |
const tryToFindTimeline = () => { | |
var timelineTargetNode = document.querySelector('[aria-label="Timeline: Your Home Timeline"]'); | |
if (timelineTargetNode) { | |
console.log(`timeline is present.`); | |
let timelineObserver = new MutationObserver(timelineCallback); | |
timelineObserver.observe( | |
timelineTargetNode, | |
{ | |
childList: true, | |
subtree: true, | |
} | |
); | |
} else { | |
console.log(`timeline is not present.`); | |
} | |
} | |
const tryToHideViewCounts = () => { | |
let viewCountsTargetNode = document.querySelectorAll("a[href*='analytics']")[0]; | |
if (viewCountsTargetNode) { | |
let viewCounts = document.querySelectorAll("a[href*='analytics']"); | |
viewCounts.forEach(viewCount =>{ | |
viewCount.parentNode.style.display = 'none'; | |
}) | |
console.log('# of view analytics: ', viewCounts.length); | |
} else { | |
console.log('viewcounts are not present'); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment