mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
this fixes #507
This commit is contained in:
parent
f1cf2036fc
commit
528354f594
@ -294,6 +294,7 @@ vAPI.tabs.open = function(details) {
|
||||
if ( typeof targetURL !== 'string' || targetURL === '' ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// extension pages
|
||||
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
|
||||
targetURL = vAPI.getURL(targetURL);
|
||||
@ -370,15 +371,33 @@ vAPI.tabs.open = function(details) {
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.tabs.query({ url: targetURL }, function(tabs) {
|
||||
// https://developer.chrome.com/extensions/tabs#method-query
|
||||
// "Note that fragment identifiers are not matched."
|
||||
// It's a lie, fragment identifiers ARE matched. So we need to remove the
|
||||
// fragment.
|
||||
var targetURLWithoutHash = targetURL;
|
||||
var pos = targetURL.indexOf('#');
|
||||
if ( pos !== -1 ) {
|
||||
targetURLWithoutHash = targetURL.slice(0, pos);
|
||||
}
|
||||
|
||||
chrome.tabs.query({ url: targetURLWithoutHash }, function(tabs) {
|
||||
var tab = tabs[0];
|
||||
if ( tab ) {
|
||||
chrome.tabs.update(tab.id, { active: true }, function(tab) {
|
||||
chrome.windows.update(tab.windowId, { focused: true });
|
||||
});
|
||||
} else {
|
||||
if ( !tab ) {
|
||||
wrapper();
|
||||
return;
|
||||
}
|
||||
|
||||
var _details = {
|
||||
active: true,
|
||||
url: undefined
|
||||
};
|
||||
if ( targetURL !== tab.url ) {
|
||||
_details.url = targetURL;
|
||||
}
|
||||
chrome.tabs.update(tab.id, _details, function(tab) {
|
||||
chrome.windows.update(tab.windowId, { focused: true });
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -669,7 +669,17 @@ vAPI.tabs.open = function(details) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Or simply .equals if we care about the fragment
|
||||
if ( URI.equalsExceptRef(browser.currentURI) === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.select(tab);
|
||||
|
||||
// Update URL if fragment is different
|
||||
if ( URI.equals(browser.currentURI) === false ) {
|
||||
browser.loadURI(URI.asciiSpec);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -688,6 +688,10 @@ var onLogBufferRead = function(response) {
|
||||
allTabIdsToken = response.tabIdsToken;
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/507
|
||||
// Ensure tab selector is in sync with URL hash
|
||||
pageSelectorFromURLHash();
|
||||
|
||||
renderLogEntries(response);
|
||||
|
||||
if ( rowVoided ) {
|
||||
@ -719,26 +723,55 @@ var readLogBuffer = function() {
|
||||
/******************************************************************************/
|
||||
|
||||
var pageSelectorChanged = function() {
|
||||
var style = uDom.nodeFromId('tabFilterer');
|
||||
var tabClass = uDom.nodeFromId('pageSelector').value;
|
||||
var sheet = style.sheet;
|
||||
while ( sheet.cssRules.length !== 0 ) {
|
||||
sheet.deleteRule(0);
|
||||
}
|
||||
if ( tabClass !== '' ) {
|
||||
sheet.insertRule(
|
||||
'#netInspector tr:not(.' + tabClass + ') { display: none; }',
|
||||
0
|
||||
);
|
||||
}
|
||||
uDom('.needtab').toggleClass(
|
||||
'disabled',
|
||||
tabClass === '' || tabClass === 'tab_bts'
|
||||
);
|
||||
window.location.replace('#' + uDom.nodeFromId('pageSelector').value);
|
||||
pageSelectorFromURLHash();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var pageSelectorFromURLHash = (function() {
|
||||
var lastHash = '';
|
||||
|
||||
return function() {
|
||||
var hash = window.location.hash;
|
||||
if ( hash === lastHash ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tabClass = hash.slice(1);
|
||||
var select = uDom.nodeFromId('pageSelector');
|
||||
var option = select.querySelector('option[value="' + tabClass + '"]');
|
||||
if ( option === null ) {
|
||||
hash = window.location.hash = '';
|
||||
tabClass = '';
|
||||
option = select.options[0];
|
||||
}
|
||||
|
||||
lastHash = hash;
|
||||
|
||||
select.selectedIndex = option.index;
|
||||
select.value = option.value;
|
||||
|
||||
var style = uDom.nodeFromId('tabFilterer');
|
||||
var sheet = style.sheet;
|
||||
while ( sheet.cssRules.length !== 0 ) {
|
||||
sheet.deleteRule(0);
|
||||
}
|
||||
if ( tabClass !== '' ) {
|
||||
sheet.insertRule(
|
||||
'#netInspector tr:not(.' + tabClass + ') { display: none; }',
|
||||
0
|
||||
);
|
||||
}
|
||||
uDom('.needtab').toggleClass(
|
||||
'disabled',
|
||||
tabClass === '' || tabClass === 'tab_bts'
|
||||
);
|
||||
};
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var reloadTab = function() {
|
||||
var tabClass = uDom.nodeFromId('pageSelector').value;
|
||||
var tabId = tabIdFromClassName(tabClass);
|
||||
@ -1720,25 +1753,21 @@ var popupManager = (function() {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
uDom.onLoad(function() {
|
||||
readLogBuffer();
|
||||
readLogBuffer();
|
||||
|
||||
uDom('#pageSelector').on('change', pageSelectorChanged);
|
||||
uDom('#refresh').on('click', reloadTab);
|
||||
uDom('#showdom').on('click', toggleInspectors);
|
||||
uDom('#pageSelector').on('change', pageSelectorChanged);
|
||||
uDom('#refresh').on('click', reloadTab);
|
||||
uDom('#showdom').on('click', toggleInspectors);
|
||||
|
||||
uDom('#compactViewToggler').on('click', toggleCompactView);
|
||||
uDom('#clean').on('click', cleanBuffer);
|
||||
uDom('#clear').on('click', clearBuffer);
|
||||
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
||||
uDom('#netInspector table').on('click', 'tr.canMtx > td:nth-of-type(2)', popupManager.toggleOn);
|
||||
uDom('#netInspector').on('click', 'tr.canLookup > td:nth-of-type(3)', reverseLookupManager.toggleOn);
|
||||
uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(4)', netFilteringManager.toggleOn);
|
||||
uDom('#compactViewToggler').on('click', toggleCompactView);
|
||||
uDom('#clean').on('click', cleanBuffer);
|
||||
uDom('#clear').on('click', clearBuffer);
|
||||
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
||||
uDom('#netInspector table').on('click', 'tr.canMtx > td:nth-of-type(2)', popupManager.toggleOn);
|
||||
uDom('#netInspector').on('click', 'tr.canLookup > td:nth-of-type(3)', reverseLookupManager.toggleOn);
|
||||
uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(4)', netFilteringManager.toggleOn);
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/404
|
||||
// Ensure page state is in sync with the state of its various widgets.
|
||||
pageSelectorChanged();
|
||||
});
|
||||
window.addEventListener('hashchange', pageSelectorFromURLHash);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -433,6 +433,15 @@ var renderPopup = function() {
|
||||
}
|
||||
uDom.nodeFromId('total-blocked').textContent = text;
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/507
|
||||
// Convenience: open the logger with current tab automatically selected
|
||||
if ( popupData.tabId ) {
|
||||
uDom.nodeFromSelector('.statName > a[href^="logger-ui.html"]').setAttribute(
|
||||
'href',
|
||||
'logger-ui.html#tab_' + popupData.tabId
|
||||
);
|
||||
}
|
||||
|
||||
// This will collate all domains, touched or not
|
||||
renderPrivacyExposure();
|
||||
|
||||
@ -825,33 +834,32 @@ var onHideTooltip = function() {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Make menu only when popup html is fully loaded
|
||||
// Popup DOM is assumed to be loaded at this point -- because this script
|
||||
// is loaded after everything else..
|
||||
|
||||
uDom.onLoad(function () {
|
||||
// If there's no tab id specified in the query string,
|
||||
// it will default to current tab.
|
||||
var tabId = null;
|
||||
// If there's no tab id specified in the query string,
|
||||
// it will default to current tab.
|
||||
var tabId = null;
|
||||
|
||||
// Extract the tab id of the page this popup is for
|
||||
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
||||
if ( matches && matches.length === 2 ) {
|
||||
tabId = matches[1];
|
||||
}
|
||||
getPopupData(tabId);
|
||||
// Extract the tab id of the page this popup is for
|
||||
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
||||
if ( matches && matches.length === 2 ) {
|
||||
tabId = matches[1];
|
||||
}
|
||||
getPopupData(tabId);
|
||||
|
||||
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
||||
uDom('#gotoPick').on('click', gotoPick);
|
||||
uDom('a[href]').on('click', gotoURL);
|
||||
uDom('h2').on('click', toggleFirewallPane);
|
||||
uDom('#refresh').on('click', reloadTab);
|
||||
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
|
||||
uDom('#saveRules').on('click', saveFirewallRules);
|
||||
uDom('#revertRules').on('click', revertFirewallRules);
|
||||
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
|
||||
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
||||
uDom('#gotoPick').on('click', gotoPick);
|
||||
uDom('a[href]').on('click', gotoURL);
|
||||
uDom('h2').on('click', toggleFirewallPane);
|
||||
uDom('#refresh').on('click', reloadTab);
|
||||
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
|
||||
uDom('#saveRules').on('click', saveFirewallRules);
|
||||
uDom('#revertRules').on('click', revertFirewallRules);
|
||||
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
|
||||
|
||||
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
|
||||
.on('mouseleave', '[data-tip]', onHideTooltip);
|
||||
});
|
||||
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
|
||||
.on('mouseleave', '[data-tip]', onHideTooltip);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user