-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
31 lines (28 loc) · 1.05 KB
/
contentScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function addTextToTweets() {
const tweets = document.querySelectorAll('article');
tweets.forEach((tweet) => {
if (!tweet.classList.contains('processed')) {
const textElement = document.createElement('div');
textElement.innerText = 'TEXT';
textElement.style.position = 'absolute';
textElement.style.top = '0';
textElement.style.right = '0';
tweet.appendChild(textElement);
tweet.classList.add('processed');
// Find the nested anchor tags
const anchorTags = tweet.querySelectorAll('a');
anchorTags.forEach((anchorTag) => {
// Check if the href attribute matches the structure "/username/status/ID"
const href = anchorTag.getAttribute('href');
if (href && href.match(/^\/[^\/]+\/status\/\d+$/)) {
console.log(href);
tweet.remove()
}
});
}
});
}
// Run the function initially
addTextToTweets();
// Run the function every time new tweets are loaded
new MutationObserver(addTextToTweets).observe(document.body, { childList: true, subtree: true });