Skip to content

Commit c0f08ce

Browse files
committed
Support for focusing and/or highlighting elements when opening the options page.
1 parent 8848719 commit c0f08ce

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

src/bg/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,17 @@
338338
return this.policy;
339339
},
340340

341-
341+
openOptionsPage({tab, focus, hilite}) {
342+
let url = new URL(browser.runtime.getManifest().options_ui.page);
343+
if (tab !== undefined) {
344+
url.hash += `;tab-main-tabs=${tab}`;
345+
}
346+
let search = new URLSearchParams(url.search);
347+
if (focus) search.set("focus", focus);
348+
if (hilite) search.set("hilite", hilite);
349+
url.search = search;
350+
browser.tabs.create({url: url.toString() });
351+
},
342352

343353
async save(obj) {
344354
if (obj && obj.storage) {

src/ui/options.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,26 @@ document.querySelector("#version").textContent = _("Version",
203203
UI.updateSettings({policy});
204204
newSiteInput.value = "";
205205
sitesUI.render(policy.sites);
206-
sitesUI.highlight(site);
206+
sitesUI.hilite(site);
207207
sitesUI.onChange();
208208
}
209209
}, true);
210210
}
211211

212+
window.setTimeout(() => {
213+
// focus and/or hilite elements based on query string
214+
let params = new URLSearchParams(location.search);
215+
let el = key => {
216+
let selector = params.get(key);
217+
return selector && document.querySelector(selector);
218+
}
219+
220+
let focusElement = el("focus");
221+
if (focusElement) focusElement.focus();
222+
223+
let hiliteElement = el("hilite");
224+
if (hiliteElement) UI.hilite(hiliteElement);
225+
}, 1000);
212226

213227
// UTILITY FUNCTIONS
214228

src/ui/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ addEventListener("unload", e => {
107107
let handlers = {
108108
"options": e => {
109109
if (UA.mobile) { // Fenix fails on openOptionsPage
110-
browser.tabs.create({url: browser.runtime.getURL("/ui/options.html")});
110+
browser.tabs.create({url: browser.runtime.getManifest().options_ui.page});
111111
} else {
112112
browser.runtime.openOptionsPage();
113113
}

src/ui/ui.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ var UI = (() => {
185185
return input;
186186
},
187187

188+
hilite(el) {
189+
el.classList.add("hilite");
190+
window.setTimeout(() => {
191+
el.classList.remove("hilite");
192+
el.classList.add("hilite-end");
193+
el.scrollIntoView();
194+
window.setTimeout(() => {
195+
el.classList.remove("hilite-end");
196+
}, 1000)
197+
}, 50);
198+
},
199+
188200
createXSSChoiceManager(parent = "#xssChoices") {
189201
if (!UA.isMozilla) return;
190202
let choicesUI = document.querySelector(parent);
@@ -1115,20 +1127,12 @@ var UI = (() => {
11151127
}
11161128
}
11171129

1118-
highlight(key) {
1130+
hilite(key) {
11191131
key = Sites.toExternal(key);
11201132
for (let r of this.allSiteRows()) {
11211133
if (key === r.siteMatch) {
1122-
r.classList.add("hilite");
1134+
UI.hilite(r);
11231135
r.querySelector("input.preset:checked").focus();
1124-
window.setTimeout(() => {
1125-
r.classList.remove("hilite");
1126-
r.classList.add("hilite-end");
1127-
r.scrollIntoView();
1128-
window.setTimeout(() => {
1129-
r.classList.remove("hilite-end");
1130-
}, 1000)
1131-
}, 50);
11321136
break;
11331137
}
11341138
}

0 commit comments

Comments
 (0)