replace overrides with declarative CSS + code cosmetics
This commit is contained in:
parent
cec24557bf
commit
a1acf53539
|
@ -11,8 +11,6 @@
|
||||||
<link rel="stylesheet" href="options/onoffswitch.css">
|
<link rel="stylesheet" href="options/onoffswitch.css">
|
||||||
<link rel="stylesheet" href="vendor-overwrites/colorpicker/colorpicker.css">
|
<link rel="stylesheet" href="vendor-overwrites/colorpicker/colorpicker.css">
|
||||||
|
|
||||||
<style id="style-overrides"></style>
|
|
||||||
|
|
||||||
<style id="firefox-transitions-bug-suppressor">
|
<style id="firefox-transitions-bug-suppressor">
|
||||||
/* restrict to FF */
|
/* restrict to FF */
|
||||||
@supports (-moz-appearance:none) {
|
@supports (-moz-appearance:none) {
|
||||||
|
|
|
@ -18,8 +18,8 @@ body {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.all-styles-hidden-by-filters:before,
|
body.all-styles-hidden-by-filters::before,
|
||||||
body.all-styles-hidden-by-filters:after {
|
body.all-styles-hidden-by-filters::after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: calc(3rem + var(--header-width));
|
left: calc(3rem + var(--header-width));
|
||||||
color: hsla(180, 40%, 45%, .3);
|
color: hsla(180, 40%, 45%, .3);
|
||||||
|
@ -32,7 +32,8 @@ body.all-styles-hidden-by-filters:before {
|
||||||
top: 3.5rem;
|
top: 3.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.all-styles-hidden-by-filters:after {
|
body.all-styles-hidden-by-filters::after {
|
||||||
|
content: var(--filteredStylesAllHidden);
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 3rem;
|
top: 3rem;
|
||||||
|
@ -253,7 +254,11 @@ a:hover {
|
||||||
vertical-align: text-top;
|
vertical-align: text-top;
|
||||||
}
|
}
|
||||||
|
|
||||||
.disabled h2::after, .entry.usercss .style-name-link::after {
|
.disabled h2::after {
|
||||||
|
content: var(--genericDisabledLabel);
|
||||||
|
}
|
||||||
|
.disabled h2::after,
|
||||||
|
.entry.usercss .style-name-link::after {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
text-transform: lowercase;
|
text-transform: lowercase;
|
||||||
|
@ -642,6 +647,7 @@ a:hover {
|
||||||
|
|
||||||
.newUI .targets {
|
.newUI .targets {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
max-height: calc(var(--num-targets) * 18px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.newUI .applies-to.expanded .targets {
|
.newUI .applies-to.expanded .targets {
|
||||||
|
@ -687,13 +693,16 @@ a:hover {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
margin: -1px 4px 0 -20px;
|
margin: -1px 4px 0 -20px;
|
||||||
transition: opacity .5s, filter .5s;
|
transition: opacity .5s, filter .5s;
|
||||||
filter: grayscale(1);
|
|
||||||
/* workaround for the buggy CSS filter: images in the hidden overflow are shown on Mac */
|
/* workaround for the buggy CSS filter: images in the hidden overflow are shown on Mac */
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
opacity: .25;
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.newUI .favicons-grayed .target img {
|
||||||
|
filter: grayscale(1);
|
||||||
|
opacity: .25;
|
||||||
|
}
|
||||||
|
|
||||||
.newUI .has-favicons .target {
|
.newUI .has-favicons .target {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
@ -773,6 +782,7 @@ a:hover {
|
||||||
}
|
}
|
||||||
|
|
||||||
#update-all-no-updates[data-skipped-edited="true"]::after {
|
#update-all-no-updates[data-skipped-edited="true"]::after {
|
||||||
|
content: " " var(--updateAllCheckSucceededSomeEdited);
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {HTMLElement} */
|
||||||
let installed;
|
let installed;
|
||||||
|
|
||||||
const ENTRY_ID_PREFIX_RAW = 'style-';
|
const ENTRY_ID_PREFIX_RAW = 'style-';
|
||||||
|
@ -70,21 +71,22 @@ const AGES = [
|
||||||
|
|
||||||
const handleEvent = {};
|
const handleEvent = {};
|
||||||
|
|
||||||
Promise.all([
|
(async () => {
|
||||||
|
const query = router.getSearch('search');
|
||||||
|
const [styles, ids, el] = await Promise.all([
|
||||||
API.getAllStyles(),
|
API.getAllStyles(),
|
||||||
// FIXME: integrate this into filter.js
|
query && API.searchDB({query}), // FIXME: integrate this into filter.js
|
||||||
router.getSearch('search') && API.searchDB({query: router.getSearch('search')}),
|
|
||||||
waitForSelector('#installed'), // needed to avoid flicker due to an extra frame and layout shift
|
waitForSelector('#installed'), // needed to avoid flicker due to an extra frame and layout shift
|
||||||
prefs.initializing,
|
prefs.initializing,
|
||||||
]).then(([styles, ids, el]) => {
|
]);
|
||||||
installed = el;
|
installed = el;
|
||||||
installed.onclick = handleEvent.entryClicked;
|
installed.onclick = handleEvent.entryClicked;
|
||||||
$('#manage-options-button').onclick = () => router.updateHash('#stylus-options');
|
$('#manage-options-button').onclick = () => router.updateHash('#stylus-options');
|
||||||
$('#sync-styles').onclick = () => router.updateHash('#stylus-options');
|
$('#sync-styles').onclick = () => router.updateHash('#stylus-options');
|
||||||
$$('#header a[href^="http"]').forEach(a => (a.onclick = handleEvent.external));
|
$$('#header a[href^="http"]').forEach(a => (a.onclick = handleEvent.external));
|
||||||
// show date installed & last update on hover
|
// show date installed & last update on hover
|
||||||
installed.addEventListener('mouseover', handleEvent.lazyAddEntryTitle);
|
installed.addEventListener('mouseover', handleEvent.lazyAddEntryTitle, {passive: true});
|
||||||
installed.addEventListener('mouseout', handleEvent.lazyAddEntryTitle);
|
installed.addEventListener('mouseout', handleEvent.lazyAddEntryTitle, {passive: true});
|
||||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||||
// N.B. triggers existing onchange listeners
|
// N.B. triggers existing onchange listeners
|
||||||
setupLivePrefs();
|
setupLivePrefs();
|
||||||
|
@ -92,17 +94,13 @@ Promise.all([
|
||||||
prefs.subscribe(newUI.ids.map(newUI.prefKeyForId), () => switchUI());
|
prefs.subscribe(newUI.ids.map(newUI.prefKeyForId), () => switchUI());
|
||||||
switchUI({styleOnly: true});
|
switchUI({styleOnly: true});
|
||||||
// translate CSS manually
|
// translate CSS manually
|
||||||
document.head.appendChild($create('style', `
|
document.styleSheets[0].insertRule(
|
||||||
.disabled h2::after {
|
`:root {${[
|
||||||
content: "${t('genericDisabledLabel')}";
|
'genericDisabledLabel',
|
||||||
}
|
'updateAllCheckSucceededSomeEdited',
|
||||||
#update-all-no-updates[data-skipped-edited="true"]::after {
|
'filteredStylesAllHidden',
|
||||||
content: " ${t('updateAllCheckSucceededSomeEdited')}";
|
].map(id => `--${id}:"${CSS.escape(t(id))}";`).join('')
|
||||||
}
|
}}`);
|
||||||
body.all-styles-hidden-by-filters::after {
|
|
||||||
content: "${t('filteredStylesAllHidden')}";
|
|
||||||
}
|
|
||||||
`));
|
|
||||||
if (!VIVALDI) {
|
if (!VIVALDI) {
|
||||||
$$('#header select').forEach(el => el.adjustWidth());
|
$$('#header select').forEach(el => el.adjustWidth());
|
||||||
}
|
}
|
||||||
|
@ -113,9 +111,11 @@ Promise.all([
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
showStyles(styles, ids);
|
showStyles(styles, ids);
|
||||||
});
|
})();
|
||||||
|
|
||||||
msg.onExtension(onRuntimeMessage);
|
msg.onExtension(onRuntimeMessage);
|
||||||
|
router.watch({hash: '#stylus-options'}, state => (state ? embedOptions : unembedOptions)());
|
||||||
|
window.addEventListener('closeOptions', () => router.updateHash(''));
|
||||||
|
|
||||||
function onRuntimeMessage(msg) {
|
function onRuntimeMessage(msg) {
|
||||||
switch (msg.method) {
|
switch (msg.method) {
|
||||||
|
@ -673,22 +673,9 @@ function switchUI({styleOnly} = {}) {
|
||||||
|
|
||||||
Object.assign(newUI, current);
|
Object.assign(newUI, current);
|
||||||
newUI.renderClass();
|
newUI.renderClass();
|
||||||
installed.classList.toggle('has-favicons', newUI.favicons);
|
installed.classList.toggle('has-favicons', newUI.enabled && newUI.favicons);
|
||||||
$('#style-overrides').textContent = `
|
installed.classList.toggle('favicons-grayed', newUI.enabled && newUI.faviconsGray);
|
||||||
.newUI .targets {
|
if (changed.targets) installed.style.setProperty('--num-targets', newUI.targets);
|
||||||
max-height: ${newUI.targets * 18}px;
|
|
||||||
}
|
|
||||||
` + (newUI.faviconsGray ? `
|
|
||||||
.newUI .target img {
|
|
||||||
filter: grayscale(1);
|
|
||||||
opacity: .25;
|
|
||||||
}
|
|
||||||
` : `
|
|
||||||
.newUI .target img {
|
|
||||||
filter: none;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
|
|
||||||
if (styleOnly) {
|
if (styleOnly) {
|
||||||
return;
|
return;
|
||||||
|
@ -764,13 +751,11 @@ function waitForSelector(selector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function embedOptions() {
|
function embedOptions() {
|
||||||
let options = $('#stylus-embedded-options');
|
const options = $('#stylus-embedded-options') ||
|
||||||
if (!options) {
|
document.documentElement.appendChild($create('iframe', {
|
||||||
options = document.createElement('iframe');
|
id: 'stylus-embedded-options',
|
||||||
options.id = 'stylus-embedded-options';
|
src: '/options.html',
|
||||||
options.src = '/options.html';
|
}));
|
||||||
document.documentElement.appendChild(options);
|
|
||||||
}
|
|
||||||
options.focus();
|
options.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,20 +763,7 @@ async function unembedOptions() {
|
||||||
const options = $('#stylus-embedded-options');
|
const options = $('#stylus-embedded-options');
|
||||||
if (options) {
|
if (options) {
|
||||||
options.contentWindow.document.body.classList.add('scaleout');
|
options.contentWindow.document.body.classList.add('scaleout');
|
||||||
options.classList.add('fadeout');
|
|
||||||
await animateElement(options, 'fadeout');
|
await animateElement(options, 'fadeout');
|
||||||
options.remove();
|
options.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
router.watch({hash: '#stylus-options'}, state => {
|
|
||||||
if (state) {
|
|
||||||
embedOptions();
|
|
||||||
} else {
|
|
||||||
unembedOptions();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('closeOptions', () => {
|
|
||||||
router.updateHash('');
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user