MCPcopy
hub / github.com/philc/vimium / init

Function init

pages/action.js:9–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8const ActionPage = {
9 async init() {
10 // Is it possible for the current tab's URL to change while this action popup is open?
11 const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
12 const activeTab = tabs[0];
13 this.tabUrl = activeTab.url;
14
15 const hideUI = () => {
16 document.querySelector("#dialog-body").style.display = "none";
17 document.querySelector("footer").style.display = "none";
18 };
19
20 // In Firefox, prompt the user if they haven't enabled the "all hosts" permission. Vimium needs
21 // this permission to work correctly, and as of 2023-11-06, Firefox does not grant this
22 // permission without user consent, and doesn't make it clear that the user needs to do
23 // anything. See #4348 for discussion, and https://stackoverflow.com/q/76083327 for
24 // implementation notes.
25 const permission = { origins: ["<all_urls>"] };
26 if (bgUtils.isFirefox()) {
27 const hasAllHostsPermission = await browser.permissions.contains(permission);
28 if (!hasAllHostsPermission) {
29 hideUI();
30 document.querySelector("#grant-hosts-permission").addEventListener("click", async (e) => {
31 browser.permissions.request(permission);
32 // We close the action page because if the user clicks on this button once, clicks "deny"
33 // on the browser's permissions dialog, and then clicks on the button a second time, the
34 // browser permissions dialog will now be shown *under* the action page!
35 globalThis.close();
36 });
37 document.querySelector("#firefox-missing-permissions-error").style.display = "block";
38 return;
39 }
40 }
41
42 if (!await this.isVimiumInstalledInTab(activeTab.id)) {
43 hideUI();
44 document.querySelector("#not-enabled-error").style.display = "block";
45 return;
46 }
47
48 document.querySelector("#optionsLink").href = chrome.runtime.getURL("pages/options.html");
49
50 const saveButton = document.querySelector("#save");
51 saveButton.addEventListener("click", (e) => this.onSave());
52
53 document.querySelector("#cancel").addEventListener("click", () => globalThis.close());
54
55 const onUpdated = () => {
56 saveButton.disabled = false;
57 saveButton.textContent = "Save changes";
58 this.syncEnabledKeysCaption();
59 this.showValidationErrors();
60 };
61
62 const defaultPatternForNewRules = this.generateDefaultPattern(this.tabUrl);
63
64 document.querySelector("#add-first-rule").addEventListener(
65 "click",
66 () => {

Callers

nothing calls this directly

Calls 6

hideUIFunction · 0.85
getMethod · 0.80
matchMethod · 0.80
onUpdatedFunction · 0.70
initMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected