summaryrefslogtreecommitdiff
path: root/ext/bg/js/settings2/settings-display-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-08 17:52:25 -0500
committerGitHub <noreply@github.com>2021-02-08 17:52:25 -0500
commitace6e92d55b32c08b5a0a2b19bdd8974d53aa552 (patch)
tree0b3a8c239e69daf57b8f1f823fe1b95614d6bfb0 /ext/bg/js/settings2/settings-display-controller.js
parent9f5cbaac5ac38ac1106eb8392b1ceb5ef841225e (diff)
Update chrome://extensions/shortcuts URLs to be clickable (#1342)
Diffstat (limited to 'ext/bg/js/settings2/settings-display-controller.js')
-rw-r--r--ext/bg/js/settings2/settings-display-controller.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/ext/bg/js/settings2/settings-display-controller.js b/ext/bg/js/settings2/settings-display-controller.js
index 75c147f2..9d3e5459 100644
--- a/ext/bg/js/settings2/settings-display-controller.js
+++ b/ext/bg/js/settings2/settings-display-controller.js
@@ -54,6 +54,14 @@ class SettingsDisplayController {
node.addEventListener('keydown', onInputTabActionKeyDown, false);
}
+ const onSpecialUrlLinkClick = this._onSpecialUrlLinkClick.bind(this);
+ const onSpecialUrlLinkMouseDown = this._onSpecialUrlLinkMouseDown.bind(this);
+ for (const node of document.querySelectorAll('[data-special-url]')) {
+ node.addEventListener('click', onSpecialUrlLinkClick, false);
+ node.addEventListener('auxclick', onSpecialUrlLinkClick, false);
+ node.addEventListener('mousedown', onSpecialUrlLinkMouseDown, false);
+ }
+
for (const node of document.querySelectorAll('.defer-load-iframe')) {
this._setupDeferLoadIframe(node);
}
@@ -220,6 +228,57 @@ class SettingsDisplayController {
}
}
+ _onSpecialUrlLinkClick(e) {
+ switch (e.button) {
+ case 0:
+ case 1:
+ e.preventDefault();
+ this._createTab(e.currentTarget.dataset.specialUrl, true);
+ break;
+ }
+ }
+
+ _onSpecialUrlLinkMouseDown(e) {
+ switch (e.button) {
+ case 0:
+ case 1:
+ e.preventDefault();
+ break;
+ }
+ }
+
+ async _createTab(url, useOpener) {
+ let openerTabId;
+ if (useOpener) {
+ try {
+ const tab = await new Promise((resolve, reject) => {
+ chrome.tabs.getCurrent((result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(result);
+ }
+ });
+ });
+ openerTabId = tab.id;
+ } catch (e) {
+ // NOP
+ }
+ }
+
+ return await new Promise((resolve, reject) => {
+ chrome.tabs.create({url, openerTabId}, (tab2) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(tab2);
+ }
+ });
+ });
+ }
+
_updateScrollTarget() {
const hash = window.location.hash;
if (!hash.startsWith('#!')) { return; }