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 === '' ) {
|
if ( typeof targetURL !== 'string' || targetURL === '' ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extension pages
|
// extension pages
|
||||||
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
|
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
|
||||||
targetURL = vAPI.getURL(targetURL);
|
targetURL = vAPI.getURL(targetURL);
|
||||||
@ -370,15 +371,33 @@ vAPI.tabs.open = function(details) {
|
|||||||
return;
|
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];
|
var tab = tabs[0];
|
||||||
if ( tab ) {
|
if ( !tab ) {
|
||||||
chrome.tabs.update(tab.id, { active: true }, function(tab) {
|
|
||||||
chrome.windows.update(tab.windowId, { focused: true });
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
wrapper();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Or simply .equals if we care about the fragment
|
||||||
|
if ( URI.equalsExceptRef(browser.currentURI) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this.select(tab);
|
this.select(tab);
|
||||||
|
|
||||||
|
// Update URL if fragment is different
|
||||||
|
if ( URI.equals(browser.currentURI) === false ) {
|
||||||
|
browser.loadURI(URI.asciiSpec);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,6 +688,10 @@ var onLogBufferRead = function(response) {
|
|||||||
allTabIdsToken = response.tabIdsToken;
|
allTabIdsToken = response.tabIdsToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/507
|
||||||
|
// Ensure tab selector is in sync with URL hash
|
||||||
|
pageSelectorFromURLHash();
|
||||||
|
|
||||||
renderLogEntries(response);
|
renderLogEntries(response);
|
||||||
|
|
||||||
if ( rowVoided ) {
|
if ( rowVoided ) {
|
||||||
@ -719,26 +723,55 @@ var readLogBuffer = function() {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var pageSelectorChanged = function() {
|
var pageSelectorChanged = function() {
|
||||||
var style = uDom.nodeFromId('tabFilterer');
|
window.location.replace('#' + uDom.nodeFromId('pageSelector').value);
|
||||||
var tabClass = uDom.nodeFromId('pageSelector').value;
|
pageSelectorFromURLHash();
|
||||||
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 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 reloadTab = function() {
|
||||||
var tabClass = uDom.nodeFromId('pageSelector').value;
|
var tabClass = uDom.nodeFromId('pageSelector').value;
|
||||||
var tabId = tabIdFromClassName(tabClass);
|
var tabId = tabIdFromClassName(tabClass);
|
||||||
@ -1720,25 +1753,21 @@ var popupManager = (function() {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
uDom.onLoad(function() {
|
readLogBuffer();
|
||||||
readLogBuffer();
|
|
||||||
|
|
||||||
uDom('#pageSelector').on('change', pageSelectorChanged);
|
uDom('#pageSelector').on('change', pageSelectorChanged);
|
||||||
uDom('#refresh').on('click', reloadTab);
|
uDom('#refresh').on('click', reloadTab);
|
||||||
uDom('#showdom').on('click', toggleInspectors);
|
uDom('#showdom').on('click', toggleInspectors);
|
||||||
|
|
||||||
uDom('#compactViewToggler').on('click', toggleCompactView);
|
uDom('#compactViewToggler').on('click', toggleCompactView);
|
||||||
uDom('#clean').on('click', cleanBuffer);
|
uDom('#clean').on('click', cleanBuffer);
|
||||||
uDom('#clear').on('click', clearBuffer);
|
uDom('#clear').on('click', clearBuffer);
|
||||||
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
||||||
uDom('#netInspector table').on('click', 'tr.canMtx > td:nth-of-type(2)', popupManager.toggleOn);
|
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.canLookup > td:nth-of-type(3)', reverseLookupManager.toggleOn);
|
||||||
uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(4)', netFilteringManager.toggleOn);
|
uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(4)', netFilteringManager.toggleOn);
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/404
|
window.addEventListener('hashchange', pageSelectorFromURLHash);
|
||||||
// Ensure page state is in sync with the state of its various widgets.
|
|
||||||
pageSelectorChanged();
|
|
||||||
});
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -433,6 +433,15 @@ var renderPopup = function() {
|
|||||||
}
|
}
|
||||||
uDom.nodeFromId('total-blocked').textContent = text;
|
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
|
// This will collate all domains, touched or not
|
||||||
renderPrivacyExposure();
|
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,
|
||||||
// If there's no tab id specified in the query string,
|
// it will default to current tab.
|
||||||
// it will default to current tab.
|
var tabId = null;
|
||||||
var tabId = null;
|
|
||||||
|
|
||||||
// Extract the tab id of the page this popup is for
|
// Extract the tab id of the page this popup is for
|
||||||
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
||||||
if ( matches && matches.length === 2 ) {
|
if ( matches && matches.length === 2 ) {
|
||||||
tabId = matches[1];
|
tabId = matches[1];
|
||||||
}
|
}
|
||||||
getPopupData(tabId);
|
getPopupData(tabId);
|
||||||
|
|
||||||
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
||||||
uDom('#gotoPick').on('click', gotoPick);
|
uDom('#gotoPick').on('click', gotoPick);
|
||||||
uDom('a[href]').on('click', gotoURL);
|
uDom('a[href]').on('click', gotoURL);
|
||||||
uDom('h2').on('click', toggleFirewallPane);
|
uDom('h2').on('click', toggleFirewallPane);
|
||||||
uDom('#refresh').on('click', reloadTab);
|
uDom('#refresh').on('click', reloadTab);
|
||||||
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
|
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
|
||||||
uDom('#saveRules').on('click', saveFirewallRules);
|
uDom('#saveRules').on('click', saveFirewallRules);
|
||||||
uDom('#revertRules').on('click', revertFirewallRules);
|
uDom('#revertRules').on('click', revertFirewallRules);
|
||||||
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
|
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
|
||||||
|
|
||||||
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
|
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
|
||||||
.on('mouseleave', '[data-tip]', onHideTooltip);
|
.on('mouseleave', '[data-tip]', onHideTooltip);
|
||||||
});
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user