-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
41 lines (37 loc) · 1.35 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
document.addEventListener("DOMContentLoaded", function () {
const toggleButton = document.getElementById("toggle-html");
const status = document.getElementById("status");
toggleButton.addEventListener("click", async function () {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: toggleHTML
},
(result) => {
const isHidden = result[0].result;
status.textContent = isHidden ? "HTML désactivé" : "HTML activé";
toggleButton.textContent = isHidden ? "Activer HTML" : "Désactiver HTML";
}
);
});
function toggleHTML() {
const body = document.body;
const isHidden = body.style.display === "none";
body.style.display = isHidden ? "" : "none";
return !isHidden;
}
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: () => document.body.style.display === "none"
},
(result) => {
const isHidden = result[0].result;
status.textContent = isHidden ? "HTML désactivé" : "HTML activé";
toggleButton.textContent = isHidden ? "Activer HTML" : "Désactiver HTML";
}
);
});
});