diff --git a/background/background.js b/background/background.js index 1bcef0db..c51a375b 100644 --- a/background/background.js +++ b/background/background.js @@ -178,7 +178,7 @@ browserCommands = { openURL({url: 'manage.html'}); }, openOptions() { - openURL({url: 'manage.html?#stylus-options'}); + openURL({url: 'manage.html#stylus-options'}); }, styleDisableAll(info) { prefs.set('disableAll', info ? info.checked : !prefs.get('disableAll')); diff --git a/js/messaging.js b/js/messaging.js index d809d1bb..d6652777 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -1,6 +1,7 @@ /* exported getActiveTab onTabReady stringAsRegExp getTabRealURL openURL getStyleWithNoCode tryRegExp sessionStorageHash download deepEqual closeCurrentTab capitalize */ +/* global prefs */ 'use strict'; const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]); @@ -225,7 +226,7 @@ function openURL({ url = url.replace(/^(opera|vivaldi)/, 'chrome'); const editMatch = /edit\.html/.test(url); // ignore filtered manager URLs with params & edit URLs created from popup on manager page - const manageMatch = !editMatch ? /manage\.html(\?#stylus-options)?$/.test(url) : null; + const manageMatch = !editMatch ? /manage\.html(#stylus-options)?$/.test(url) : null; // FF doesn't handle moz-extension:// URLs (bug) // FF decodes %2F in encoded parameters (bug) // API doesn't handle the hash-fragment part @@ -243,9 +244,10 @@ function openURL({ function maybeSwitch(tabs = []) { const urlWithSlash = url + '/'; const urlFF = FIREFOX && url.replace(/%2F/g, '/'); - const urlOptions = manageMatch ? URLS.ownOrigin + 'manage.html?#stylus-options' : null; + const urlOptions = manageMatch ? URLS.ownOrigin + 'manage.html#stylus-options' : null; const urlManage = manageMatch ? URLS.ownOrigin + 'manage.html' : null; - let tab = tabs.find(({url: u}) => u === url || u === urlFF || u === urlWithSlash || u === urlOptions || u === urlManage); + const tab = tabs.find(({url: u}) => u === url || u === urlFF || u === urlWithSlash || + u === urlOptions || u === urlManage); if (!tab && prefs.get('openEditInWindow') && chrome.windows && editMatch) { chrome.windows.create( Object.assign({ @@ -264,8 +266,7 @@ function openURL({ } getActiveTab() .then(currentTab => { - const closePopup = tab && FIREFOX && currentTab.windowId !== tab.windowId ? false : true; - if (closePopup) { + if (!(tab && FIREFOX && currentTab.windowId !== tab.windowId)) { chrome.runtime.sendMessage({ 'name': 'popup', 'data': 'close-popup' diff --git a/manage/import-export.js b/manage/import-export.js index 327314c0..3815de8d 100644 --- a/manage/import-export.js +++ b/manage/import-export.js @@ -7,8 +7,12 @@ const STYLISH_DUMP_FILE_EXT = '.txt'; const STYLUS_BACKUP_FILE_EXT = '.json'; onDOMready().then(() => { - $('#file-all-styles').onclick = exportToFile; - $('#unfile-all-styles').onclick = () => { + $('#file-all-styles').onclick = event => { + event.preventDefault(); + exportToFile(); + }; + $('#unfile-all-styles').onclick = event => { + event.preventDefault(); importFromFile({fileTypeFilter: STYLUS_BACKUP_FILE_EXT}); }; diff --git a/manage/manage.js b/manage/manage.js index 83221f16..ed9ff34c 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -84,7 +84,8 @@ function onRuntimeMessage(msg) { function initGlobalEvents() { installed = $('#installed'); installed.onclick = handleEvent.entryClicked; - $('#manage-options-button').onclick = () => history.replaceState('', document.title, location.href + '?#stylus-options'); + $('#manage-options-button').onclick = () => + history.replaceState('', document.title, location.href + '#stylus-options'); { const btn = $('#manage-shortcuts-button'); btn.onclick = btn.onclick || (() => openURL({url: URLS.configureCommands})); @@ -719,7 +720,7 @@ function embedOptions() { function removeOptions() { const options = $('#stylus-embedded-options'); - if (options) options.remove() + if (options) options.remove(); } // wait for possible filter params to be removed @@ -746,11 +747,11 @@ onDOMready().then(() => { function toggleOptions(msg) { if (msg === 'options-open' && location.hash !== '#stylus-options') { - history.replaceState('', document.title, location.href + '?#stylus-options'); + history.replaceState('', document.title, location.href + '#stylus-options'); } else if (msg === 'options-close' && location.hash === '#stylus-options') { history.replaceState('', document.title, location.origin + location.pathname); } -}; +} if (location.hash === '#stylus-options') embedOptions(); diff --git a/options/options.js b/options/options.js index e8a5d2de..6feb02c4 100644 --- a/options/options.js +++ b/options/options.js @@ -40,8 +40,8 @@ if (FIREFOX && 'update' in (chrome.commands || {})) { // actions $('#options-close-icon').onclick = () => { - window.top.history.replaceState('', window.top.document.title, window.top.location.origin + window.top.location.pathname); -} + top.history.replaceState('', top.document.title, top.location.origin + top.location.pathname); +}; document.onclick = e => { const target = e.target.closest('[data-cmd]'); @@ -299,9 +299,9 @@ function customizeHotkeys() { window.onkeydown = event => { if (event.keyCode === 27) { - window.top.history.replaceState('', window.top.document.title, window.top.location.origin + window.top.location.pathname); + top.history.replaceState('', top.document.title, top.location.origin + top.location.pathname); } -} +}; // FF is slow to allow focus, particularly when launched via manager button setTimeout(() => { diff --git a/popup/popup.js b/popup/popup.js index f328ff6c..85622269 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -106,7 +106,7 @@ function initPopup() { }); $('#popup-options-button').onclick = () => { - API.openURL({url: 'manage.html?#stylus-options'}); + API.openURL({url: 'manage.html#stylus-options'}); window.close(); }; diff --git a/sync/import-export-dropbox.js b/sync/import-export-dropbox.js index 222df852..f72c711a 100644 --- a/sync/import-export-dropbox.js +++ b/sync/import-export-dropbox.js @@ -48,7 +48,8 @@ function uploadFileDropbox(client, stylesText) { return client.filesUpload({path: '/' + DROPBOX_FILE, contents: stylesText}); } -$('#sync-dropbox-export').onclick = () => { +$('#sync-dropbox-export').onclick = event => { + event.preventDefault(); const mode = localStorage.installType; const title = t('syncDropboxStyles'); const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed'); @@ -122,7 +123,8 @@ $('#sync-dropbox-export').onclick = () => { }); }; -$('#sync-dropbox-import').onclick = () => { +$('#sync-dropbox-import').onclick = event => { + event.preventDefault(); const mode = localStorage.installType; const title = t('retrieveDropboxSync'); const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed');