-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
33 lines (28 loc) · 788 Bytes
/
popup.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
let button = document.getElementById("remove-button");
function YouTubeGetID(url) {
var ID = "";
url = url
.replace(/(>|<)/gi, "")
.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
if (url[2] !== undefined) {
ID = url[2].split(/[^0-9a-z_\-]/i);
ID = ID[0];
} else {
ID = url;
}
return ID;
}
button.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const youtubeID = YouTubeGetID(tab.url);
if (typeof youtubeID === "string") {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: removeYoutubeTitle,
});
}
});
function removeYoutubeTitle() {
document.title = "a";
document.querySelector("#title h1 yt-formatted-string").innerText = "";
}