-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
145 lines (132 loc) · 4.82 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
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
let item,
item2,
item3,
item4,
item5,
item6,
related,
homeFeed,
scrollContainer,
homeFeedIronSelector,
youtubeLogo,
shorts,
commentSection,
liveChat,
ad;
async function doSomething() {
item = await chrome.storage.sync.get(["homeFeed"]);
item2 = await chrome.storage.sync.get(["recommendedVideos"]);
item3 = await chrome.storage.sync.get(["shorts"]);
item4 = await chrome.storage.sync.get(["commentSection"]);
item5 = await chrome.storage.sync.get(["liveChat"]);
item6 = await chrome.storage.sync.get(["ad"]);
}
doSomething();
youtubeLogo = document.getElementById("logo-icon");
youtubeLogo.addEventListener("click", () => {
window.location = "https://www.youtube.com/";
});
chrome.runtime.onMessage.addListener(gotMessage);
function gotMessage(message, sender, sendResponse) {
performAction(message.text);
}
async function performAction(message) {
if (message === "hideRecommendedVideos") {
related = document.getElementById("related");
related.style["visibility"] = "hidden";
} else if (message === "showRecommendedVideos") {
related = document.getElementById("related");
related.style["visibility"] = "visible";
} else if (message === "hideHomeFeed") {
homeFeed = document.getElementById("contents");
scrollContainer = document.getElementById("chips-wrapper");
homeFeed.style["display"] = "none";
scrollContainer.style["display"] = "none";
} else if (message === "showHomeFeed") {
homeFeed = document.getElementById("contents");
scrollContainer = document.getElementById("chips-wrapper");
homeFeed.style["display"] = "";
scrollContainer.style["display"] = "";
} else if (message === "hideShorts") {
shorts = document.querySelector("[title='Shorts']");
shorts.style["display"] = "none";
} else if (message === "showShorts") {
shorts = document.querySelector("[title='Shorts']");
shorts.style["display"] = "";
} else if (message == "showCommentSection") {
commentSection = document.getElementById("comments");
commentSection.style["display"] = "";
} else if (message == "hideCommentSection") {
commentSection = document.getElementById("comments");
commentSection.style["display"] = "none";
} else if (message == "hideLiveChat") {
liveChat = document.getElementById("chat");
liveChat.style["display"] = "none";
} else if (message == "showLiveChat") {
liveChat = document.getElementById("chat");
liveChat.style["display"] = "";
} else if (message == "showAd") {
ad = document.querySelectorAll("#masthead-ad");
ad.forEach(function (ele) {
ele.style["display"] = "";
});
} else if (message == "hideAd") {
ad = document.querySelectorAll("#masthead-ad");
ad.forEach(function (ele) {
ele.style["display"] = "none";
});
} else if (message === "hello") {
await doSomething();
// declaring variables to store each element
related = document.getElementById("related");
homeFeed = document.getElementById("contents");
scrollContainer = document.getElementById("chips-wrapper");
youtubeLogo = document.querySelector("#logo-icon");
shorts = document.querySelector("[title='Shorts']");
commentSection = document.getElementById("comments");
liveChat = document.getElementById("chat");
ad = document.querySelectorAll("#masthead-ad");
// check if the page has a homefeed
if (item && item.homeFeed && homeFeed !== null) {
// set the visibility of home page to hidden
homeFeed.style["display"] = "none";
homeFeed = null;
}
if (item && item.homeFeed && scrollContainer !== null) {
// set the display property of scroll container to none
scrollContainer.style["display"] = "none";
scrollContainer = null;
}
if (youtubeLogo !== null) {
youtubeLogo.innerHTML =
'<img src = "https://raw.githubusercontent.com/KishanKokal/Untrapped/89f2281ee2f6f936d9eb831d065ab436cd785675/untrapped.svg" width = "100px"></img>';
youtubeLogo = null;
}
// check if the page has a side bar
if (item2 && item2.recommendedVideos && related !== null) {
// set the visibility of side bar to hidden
related.style["visibility"] = "hidden";
related = null;
}
if (item4 && item4.commentSection && commentSection !== null) {
commentSection.style["display"] = "none";
commentSection = null;
}
if (item5 && item5.liveChat && liveChat !== null) {
liveChat.style["display"] = "none";
liveChat = null;
}
if (item6 && item6.ad && ad !== null) {
ad = document.querySelectorAll("#masthead-ad");
ad.forEach(function (ele) {
ele.style["display"] = "none";
});
}
if (item3 && item3.shorts && shorts !== null) {
// set the visibility of side bar to hidden
shorts.style["display"] = "none";
shorts = null;
}
}
}
performAction("hello");