Add: openManage API

This commit is contained in:
eight 2020-02-01 17:06:38 +08:00
parent 4ae74171cb
commit f86a678a1f
3 changed files with 22 additions and 12 deletions

View File

@ -73,7 +73,9 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
syncStop: sync.stop, syncStop: sync.stop,
syncNow: sync.syncNow, syncNow: sync.syncNow,
getSyncStatus: sync.getStatus, getSyncStatus: sync.getStatus,
syncLogin: sync.login syncLogin: sync.login,
openManage
}); });
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@ -178,12 +180,8 @@ chrome.runtime.onInstalled.addListener(({reason}) => {
// ************************************************************************* // *************************************************************************
// browser commands // browser commands
browserCommands = { browserCommands = {
openManage() { openManage,
openURL({url: 'manage.html', currentWindow: null}); openOptions: () => openManage({options: true}),
},
openOptions() {
openURL({url: 'manage.html#stylus-options', currentWindow: null});
},
styleDisableAll(info) { styleDisableAll(info) {
prefs.set('disableAll', info ? info.checked : !prefs.get('disableAll')); prefs.set('disableAll', info ? info.checked : !prefs.get('disableAll'));
}, },
@ -413,3 +411,14 @@ function openEditor(params) {
openURL({url}); openURL({url});
} }
} }
function openManage({options = false, search} = {}) {
let url = 'manage.html';
if (search) {
url += `?search=${encodeURIComponent(search)}`;
}
if (options) {
url += '#stylus-options';
}
return openURL({url, currentWindow: null});
}

View File

@ -53,7 +53,7 @@ document.onclick = e => {
switch (target.dataset.cmd) { switch (target.dataset.cmd) {
case 'open-manage': case 'open-manage':
openURL({url: 'manage.html'}); API.openManage();
break; break;
case 'check-updates': case 'check-updates':

View File

@ -102,7 +102,7 @@ function initPopup() {
}); });
$('#popup-options-button').onclick = () => { $('#popup-options-button').onclick = () => {
API.openURL({url: 'manage.html#stylus-options', currentWindow: null}); API.openManage({options: true});
window.close(); window.close();
}; };
@ -591,9 +591,10 @@ Object.assign(handleEvent, {
if (!this.eventHandled) { if (!this.eventHandled) {
// FIXME: this only works if popup is closed // FIXME: this only works if popup is closed
this.eventHandled = true; this.eventHandled = true;
this.dataset.href += event.shiftKey || event.button === 2 ? API.openManage({
'?search=' + encodeURIComponent(`url:${tabURL}`) : ''; search: event.shiftKey || event.button === 2 ?
API.openURL({url: this.dataset.href, currentWindow: null}); `url:${tabURL}` : null
});
window.close(); window.close();
} }
}, },