-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
111 lines (101 loc) · 4.06 KB
/
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
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
let activate = document.querySelector("#activate")
let handleDiv = document.querySelector(".size-handler")
let min = document.querySelector(".min")
let max = document.querySelector(".max")
let guide = document.querySelector(".btn-txt")
const pxtoVh = (pxh) => {
const vh100 = document.documentElement.clientHeight
return (100/vh100)*pxh
}
const pxtoVw = (pxw) => {
const vw100 = document.documentElement.clientWidth
return (100/vw100)*pxw
}
chrome.storage.sync.get("isActive", async ({isActive}) => {
if(!isActive) {
activate.innerHTML = "Resize"
activate.style.backgroundColor = "rgb(26, 255, 26)"
return handleDiv.style.display = "none"
} else {
activate.innerHTML = "Return"
activate.style.backgroundColor = "red"
guide.innerHTML = "Fullscreen mode is active"
handleDiv.style.display = "flex"
}
})
const onActivate = async () => {
chrome.storage.sync.get("isActive", async ({isActive}) => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const tabId = tab.id;
const url = tab.url.toString()
if(url.includes("https://www.youtube.com")) {
if(isActive) {
chrome.scripting.executeScript(
{
target: {tabId: tabId, allFrames: true},
func: () => window.location.reload(true)
}
)
isActive = false
return chrome.storage.sync.set({ isActive })
} else {
const addIframe = async () => {
let Str = `<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Youtube Resized</title> </head> <body> <iframe src=${document.URL.replace("?v=", "/").replace("watch","embed").replace("&", "?")} frameborder="0" style="width: 100vw; height: 100vh" class="myiframe"> </iframe> </body></html>`
var newHTML = document.open("text/html", "replace");
newHTML.write(Str);
newHTML.close();
}
chrome.scripting.executeScript(
{
target: {tabId: tabId, allFrames: true},
func: addIframe,
}
)
activate.innerHTML = "Return"
activate.style.backgroundColor = "red"
handleDiv.style.display = "flex"
guide.innerHTML = "Fullscreen mode is active"
isActive = true
return chrome.storage.sync.set({ isActive })
}
}
else {
return alert("This extension is only for youtube!!!")
}
})
}
activate.addEventListener("click", onActivate)
min.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const tabId = tab.id;
const onMax = async () => {
let iframe = document.querySelector(".myiframe")
if(iframe) {
iframe.style.width = `${(parseInt(iframe.style.width.replace("vw","")) - 5)}vw`
iframe.style.height = `${(parseInt(iframe.style.height.replace("vw","")) - 5)}vh`
}
}
chrome.scripting.executeScript(
{
target: {tabId: tabId, allFrames: true},
func: onMax
}
)
})
max.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const tabId = tab.id;
const onMax = async () => {
let iframe = document.querySelector(".myiframe")
if(iframe) {
iframe.style.width = `${(parseInt(iframe.style.width.replace("vw","")) + 5)}vw`
iframe.style.height = `${(parseInt(iframe.style.height.replace("vw","")) + 5)}vh`
}
}
chrome.scripting.executeScript(
{
target: {tabId: tabId, allFrames: true},
func: onMax
}
)
})