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

Function init

pages/options.js:30–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28};
29
30export async function init() {
31 await Settings.onLoaded();
32
33 const shortcutLabel = document.querySelector("#shortcut-to-save-all");
34 shortcutLabel.textContent = KeyboardUtils.platform == "Mac" ? "Cmd-Enter" : "Ctrl-Enter";
35
36 const saveButton = document.querySelector("#save");
37
38 const onUpdated = () => {
39 maintainNewTabUrlView();
40 saveButton.disabled = false;
41 saveButton.textContent = "Save changes";
42 };
43
44 for (const el of document.querySelectorAll("input, textarea")) {
45 // We want to immediately enable the save button when a setting is changed, so we want to use
46 // the HTML element's "input" event here rather than the "change" event.
47 el.addEventListener("input", () => onUpdated());
48 el.addEventListener("blur", () => {
49 showValidationErrors();
50 });
51 }
52
53 saveButton.addEventListener("click", () => saveOptions());
54
55 getOptionEl("filterLinkHints").addEventListener(
56 "click",
57 () => maintainLinkHintsView(),
58 );
59
60 document.querySelector("#download-backup").addEventListener(
61 "mousedown",
62 () => onDownloadBackupClicked(),
63 true,
64 );
65 document.querySelector("#upload-backup").addEventListener(
66 "change",
67 () => onUploadBackupClicked(),
68 );
69
70 for (const el of document.querySelectorAll(".reset-link a")) {
71 el.addEventListener("click", (event) => {
72 resetInputValue(event);
73 showValidationErrors();
74 onUpdated();
75 });
76 }
77
78 globalThis.onbeforeunload = () => {
79 if (!saveButton.disabled) {
80 return "You have unsaved changes to options.";
81 }
82 };
83
84 document.addEventListener("keydown", (event) => {
85 // Firefox on Mac doesn't pass ctrl-enter to our page because MacOS Sequoia treats it as a
86 // shortcut for right click; typing it shows a context menu. So, we also allow cmd-enter to save
87 // all options. Note that ctrl-enter still works on Chrome for some reason.

Callers 1

options.jsFile · 0.70

Calls 10

saveOptionsFunction · 0.85
getOptionElFunction · 0.85
maintainLinkHintsViewFunction · 0.85
onDownloadBackupClickedFunction · 0.85
onUploadBackupClickedFunction · 0.85
resetInputValueFunction · 0.85
setFormFromSettingsFunction · 0.85
onUpdatedFunction · 0.70
showValidationErrorsFunction · 0.70
initMethod · 0.45

Tested by

no test coverage detected