Syntax, hash only, and prevent empty hash
This commit is contained in:
parent
1a3161b62c
commit
a976c45a3a
|
@ -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'));
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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});
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue
Block a user