mirror of https://github.com/gorhill/uBlock.git
Add a "Block Element" context menu command to the Firefox Network tab (to match the one in the Inspector tab)
This commit is contained in:
parent
128e7bf9ff
commit
c98ff26709
|
@ -2019,7 +2019,7 @@ vAPI.contextMenu.registerForWebInspector = function(eventName, toolbox, panel) {
|
||||||
selectedNodeFront = selectedNodeFront.parentNode();
|
selectedNodeFront = selectedNodeFront.parentNode();
|
||||||
}
|
}
|
||||||
if (selectedNodeFront) {
|
if (selectedNodeFront) {
|
||||||
selectedNodeFront.getUniqueSelector().then(selector => µBlock.elementPickerExec(vAPI.tabs.getTabId(panel.browser), selector));
|
selectedNodeFront.getUniqueSelector().then(selector => µBlock.elementPickerExec(vAPI.tabs.getTabId(panel.browser), { type: 'element', value: selector}));
|
||||||
|
|
||||||
// Turn off 3D view, if it's turned on.
|
// Turn off 3D view, if it's turned on.
|
||||||
if (tiltButton && tiltButton.checked) {
|
if (tiltButton && tiltButton.checked) {
|
||||||
|
@ -2032,6 +2032,24 @@ vAPI.contextMenu.registerForWebInspector = function(eventName, toolbox, panel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vAPI.contextMenu.registerForNetMonitor = function(eventName, toolbox, panel) {
|
||||||
|
var doc = panel.panelWin.document;
|
||||||
|
var menuPopup = doc.getElementById("network-request-popup");
|
||||||
|
var insertBeforeMenuItem = doc.getElementById("request-menu-context-separator");
|
||||||
|
|
||||||
|
if (menuPopup && insertBeforeMenuItem) {
|
||||||
|
var menuitem = vAPI.contextMenu.createContextMenuItem(doc);
|
||||||
|
menuitem.addEventListener('command', function() {
|
||||||
|
var selectedRequest = panel.panelWin.NetMonitorView.RequestsMenu.selectedAttachment;
|
||||||
|
if (selectedRequest) {
|
||||||
|
µBlock.elementPickerExec(vAPI.tabs.getTabId(toolbox.target.tab), { type: 'url', value: selectedRequest.url });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menuPopup.insertBefore(menuitem, insertBeforeMenuItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.contextMenu.create = function(details, callback) {
|
vAPI.contextMenu.create = function(details, callback) {
|
||||||
|
@ -2086,6 +2104,7 @@ vAPI.contextMenu.create = function(details, callback) {
|
||||||
|
|
||||||
if (this.gDevTools) {
|
if (this.gDevTools) {
|
||||||
this.gDevTools.on("inspector-ready", this.registerForWebInspector);
|
this.gDevTools.on("inspector-ready", this.registerForWebInspector);
|
||||||
|
this.gDevTools.on("netmonitor-ready", this.registerForNetMonitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2103,6 +2122,7 @@ vAPI.contextMenu.remove = function() {
|
||||||
|
|
||||||
if (!vAPI.fennec && this.gDevTools) {
|
if (!vAPI.fennec && this.gDevTools) {
|
||||||
this.gDevTools.off("inspector-ready", this.registerForWebInspector);
|
this.gDevTools.off("inspector-ready", this.registerForWebInspector);
|
||||||
|
this.gDevTools.off("netmonitor-ready", this.registerForNetMonitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menuItemId = null;
|
this.menuItemId = null;
|
||||||
|
|
|
@ -138,7 +138,7 @@ return {
|
||||||
contextMenuClientX: -1,
|
contextMenuClientX: -1,
|
||||||
contextMenuClientY: -1,
|
contextMenuClientY: -1,
|
||||||
|
|
||||||
epickerTargetElementSelector: null,
|
epickerTarget: null,
|
||||||
epickerEprom: null,
|
epickerEprom: null,
|
||||||
|
|
||||||
// so that I don't have to care for last comma
|
// so that I don't have to care for last comma
|
||||||
|
|
|
@ -326,13 +326,18 @@ var netFilterFromElement = function(elem, out) {
|
||||||
if ( src.length === 0 ) {
|
if ( src.length === 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Remove fragment
|
|
||||||
var pos = src.indexOf('#');
|
netFilterFromUrl(src, out);
|
||||||
if ( pos !== -1 ) {
|
|
||||||
src = src.slice(0, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter = src.replace(/^https?:\/\//, '||');
|
var netFilterFromUrl = function(url, out) {
|
||||||
|
// Remove fragment
|
||||||
|
var pos = url.indexOf('#');
|
||||||
|
if ( pos !== -1 ) {
|
||||||
|
url = url.slice(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
var filter = url.replace(/^https?:\/\//, '||');
|
||||||
|
|
||||||
// Anchor absolute filter to hostname
|
// Anchor absolute filter to hostname
|
||||||
out.push(filter);
|
out.push(filter);
|
||||||
|
@ -344,7 +349,7 @@ var netFilterFromElement = function(elem, out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suggest a filter which is a result of combining more than one URL.
|
// Suggest a filter which is a result of combining more than one URL.
|
||||||
netFilterFromUnion(src, out);
|
netFilterFromUnion(url, out);
|
||||||
};
|
};
|
||||||
|
|
||||||
var netFilterSources = {
|
var netFilterSources = {
|
||||||
|
@ -472,6 +477,14 @@ var filtersFromElement = function(elem) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var filtersFromUrl = function(url) {
|
||||||
|
netFilterCandidates.length = 0;
|
||||||
|
cosmeticFilterCandidates.length = 0;
|
||||||
|
netFilterFromUrl(url, netFilterCandidates);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
var elementsFromFilter = function(filter) {
|
var elementsFromFilter = function(filter) {
|
||||||
var out = [];
|
var out = [];
|
||||||
|
|
||||||
|
@ -874,20 +887,23 @@ var startPicker = function(details) {
|
||||||
|
|
||||||
highlightElements([], true);
|
highlightElements([], true);
|
||||||
|
|
||||||
var elem = null;
|
// If a target was provided, use it
|
||||||
|
if (details.target) {
|
||||||
// If a target element was provided, use it
|
if (details.target.type === 'element') {
|
||||||
if (details.targetElementSelector) {
|
filtersFromElement(document.querySelector(details.target.value));
|
||||||
elem = document.querySelector(details.targetElementSelector);
|
} else if (details.target.type === 'url') {
|
||||||
|
filtersFromUrl(details.target.value);
|
||||||
|
} else {
|
||||||
|
console.error('uBlock> unknown element picker target details type: %s', details.target.type);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Try using mouse position
|
// Try using mouse position
|
||||||
if (!elem && details.clientX !== -1) {
|
if (details.clientX !== -1) {
|
||||||
elem = elementFromPoint(details.clientX, details.clientY);
|
filtersFromElement(elementFromPoint(details.clientX, details.clientY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elem !== null) {
|
if (netFilterCandidates.length > 0 || cosmeticFilterCandidates.length > 0) {
|
||||||
filtersFromElement(elem);
|
|
||||||
showDialog();
|
showDialog();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -558,7 +558,7 @@ var onMessage = function(request, sender, callback) {
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
frameContent: this.responseText.replace(reStrings, replacer),
|
frameContent: this.responseText.replace(reStrings, replacer),
|
||||||
targetElementSelector: µb.epickerTargetElementSelector,
|
target: µb.epickerTarget,
|
||||||
clientX: µb.contextMenuClientX,
|
clientX: µb.contextMenuClientX,
|
||||||
clientY: µb.contextMenuClientY,
|
clientY: µb.contextMenuClientY,
|
||||||
eprom: µb.epickerEprom
|
eprom: µb.epickerEprom
|
||||||
|
|
|
@ -276,8 +276,8 @@ var matchWhitelistDirective = function(url, hostname, directive) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.elementPickerExec = function(tabId, targetElementSelector) {
|
µBlock.elementPickerExec = function(tabId, target) {
|
||||||
this.epickerTargetElementSelector = targetElementSelector;
|
this.epickerTarget = target;
|
||||||
vAPI.tabs.injectScript(tabId, { file: 'js/element-picker.js' });
|
vAPI.tabs.injectScript(tabId, { file: 'js/element-picker.js' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue