Skip to content

Commit e883790

Browse files
committed
add removing new video show, add message while the script is disabled
1 parent dee18e1 commit e883790

File tree

3 files changed

+159
-9
lines changed

3 files changed

+159
-9
lines changed

content.js

Lines changed: 141 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@ const observeAndRemoveElements = () => {
1010
for (let mutation of mutationsList) {
1111
for (let node of mutation.addedNodes) {
1212
if (node instanceof HTMLElement) {
13-
if (node.matches("#shorts-container, ytd-rich-grid-renderer")) {
13+
if (node.id == "columns") {
14+
console.log("trouvé !")
15+
removeElement("#columns #secondary")
16+
}
17+
if (node.matches('ytd-rich-grid-renderer')) {
18+
removeElement('ytd-rich-grid-renderer')
19+
console.log("start custom texte")
20+
const y = document.querySelector('ytd-two-column-browse-results-renderer')
21+
const t = document.createElement('h1')
22+
t.style.textAlign = "center";
23+
t.style.width = "100%";
24+
t.style.color = "#fff";
25+
t.style.fontSize = '40px';
26+
chrome.storage.sync.get(['removeYtdBrowse', 'msg'], (result) => {
27+
t.innerHTML = `${result.msg}`
28+
})
29+
y.append(t)
30+
}
31+
if (node.matches("#shorts-container, ytd-rich-grid-renderer, ytd-watch-next-secondary-results-renderer #items,#columns #secondary")) {
1432
node.remove()
1533
}
1634
}
@@ -21,11 +39,39 @@ const observeAndRemoveElements = () => {
2139
observer.observe(document.body, { childList: true, subtree: true });
2240
};
2341

24-
window.addEventListener("load", () => {
42+
window.addEventListener("load", async () => {
43+
console.log("loaded !")
44+
const script = document.createElement("script")
45+
const src = await chrome.runtime.getURL("external-script.js")
46+
script.src = src
47+
console.log(script)
48+
document.querySelector("body").append(script);
49+
50+
async function yes() {
51+
document.querySelector("#alerteboxforyoutubedisabled").remove()
52+
}
53+
async function no() {
54+
55+
}
56+
2557
chrome.storage.sync.get(['removeYtdBrowse', 'msg'], (result) => {
2658
if (result.removeYtdBrowse === true) {
27-
removeElement("#shorts-container");
28-
removeElement("ytd-rich-grid-renderer");
59+
console.log("start observeur")
60+
observeAndRemoveElements();
61+
console.log("start selctor")
62+
if (document.querySelector("#shorts-container")) {
63+
removeElement("#shorts-container");
64+
}
65+
if (document.querySelector("ytd-watch-next-secondary-results-renderer #items")) {
66+
removeElement("ytd-watch-next-secondary-results-renderer #items");
67+
}
68+
if (document.querySelector("ytd-rich-grid-renderer")) {
69+
removeElement("ytd-rich-grid-renderer");
70+
}
71+
if (document.querySelector("#columns #secondary")) {
72+
removeElement("#columns #secondary")
73+
}
74+
console.log("start custom texte")
2975
const y = document.querySelector('ytd-two-column-browse-results-renderer')
3076
const t = document.createElement('h1')
3177
t.style.textAlign = "center";
@@ -34,9 +80,97 @@ window.addEventListener("load", () => {
3480
t.style.fontSize = '40px';
3581
t.innerHTML = `${result.msg}`
3682
y.append(t)
37-
observeAndRemoveElements();
3883
} else if (result.removeYtdBrowse === false) {
39-
84+
console.log("create alerte box")
85+
const styled = document.createElement("style")
86+
styled.innerHTML = `
87+
/* CSS */
88+
.button-3 {
89+
appearance: none;
90+
background-color: #2ea44f;
91+
border: 1px solid rgba(27, 31, 35, .15);
92+
border-radius: 6px;
93+
box-shadow: rgba(27, 31, 35, .1) 0 1px 0;
94+
box-sizing: border-box;
95+
color: #fff;
96+
cursor: pointer;
97+
display: inline-block;
98+
font-family: -apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
99+
font-size: 14px;
100+
font-weight: 600;
101+
line-height: 20px;
102+
padding: 6px 16px;
103+
position: relative;
104+
text-align: center;
105+
text-decoration: none;
106+
user-select: none;
107+
-webkit-user-select: none;
108+
touch-action: manipulation;
109+
vertical-align: middle;
110+
white-space: nowrap;
111+
}
112+
113+
.button-3:focus:not(:focus-visible):not(.focus-visible) {
114+
box-shadow: none;
115+
outline: none;
116+
}
117+
118+
.button-3:hover {
119+
background-color: #2c974b;
120+
}
121+
122+
.button-3:focus {
123+
box-shadow: rgba(46, 164, 79, .4) 0 0 0 3px;
124+
outline: none;
125+
}
126+
127+
.button-3:disabled {
128+
background-color: #94d3a2;
129+
border-color: rgba(27, 31, 35, .1);
130+
color: rgba(255, 255, 255, .8);
131+
cursor: default;
132+
}
133+
134+
.button-3:active {
135+
background-color: #298e46;
136+
box-shadow: rgba(20, 70, 32, .2) 0 1px 0 inset;
137+
}
138+
`
139+
document.querySelector("head").append(styled)
140+
const newalertebox = document.createElement("div")
141+
newalertebox.id = "alerteboxforyoutubedisabled"
142+
newalertebox.style.width = "100vw"
143+
newalertebox.style.height = "100vh"
144+
newalertebox.style.display = "flex"
145+
newalertebox.style.justifyContent = "center"
146+
newalertebox.style.alignItems = "center"
147+
newalertebox.style.position = "fixed"
148+
newalertebox.style.top = "0"
149+
newalertebox.style.bottom = "0"
150+
newalertebox.style.right = "0"
151+
newalertebox.style.left = "0"
152+
newalertebox.style.backgroundColor = "#000"
153+
newalertebox.style.zIndex = "10000"
154+
document.querySelector("body").append(newalertebox)
155+
const newbox = document.createElement("div")
156+
newbox.id = "alerteboxforyoutubedisabledbox"
157+
newbox.style.display = "flex"
158+
newbox.style.justifyContent = "center"
159+
newbox.style.alignItems = "center"
160+
newbox.style.flexDirection = "column"
161+
newbox.style.gap = "5px"
162+
newbox.innerHTML = `
163+
<h1 style="color: #fff;">Are you sur to acces youtube ?</h1>
164+
<button id="yesclickplease" onclick="yes()" class="button-3" role="button">YES</button>
165+
<button id="noclickplease" onclick="no()" style="background-color: red;" class="button-3" role="button">NO</button>
166+
`
167+
document.querySelector("#alerteboxforyoutubedisabled").append(newbox)
168+
const all = document.querySelector("#yesclickplease")
169+
const allno = document.querySelector("#noclickplease")
170+
171+
all.onclick = (async () => {window.yes()})
172+
allno.onclick = (async () => {window.no()})
173+
40174
}
41175
});
42-
});
176+
});

external-script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
window.yes = async function() {
2+
document.querySelector("#alerteboxforyoutubedisabled").remove();
3+
};
4+
5+
window.no = async function() {
6+
console.log("remove")
7+
chrome.storage.sync.set({ 'removeYtdBrowse': true });
8+
console.log("restart")
9+
location.href = location.href
10+
};

manifest.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "disable youtube",
4-
"version": "0.0.3",
4+
"version": "0.0.4",
55
"description": "an extention to delete youtube home page and youtube short",
66
"permissions": [
77
"activeTab",
@@ -10,7 +10,13 @@
1010
"content_scripts": [
1111
{
1212
"matches": ["*://www.youtube.com/*"],
13-
"js": ["content.js"]
13+
"js": ["content.js", "external-script.js"]
14+
}
15+
],
16+
"web_accessible_resources": [
17+
{
18+
"resources": ["external-script.js"],
19+
"matches": ["<all_urls>"]
1420
}
1521
],
1622
"action": {

0 commit comments

Comments
 (0)