mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Prevent popup panel to close when forcing a tab reload
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/672 Additionally, this commit add the ability to press F5 to force a reload while the popup panel is opened.
This commit is contained in:
parent
48347897ad
commit
066440534d
2 changed files with 40 additions and 21 deletions
|
@ -338,10 +338,10 @@ vAPI.Tabs = class {
|
|||
|
||||
get(tabId, callback) {
|
||||
if ( tabId === null ) {
|
||||
chrome.tabs.query(
|
||||
browser.tabs.query(
|
||||
{ active: true, currentWindow: true },
|
||||
tabs => {
|
||||
void chrome.runtime.lastError;
|
||||
void browser.runtime.lastError;
|
||||
callback(
|
||||
Array.isArray(tabs) && tabs.length !== 0
|
||||
? tabs[0]
|
||||
|
@ -358,8 +358,8 @@ vAPI.Tabs = class {
|
|||
return;
|
||||
}
|
||||
|
||||
chrome.tabs.get(tabId, function(tab) {
|
||||
void chrome.runtime.lastError;
|
||||
browser.tabs.get(tabId, function(tab) {
|
||||
void browser.runtime.lastError;
|
||||
callback(tab);
|
||||
});
|
||||
}
|
||||
|
@ -541,21 +541,21 @@ vAPI.Tabs = class {
|
|||
targetURL = vAPI.getURL(targetURL);
|
||||
}
|
||||
|
||||
chrome.tabs.update(tabId, { url: targetURL }, vAPI.resetLastError);
|
||||
browser.tabs.update(tabId, { url: targetURL }, vAPI.resetLastError);
|
||||
}
|
||||
|
||||
remove(tabId) {
|
||||
tabId = toChromiumTabId(tabId);
|
||||
if ( tabId === 0 ) { return; }
|
||||
|
||||
chrome.tabs.remove(tabId, vAPI.resetLastError);
|
||||
browser.tabs.remove(tabId, vAPI.resetLastError);
|
||||
}
|
||||
|
||||
reload(tabId, bypassCache = false) {
|
||||
tabId = toChromiumTabId(tabId);
|
||||
if ( tabId === 0 ) { return; }
|
||||
|
||||
chrome.tabs.reload(
|
||||
browser.tabs.reload(
|
||||
tabId,
|
||||
{ bypassCache: bypassCache === true },
|
||||
vAPI.resetLastError
|
||||
|
@ -566,26 +566,33 @@ vAPI.Tabs = class {
|
|||
tabId = toChromiumTabId(tabId);
|
||||
if ( tabId === 0 ) { return; }
|
||||
|
||||
chrome.tabs.update(tabId, { active: true }, function(tab) {
|
||||
void chrome.runtime.lastError;
|
||||
browser.tabs.update(tabId, { active: true }, function(tab) {
|
||||
void browser.runtime.lastError;
|
||||
if ( !tab ) { return; }
|
||||
if ( chrome.windows instanceof Object === false ) { return; }
|
||||
chrome.windows.update(tab.windowId, { focused: true });
|
||||
if ( browser.windows instanceof Object === false ) { return; }
|
||||
browser.windows.update(tab.windowId, { focused: true });
|
||||
});
|
||||
}
|
||||
|
||||
injectScript(tabId, details, callback) {
|
||||
const onScriptExecuted = function() {
|
||||
// https://code.google.com/p/chromium/issues/detail?id=410868#c8
|
||||
void chrome.runtime.lastError;
|
||||
void browser.runtime.lastError;
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback.apply(null, arguments);
|
||||
}
|
||||
};
|
||||
if ( tabId ) {
|
||||
chrome.tabs.executeScript(toChromiumTabId(tabId), details, onScriptExecuted);
|
||||
browser.tabs.executeScript(
|
||||
toChromiumTabId(tabId),
|
||||
details,
|
||||
onScriptExecuted
|
||||
);
|
||||
} else {
|
||||
chrome.tabs.executeScript(details, onScriptExecuted);
|
||||
browser.tabs.executeScript(
|
||||
details,
|
||||
onScriptExecuted
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
(function() {
|
||||
(( ) => {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -894,22 +894,35 @@ const reloadTab = function(ev) {
|
|||
{
|
||||
what: 'reloadTab',
|
||||
tabId: popupData.tabId,
|
||||
select: true,
|
||||
select: vAPI.webextFlavor.soup.has('mobile'),
|
||||
bypassCache: ev.ctrlKey || ev.metaKey || ev.shiftKey
|
||||
}
|
||||
);
|
||||
|
||||
// Polling will take care of refreshing the popup content
|
||||
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/748
|
||||
// User forces a reload, assume the popup has to be updated regardless if
|
||||
// there were changes or not.
|
||||
// User forces a reload, assume the popup has to be updated regardless
|
||||
// if there were changes or not.
|
||||
popupData.contentLastModified = -1;
|
||||
|
||||
// No need to wait to remove this.
|
||||
uDom('body').toggleClass('dirty', false);
|
||||
};
|
||||
|
||||
uDom('#refresh').on('click', reloadTab);
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/672
|
||||
document.addEventListener(
|
||||
'keydown',
|
||||
ev => {
|
||||
if ( ev.code !== 'F5' ) { return; }
|
||||
reloadTab(ev);
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
},
|
||||
{ capture: true }
|
||||
);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const toggleMinimize = function(ev) {
|
||||
|
@ -1121,7 +1134,7 @@ const onHideTooltip = function() {
|
|||
// Popup DOM is assumed to be loaded at this point -- because this script
|
||||
// is loaded after everything else..
|
||||
|
||||
(function() {
|
||||
(( ) => {
|
||||
// If there's no tab id specified in the query string,
|
||||
// it will default to current tab.
|
||||
let tabId = null;
|
||||
|
@ -1138,7 +1151,6 @@ uDom('#switch').on('click', toggleNetFilteringSwitch);
|
|||
uDom('#gotoZap').on('click', gotoZap);
|
||||
uDom('#gotoPick').on('click', gotoPick);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue