give history log a navigatable #hash

This commit is contained in:
tophf 2022-02-20 00:59:08 +03:00
parent 38ddf5d79d
commit 268c7b758b
6 changed files with 43 additions and 39 deletions

View File

@ -5,7 +5,7 @@
'use strict'; 'use strict';
/* exported InjectionOrder */ /* exported InjectionOrder */
async function InjectionOrder(show = true) { async function InjectionOrder(show, el, selector) {
if (!show) { if (!show) {
return messageBoxProxy.close(); return messageBoxProxy.close();
} }
@ -27,7 +27,7 @@ async function InjectionOrder(show = true) {
await messageBoxProxy.show({ await messageBoxProxy.show({
title: t('styleInjectionOrder'), title: t('styleInjectionOrder'),
contents: $create('fragment', Object.entries(groups).map(makeList)), contents: $create('fragment', Object.entries(groups).map(makeList)),
className: 'injection-order center-dialog', className: 'center-dialog ' + selector.slice(1),
blockScroll: true, blockScroll: true,
buttons: [t('confirmClose')], buttons: [t('confirmClose')],
}); });

View File

@ -1,3 +1,4 @@
/* global $ */// dom.js
/* global deepEqual */// toolbox.js /* global deepEqual */// toolbox.js
/* global msg */ /* global msg */
'use strict'; 'use strict';
@ -10,6 +11,18 @@ const router = {
return new URLSearchParams(location.search).get(key); return new URLSearchParams(location.search).get(key);
}, },
makeToggle(hashId, showHide, deps) {
const hash = '#' + hashId;
const selector = '.' + hash.slice(1);
router.watch({hash}, async state => {
const el = $(selector);
if (!state === !el) return;
if (state && deps) await require(deps);
await showHide(state, el, selector);
});
return router.updateHash.bind(router, hash);
},
push(url) { push(url) {
const state = history.state || {}; const state = history.state || {};
state.buffer = router.buffer; state.buffer = router.buffer;

View File

@ -273,7 +273,7 @@
<button id="check-all-updates" i18n="checkAllUpdates"> <button id="check-all-updates" i18n="checkAllUpdates">
<span id="update-progress"></span> <span id="update-progress"></span>
</button> </button>
<a id="update-history" i18n="title:genericHistoryLabel" tabindex="0"> <a id="update-history-button" i18n="title:genericHistoryLabel" tabindex="0">
<svg class="svg-icon" viewBox="0 0 20 20" i18n="alt:helpAlt"> <svg class="svg-icon" viewBox="0 0 20 20" i18n="alt:helpAlt">
<path d="M13,7H7V6h6Zm6,6.5A5.5,5.5,0,0,1,8.61,16H4V3H16V8.61A5.5,5.5,0,0,1,19,13.5ZM8,14c0-.16,0-.84,0-1H7V12H8.21a5.46,5.46,0,0,1,.39-1H7V10H9.26a5.55,5.55,0,0,1,1.09-1H7V8h7V5H6v9Zm10-.5A4.5,4.5,0,1,0,13.5,18,4.5,4.5,0,0,0,18,13.5ZM14,13V10H13v4h4V13Z"/> <path d="M13,7H7V6h6Zm6,6.5A5.5,5.5,0,0,1,8.61,16H4V3H16V8.61A5.5,5.5,0,0,1,19,13.5ZM8,14c0-.16,0-.84,0-1H7V12H8.21a5.46,5.46,0,0,1,.39-1H7V10H9.26a5.55,5.55,0,0,1,1.09-1H7V8h7V5H6v9Zm10-.5A4.5,4.5,0,1,0,13.5,18,4.5,4.5,0,0,0,18,13.5ZM14,13V10H13v4h4V13Z"/>
</svg> </svg>

View File

@ -954,7 +954,7 @@ button .svg-icon,
margin: .5em 1.25em 0; margin: .5em 1.25em 0;
} }
.update-history-log { .update-history {
font-size: 11px; font-size: 11px;
white-space: pre; white-space: pre;
overflow-x: hidden; overflow-x: hidden;
@ -976,7 +976,7 @@ button .svg-icon,
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
#stylus-embedded-options { .stylus-options {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
@ -988,7 +988,7 @@ button .svg-icon,
animation: fadein .25s ease-in-out; animation: fadein .25s ease-in-out;
} }
#stylus-embedded-options.fadeout { .stylus-options.fadeout {
animation: fadeout .25s ease-in-out; animation: fadeout .25s ease-in-out;
} }

View File

@ -50,9 +50,19 @@ newUI.renderClass();
installed.on('click', Events.entryClicked); installed.on('click', Events.entryClicked);
installed.on('mouseover', Events.lazyAddEntryTitle, {passive: true}); installed.on('mouseover', Events.lazyAddEntryTitle, {passive: true});
installed.on('mouseout', Events.lazyAddEntryTitle, {passive: true}); installed.on('mouseout', Events.lazyAddEntryTitle, {passive: true});
$('#manage-options-button').onclick = () => router.updateHash('#stylus-options'); $('#sync-styles').onclick =
$('#injection-order-button').onclick = () => router.updateHash('#injection-order'); $('#manage-options-button').onclick =
$('#sync-styles').onclick = () => router.updateHash('#stylus-options'); router.makeToggle('stylus-options', toggleEmbeddedOptions);
$('#injection-order-button').onclick =
router.makeToggle('injection-order', (...args) => InjectionOrder(...args), [
'/vendor/draggable-list/draggable-list.iife.min.js',
'/injection-order/injection-order.css',
'/injection-order/injection-order', /* global InjectionOrder */
]);
$('#update-history-button').onclick =
router.makeToggle('update-history', (...args) => showUpdateHistory(...args), [
'/manage/updater-ui', /* global showUpdateHistory */
]);
$$('#header a[href^="http"]').forEach(a => (a.onclick = Events.external)); $$('#header a[href^="http"]').forEach(a => (a.onclick = Events.external));
window.on('pageshow', handleVisibilityChange); window.on('pageshow', handleVisibilityChange);
window.on('pagehide', handleVisibilityChange); window.on('pagehide', handleVisibilityChange);
@ -91,8 +101,6 @@ newUI.renderClass();
msg.onExtension(onRuntimeMessage); msg.onExtension(onRuntimeMessage);
window.on('closeOptions', () => router.updateHash('')); window.on('closeOptions', () => router.updateHash(''));
router.watch({hash: '#stylus-options'}, toggleEmbeddedOptions);
router.watch({hash: '#injection-order'}, toggleInjectionOrder);
function onRuntimeMessage(msg) { function onRuntimeMessage(msg) {
switch (msg.method) { switch (msg.method) {
@ -115,32 +123,13 @@ function onRuntimeMessage(msg) {
setTimeout(sorter.updateStripes, 0, {onlyWhenColumnsChanged: true}); setTimeout(sorter.updateStripes, 0, {onlyWhenColumnsChanged: true});
} }
async function toggleEmbeddedOptions(state) { async function toggleEmbeddedOptions(show, el, selector) {
const el = $('#stylus-embedded-options') || if (show) {
state && $.root.appendChild($create('iframe', { $.root.appendChild($create('iframe' + selector, {src: '/options.html'}))
id: 'stylus-embedded-options', .focus();
src: '/options.html', } else {
}));
if (state) {
el.focus();
} else if (el) {
el.contentDocument.body.classList.add('scaleout'); el.contentDocument.body.classList.add('scaleout');
await animateElement(el, 'fadeout'); await animateElement(el, 'fadeout');
el.remove(); el.remove();
} }
} }
async function toggleInjectionOrder(state) {
const shown = $('.injection-order');
if (state && !shown) {
await require([
'/vendor/draggable-list/draggable-list.iife.min.js',
'/injection-order/injection-order.css',
'/injection-order/injection-order', /* global InjectionOrder */
]);
await InjectionOrder();
router.updateHash('');
} else if (!state && shown) {
await InjectionOrder(false);
}
}

View File

@ -10,7 +10,6 @@
$('#check-all-updates').onclick = checkUpdateAll; $('#check-all-updates').onclick = checkUpdateAll;
$('#check-all-updates-force').onclick = checkUpdateAll; $('#check-all-updates-force').onclick = checkUpdateAll;
$('#apply-all-updates').onclick = applyUpdateAll; $('#apply-all-updates').onclick = applyUpdateAll;
$('#update-history').onclick = showUpdateHistory;
function applyUpdateAll() { function applyUpdateAll() {
const btnApply = $('#apply-all-updates'); const btnApply = $('#apply-all-updates');
@ -215,9 +214,12 @@ function renderUpdatesOnlyFilter({show, check} = {}) {
btnApply.dataset.value = numUpdatable; btnApply.dataset.value = numUpdatable;
} }
async function showUpdateHistory(event) { /* exported showUpdateHistory */
event.preventDefault(); async function showUpdateHistory(show, el, selector) {
const log = $create('.update-history-log'); if (!show) {
return messageBoxProxy.close();
}
const log = $create(selector);
let scroller, toggler; let scroller, toggler;
let deleted = false; let deleted = false;
await require(['/js/storage-util']); /* global chromeLocal */ await require(['/js/storage-util']); /* global chromeLocal */