Add: trimHash method

This commit is contained in:
eight 2020-02-01 05:18:02 +08:00
parent c1ea0d1a7d
commit a026ccfb0b
2 changed files with 19 additions and 3 deletions

View File

@ -258,6 +258,14 @@ const APPLY = (() => {
case 'updateCount':
updateCount();
break;
case 'trimHash':
if (IS_OWN_PAGE) {
// FIXME: currently we only do this in our own page. Is it safe to do
// it on all pages?
history.pushState({preUrl: location.href}, null, ' ');
}
break;
}
}

View File

@ -1,7 +1,7 @@
/* exported getActiveTab onTabReady stringAsRegExp getTabRealURL openURL
getStyleWithNoCode tryRegExp sessionStorageHash download deepEqual
closeCurrentTab capitalize CHROME_HAS_BORDER_BUG */
/* global promisify */
/* global promisify msg */
'use strict';
const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]);
@ -248,9 +248,17 @@ function openURL(options) {
if (!tab) {
return getActiveTab().then(maybeReplace);
}
// update url if only hash is different
// update url if only hash is different?
if (tab.url !== url && tab.url.split('#')[0] === url.split('#')[0]) {
return activateTab(tab, {url, index});
if (url.includes('#')) {
return activateTab(tab, {url, index});
} else {
// we can't update URL directly since it refresh the page
return Promise.all([
activateTab(tab, {index}),
msg.sendTab(tab.id, {method: 'trimHash'}).catch(console.warn)
]);
}
}
return activateTab(tab, {index});
});