-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
62 lines (51 loc) · 2.06 KB
/
content.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This script runs in the context of Twitter web pages.
// It should find Twitter profiles and extract the necessary information.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "AdjustAukaat") {
console.log("running AdjustAukaat");
changeFontSizeForUserTweets(
message.data["handle"],
message.data["aukaat"],
);
}
});
function showHandlesInPopup() {
var tweets = document.querySelectorAll('article');
console.log("running showHandlesInPopup");
tweets.forEach(tweet => {
// console.log("running for each tweet");
let text = tweet.querySelector("div[data-testid='tweetText']")
let photo = tweet.querySelector("div[data-testid='tweetPhoto']")
let video = tweet.querySelector("div[data-testid='videoComponent']")
let handle = tweet.querySelector("a").getAttribute("href").substring(1);
// console.log(text);
console.log(handle);
chrome.runtime.sendMessage({ type: "AddHandleToPopup", data: handle });
});
}
function changeFontSizeForUserTweets(username, aukaat) {
var tweets = document.querySelectorAll('article');
console.log("running changeFontSize");
tweets.forEach(tweet => {
console.log(tweet);
console.log("running for each tweet");
let text = tweet.querySelector("div[data-testid='tweetText']")
let photo = tweet.querySelector("div[data-testid='tweetPhoto']")
let video = tweet.querySelector("div[data-testid='videoComponent']")
let handle = tweet.querySelector("a").getAttribute("href").substring(1);
console.log(handle);
console.log(username);
console.log(aukaat);
if (handle == username) {
text.style.fontSize = aukaat + "px";
}
});
}
var mObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length) {
showHandlesInPopup();
}
});
});
mObserver.observe(document.body, { childList: true, subtree: true });