-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent_script.js
78 lines (65 loc) · 1.74 KB
/
content_script.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
//Deprecated??
console.log("Productivity Blocker Extension Loaded.");
const channel = new MessageChannel();
channel.port1.onmessage = e => {
if (e.data === "pong") {
console.log("Connection test successful!");
return;
}
console.log("Message recieved from frame: "+e.data);
};
async function doStuffs() {
const overrideTime = (await browser.storage.local.get()).override;
alert(overrideTime);
if (Date.now() < overrideTime) {
// alert("timeout: " + (Date.now() - overrideTime))
setTimeout(
doStuffs,
overrideTime - Date.now()
);
return;
}
if (location.origin.match(/youtube\.com/)) {
console.log(Date.now());
createFrame();
}
}
function createFrame() {
const frame = document.createElement('iframe');
frame.id = "productivity-blocker-frame";
frame.src = browser.runtime.getURL("redirect.html");
frame.style.zIndex = "10000";
frame.style.position = "absolute";
frame.style.left = "0";
frame.style.top = "0";
frame.style.width = "100vw";
frame.style.height = "100dvh"
// Test connection to iframe
frame.addEventListener("load", () => {
console.log("Testing connection...")
frame.contentWindow.postMessage("ping", "*", [
channel.port2,
]);
});
document.body.appendChild(frame);
}
function removeFrame() {
}
doStuffs();
// async function doStuffs() {
// const overrideTime = (await browser.storage.local.get()).override;
// alert(overrideTime);
// if (Date.now() < overrideTime) {
// // alert("timeout: " + (Date.now() - overrideTime))
// setTimeout(
// doStuffs,
// overrideTime - Date.now()
// );
// return;
// }
// if (location.origin.match(/youtube\.com/)) {
// console.log(Date.now());
// location.replace(browser.runtime.getURL("password-page.html?dir="+location));
// }
// }
// doStuffs();