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