-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
167 lines (145 loc) · 5.7 KB
/
content-script.js
File metadata and controls
167 lines (145 loc) · 5.7 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
let config = {
'views': false,
'explore': true,
'bookmarks': true,
'lists': true,
'messages': true,
'happening': true,
'whotofollow': true
}
let observer = new MutationObserver(callback);
function callback (mutations) {
console.log(config);
if (!config.views) {
const viewElems = document.querySelectorAll("[aria-label*='Views']");
for (const elem of viewElems) {
elem.parentNode.style.display = "none";
}
const analyticsElems = document.querySelectorAll("[aria-label*='View Tweet analytics']");
for (const elem of analyticsElems) {
elem.parentNode.style.display = "none";
}
const spanElems = document.evaluate("//span[text()='Views']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < spanElems.snapshotLength; i++) {
spanElems.snapshotItem(i).parentNode.parentNode.parentNode.parentNode.style.display = "none";
}
} else {
const viewElems = document.querySelectorAll("[aria-label*='Views']");
for (const elem of viewElems) {
elem.parentNode.style.display = "block";
}
const analyticsElems = document.querySelectorAll("[aria-label*='View Tweet analytics']");
for (const elem of analyticsElems) {
elem.parentNode.style.display = "block";
}
const spanElems = document.evaluate("//span[text()='Views']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < spanElems.snapshotLength; i++) {
spanElems.snapshotItem(i).parentNode.parentNode.parentNode.parentNode.style.display = "block";
}
}
const exploreElem = document.querySelector("[aria-label='Search and explore']");
if (exploreElem != null) {
if (!config.explore) {
exploreElem.style.display = "none";
} else {
exploreElem.style.display = "";
}
}
const bookmarkElem = document.querySelector("[aria-label='Bookmarks']");
if (bookmarkElem != null) {
if (!config.bookmarks) {
bookmarkElem.style.display = "none";
} else {
bookmarkElem.style.display = "";
}
}
const listsElem = document.querySelector("[aria-label='Lists']");
if (listsElem != null) {
if (!config.lists) {
listsElem.style.display = "none";
} else {
listsElem.style.display = "";
}
}
const messagesElem = document.querySelector("[aria-label='Direct Messages']");
if (messagesElem != null) {
if (!config.messages) {
messagesElem.style.display = "none";
} else {
messagesElem.style.display = "";
}
}
const happeningElem = document.querySelector("[aria-label='Timeline: Trending now']");
if (happeningElem != null) {
if (!config.happening) {
happeningElem.parentNode.parentNode.parentNode.style.display = "none";
} else {
happeningElem.parentNode.parentNode.parentNode.style.display = "";
}
}
const whotofollowElem = document.querySelector("[aria-label='Who to follow']");
if (whotofollowElem != null) {
if (!config.whotofollow) {
whotofollowElem.parentNode.parentNode.style.display = "none";
} else {
whotofollowElem.parentNode.parentNode.style.display = "";
}
}
}
observer.observe(document.getElementById("react-root"), {subtree: true, childList: true});
chrome.storage.local.get(['views', 'explore', 'bookmarks', 'lists', 'messages', 'happening', 'whotofollow'], function(result) {
config.views = result.views;
config.explore = result.explore;
config.bookmarks = result.bookmarks;
config.lists = result.lists;
config.messages = result.messages;
config.happening = result.happening;
config.whotofollow = result.whotofollow;
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.hideViews) {
config.views = !config.views;
chrome.storage.local.set({'views': config.views}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideExplore) {
config.explore = !config.explore;
chrome.storage.local.set({'explore': config.explore}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideBookmarks) {
config.bookmarks = !config.bookmarks;
chrome.storage.local.set({'bookmarks': config.bookmarks}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideLists) {
config.lists = !config.lists;
chrome.storage.local.set({'lists': config.lists}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideMessages) {
config.messages = !config.messages;
chrome.storage.local.set({'messages': config.messages}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideHappening) {
config.happening = !config.happening;
chrome.storage.local.set({'happening': config.happening}, function() {});
callback(null);
sendResponse({status: true});
}
if (request.hideWhoToFollow) {
config.whotofollow = !config.whotofollow;
chrome.storage.local.set({'whotofollow': config.whotofollow}, function() {});
callback(null);
sendResponse({status: true});
}
return true;
}
);