aboutsummaryrefslogtreecommitdiffstats
path: root/js/vapi-contextmenu.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vapi-contextmenu.js')
-rw-r--r--js/vapi-contextmenu.js182
1 files changed, 91 insertions, 91 deletions
diff --git a/js/vapi-contextmenu.js b/js/vapi-contextmenu.js
index 271e30b..9e20b23 100644
--- a/js/vapi-contextmenu.js
+++ b/js/vapi-contextmenu.js
@@ -2,7 +2,7 @@
ηMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors
- Copyright (C) 2019-2020 Alessio Vanni
+ Copyright (C) 2019-2022 Alessio Vanni
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
- Home: https://libregit.spks.xyz/heckyel/ematrix
+ Home: https://gitlab.com/vannilla/ematrix
uMatrix Home: https://github.com/gorhill/uMatrix
*/
@@ -27,73 +27,73 @@
(function () {
vAPI.contextMenu = {
- contextMap: {
+ contextMap: {
frame: 'inFrame',
link: 'onLink',
image: 'onImage',
audio: 'onAudio',
video: 'onVideo',
editable: 'onEditableArea'
- }
+ }
};
vAPI.contextMenu.displayMenuItem = function ({target}) {
- let doc = target.ownerDocument;
- let gContextMenu = doc.defaultView.gContextMenu;
- if (!gContextMenu.browser) {
+ let doc = target.ownerDocument;
+ let gContextMenu = doc.defaultView.gContextMenu;
+ if (!gContextMenu.browser) {
return;
- }
+ }
- let menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
- let currentURI = gContextMenu.browser.currentURI;
+ let menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
+ let currentURI = gContextMenu.browser.currentURI;
- // https://github.com/chrisaljoudi/uBlock/issues/105
- // TODO: Should the element picker works on any kind of pages?
- if (!currentURI.schemeIs('http') && !currentURI.schemeIs('https')) {
+ // https://github.com/chrisaljoudi/uBlock/issues/105
+ // TODO: Should the element picker works on any kind of pages?
+ if (!currentURI.schemeIs('http') && !currentURI.schemeIs('https')) {
menuitem.setAttribute('hidden', true);
return;
- }
+ }
- let ctx = vAPI.contextMenu.contexts;
+ let ctx = vAPI.contextMenu.contexts;
- if (!ctx) {
+ if (!ctx) {
menuitem.setAttribute('hidden', false);
return;
- }
+ }
- let ctxMap = vAPI.contextMenu.contextMap;
+ let ctxMap = vAPI.contextMenu.contextMap;
- for (let context of ctx) {
+ for (let context of ctx) {
if (context === 'page'
- && !gContextMenu.onLink
- && !gContextMenu.onImage
- && !gContextMenu.onEditableArea
- && !gContextMenu.inFrame
- && !gContextMenu.onVideo
- && !gContextMenu.onAudio) {
- menuitem.setAttribute('hidden', false);
- return;
+ && !gContextMenu.onLink
+ && !gContextMenu.onImage
+ && !gContextMenu.onEditableArea
+ && !gContextMenu.inFrame
+ && !gContextMenu.onVideo
+ && !gContextMenu.onAudio) {
+ menuitem.setAttribute('hidden', false);
+ return;
}
if (ctxMap.hasOwnProperty(context)
- && gContextMenu[ctxMap[context]]) {
- menuitem.setAttribute('hidden', false);
- return;
+ && gContextMenu[ctxMap[context]]) {
+ menuitem.setAttribute('hidden', false);
+ return;
}
- }
+ }
- menuitem.setAttribute('hidden', true);
+ menuitem.setAttribute('hidden', true);
};
vAPI.contextMenu.register = (function () {
- let register = function (doc) {
+ let register = function (doc) {
if (!this.menuItemId) {
- return;
+ return;
}
// Already installed?
if (doc.getElementById(this.menuItemId) !== null) {
- return;
+ return;
}
let contextMenu = doc.getElementById('contentAreaContextMenu');
@@ -107,106 +107,106 @@
contextMenu.addEventListener('popupshowing', this.displayMenuItem);
contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator'));
- };
-
- let registerSafely = function (doc, tryCount) {
- // https://github.com/gorhill/uBlock/issues/906
- // Be sure document.readyState is 'complete': it could happen
- // at launch time that we are called by
- // vAPI.contextMenu.create() directly before the environment
- // is properly initialized.
+ };
+
+ let registerSafely = function (doc, tryCount) {
+ // https://github.com/gorhill/uBlock/issues/906
+ // Be sure document.readyState is 'complete': it could happen
+ // at launch time that we are called by
+ // vAPI.contextMenu.create() directly before the environment
+ // is properly initialized.
if (doc.readyState === 'complete') {
- register.call(this, doc);
- return;
+ register.call(this, doc);
+ return;
}
if (typeof tryCount !== 'number') {
- tryCount = 0;
+ tryCount = 0;
}
tryCount += 1;
if (tryCount < 8) {
- vAPI.setTimeout(registerSafely.bind(this, doc, tryCount), 200);
+ vAPI.setTimeout(registerSafely.bind(this, doc, tryCount), 200);
}
- };
+ };
- return registerSafely;
+ return registerSafely;
})();
vAPI.contextMenu.unregister = function (doc) {
- if (!this.menuItemId) {
+ if (!this.menuItemId) {
return;
- }
+ }
- let menuitem = doc.getElementById(this.menuItemId);
- if (menuitem === null) {
+ let menuitem = doc.getElementById(this.menuItemId);
+ if (menuitem === null) {
return;
- }
+ }
- let contextMenu = menuitem.parentNode;
- menuitem.removeEventListener('command', this.onCommand);
- contextMenu.removeEventListener('popupshowing', this.displayMenuItem);
- contextMenu.removeChild(menuitem);
+ let contextMenu = menuitem.parentNode;
+ menuitem.removeEventListener('command', this.onCommand);
+ contextMenu.removeEventListener('popupshowing', this.displayMenuItem);
+ contextMenu.removeChild(menuitem);
};
vAPI.contextMenu.create = function (details, callback) {
- this.menuItemId = details.id;
- this.menuLabel = details.title;
- this.contexts = details.contexts;
+ this.menuItemId = details.id;
+ this.menuLabel = details.title;
+ this.contexts = details.contexts;
- if (Array.isArray(this.contexts) && this.contexts.length) {
+ if (Array.isArray(this.contexts) && this.contexts.length) {
this.contexts = this.contexts.indexOf('all') === -1
- ? this.contexts
- : null;
- } else {
+ ? this.contexts
+ : null;
+ } else {
// default in Chrome
this.contexts = ['page'];
- }
+ }
- this.onCommand = function () {
+ this.onCommand = function () {
let gContextMenu = vAPI.browser.getOwnerWindow(this).gContextMenu;
let details = {
- menuItemId: this.id
+ menuItemId: this.id
};
if (gContextMenu.inFrame) {
- details.tagName = 'iframe';
- // Probably won't work with e10s
- // eMatrix: doesn't matter ;)
- details.frameUrl = gContextMenu.focusedWindow.location.href;
+ details.tagName = 'iframe';
+ // Probably won't work with e10s
+ // eMatrix: doesn't matter ;)
+ details.frameUrl = gContextMenu.focusedWindow.location.href;
} else if (gContextMenu.onImage) {
- details.tagName = 'img';
- details.srcUrl = gContextMenu.mediaURL;
+ details.tagName = 'img';
+ details.srcUrl = gContextMenu.mediaURL;
} else if (gContextMenu.onAudio) {
- details.tagName = 'audio';
- details.srcUrl = gContextMenu.mediaURL;
+ details.tagName = 'audio';
+ details.srcUrl = gContextMenu.mediaURL;
} else if (gContextMenu.onVideo) {
- details.tagName = 'video';
- details.srcUrl = gContextMenu.mediaURL;
+ details.tagName = 'video';
+ details.srcUrl = gContextMenu.mediaURL;
} else if (gContextMenu.onLink) {
- details.tagName = 'a';
- details.linkUrl = gContextMenu.linkURL;
+ details.tagName = 'a';
+ details.linkUrl = gContextMenu.linkURL;
}
callback(details, {
- id: vAPI.tabs.manager.tabIdFromTarget(gContextMenu.browser),
- url: gContextMenu.browser.currentURI.asciiSpec
+ id: vAPI.tabs.manager.tabIdFromTarget(gContextMenu.browser),
+ url: gContextMenu.browser.currentURI.asciiSpec
});
- };
+ };
- for (let win of vAPI.window.getWindows()) {
+ for (let win of vAPI.window.getWindows()) {
this.register(win.document);
- }
+ }
};
vAPI.contextMenu.remove = function () {
- for (let win of vAPI.window.getWindows()) {
+ for (let win of vAPI.window.getWindows()) {
this.unregister(win.document);
- }
+ }
- this.menuItemId = null;
- this.menuLabel = null;
- this.contexts = null;
- this.onCommand = null;
+ this.menuItemId = null;
+ this.menuLabel = null;
+ this.contexts = null;
+ this.onCommand = null;
};
})();