Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit d11a8bf

Browse files
Support removing trends widgets without cogwheel (#1)
Some users are reporting a version of the trends widget without the cogwheel link. We can try to identify this version (also the other version, but let’s keep the old code for that) using the “trending with…” links under some trends, which, if they exist, identify the source via some URL parameters.
1 parent a914ad8 commit d11a8bf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

hide-twitter-trends.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* then look at some of the neighboring DOM trying to reduce false positives.
77
* (The many class names on the elements don’t look stable,
88
* so we only match on element names, hoping they’re more reliable.)
9+
*
10+
* There is also a version of the Trends widget without the cogwheel.
11+
* We can try to identify this using the “trending with…” links,
12+
* which, if they exist, have &src=trend_click in the URL.
13+
* (The actual trends themselves aren’t links at all, but divs with event handlers.)
14+
* If none of the trends are “trending with” something, we’re out of luck.
915
*/
1016
function removeTrends() {
1117
for (let trends of document.querySelectorAll('a[href="/settings/trends"]')) {
@@ -32,6 +38,29 @@ function removeTrends() {
3238
trends = parent;
3339
trends.remove();
3440
}
41+
for (let trends of document.querySelectorAll('a[href*="&src=trend_click"]')) {
42+
if (!document.body.contains(trends)) {
43+
// we already removed the parent trends widget
44+
continue;
45+
}
46+
if (trends.closest('article')) {
47+
// trends link in a tweet
48+
continue;
49+
}
50+
trends = trends.closest('section');
51+
if (!trends) {
52+
// (unclear if this can happen)
53+
continue;
54+
}
55+
if (trends.firstElementChild.tagName !== 'H1') {
56+
// (unclear if this can happen)
57+
continue;
58+
}
59+
let parent;
60+
while ((parent = trends.parentElement).childElementCount == 1)
61+
trends = parent;
62+
trends.remove();
63+
}
3564
}
3665

3766
setTimeout(removeTrends, 3 * 1000);

0 commit comments

Comments
 (0)