-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
91 lines (83 loc) · 3.66 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
// Listen for messages from the background script or popup script
chrome.storage.local.get("extensionPaused", function (data) {
const extensionPaused = data.extensionPaused;
if (!extensionPaused && typeof window !== "undefined" && window.location) {
let currentUrl = window.location.href;
try {
function getDomain(url) {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
const parsedUrl = new URL(url);
return parsedUrl.hostname;
}
} catch (error) {
console.error("Error parsing URL:", error);
}
// Get current selected group
chrome.storage.local.get("selectedGroup", function (data) {
const selectedGroup = data.selectedGroup;
chrome.storage.local.get(["links", "groups"], function (data) {
const savedLinks = data.links || [];
savedLinks.forEach(function (item) {
if (
getDomain(item.link) == getDomain(currentUrl) &&
selectedGroup === item.group
) {
const init = function () {
var blackScreen = document.createElement("div");
blackScreen.id = "blackScreen";
blackScreen.style.position = "fixed";
blackScreen.style.top = "0";
blackScreen.style.left = "0";
blackScreen.style.width = "100%";
blackScreen.style.height = "100%";
blackScreen.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
blackScreen.style.zIndex = "9999";
blackScreen.style.display = "flex";
blackScreen.style.flexDirection = "column";
blackScreen.style.justifyContent = "center";
blackScreen.style.alignItems = "center";
var message = document.createElement("div");
message.id = "blackScreenMessage";
message.style.color = "white";
message.style.fontSize = "48px";
message.textContent = "Website isn't allowed in this group";
message.style.textAlign = "center";
message.style.marginBottom = "20px";
const button = document.createElement("button");
button.textContent = "Pause";
button.style.padding = "10px 20px"; // Add padding for better appearance
button.style.fontSize = "18px"; // Increase font size
button.style.border = "none"; // Remove border
button.style.borderRadius = "5px"; // Add border radius
button.style.backgroundColor = "red"; // Change background color
button.style.color = "white"; // Change text color
button.style.cursor = "pointer"; // Add pointer cursor
// Listener to hover button
button.addEventListener("mouseenter", function () {
button.style.backgroundColor = "darkred";
});
// Reset background color on mouse leave
button.addEventListener("mouseleave", function () {
button.style.backgroundColor = "red";
});
// Add event listener to handle button click
button.addEventListener("click", function () {
// Send message to background script to toggle the extension state
chrome.runtime.sendMessage({ action: "pauseExtension" });
});
blackScreen.appendChild(message);
blackScreen.appendChild(button);
document.body.appendChild(blackScreen);
};
init();
}
});
});
});
// here
} else {
console.log("Content script is paused");
}
});