Repository navigation
Expand file tree
/
Copy pathguide.js
More file actions
51 lines (45 loc) · 1.64 KB
/
Copy pathguide.js
File metadata and controls
51 lines (45 loc) · 1.64 KB
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
(function () {
var params = new URLSearchParams(location.search);
var originTabId = params.get("tabId") ? parseInt(params.get("tabId"), 10) : null;
var statusEl = document.getElementById("status");
var openBtn = document.getElementById("open-settings");
var reloadBtn = document.getElementById("reload-file");
var extensionId = chrome.runtime.id;
var pollTimer = null;
function setStatus(allowed) {
if (allowed) {
statusEl.className = "status status-ok";
statusEl.textContent = "\u2705 Access enabled \u2014 you're all set!";
if (originTabId !== null) {
reloadBtn.hidden = false;
}
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
} else {
statusEl.className = "status status-pending";
statusEl.textContent = "Waiting for permission to be enabled\u2026";
reloadBtn.hidden = true;
}
}
function check() {
chrome.extension.isAllowedFileSchemeAccess(function (allowed) {
setStatus(allowed);
});
}
openBtn.addEventListener("click", function () {
chrome.tabs.create({ url: "chrome://extensions/?id=" + extensionId });
});
reloadBtn.addEventListener("click", function () {
if (originTabId === null) return;
chrome.tabs.reload(originTabId);
chrome.tabs.update(originTabId, { active: true });
});
check();
// Chrome doesn't fire an event when this permission changes, so poll
// lightly while the guide is open, and also re-check on focus (covers
// the common case of switching back from the chrome://extensions tab).
pollTimer = setInterval(check, 1500);
window.addEventListener("focus", check);
})();