Fix: drop tHTML
This commit is contained in:
parent
97b4d91ec9
commit
bbe37adfef
|
@ -55,43 +55,14 @@ function getAppliesTo(style) {
|
||||||
function initInstallPage({style, dup}, sourceLoader) {
|
function initInstallPage({style, dup}, sourceLoader) {
|
||||||
return pendingResource.then(() => {
|
return pendingResource.then(() => {
|
||||||
const versionTest = dup && semverCompare(style.version, dup.version);
|
const versionTest = dup && semverCompare(style.version, dup.version);
|
||||||
document.body.innerHTML = '';
|
document.body.textContent = '';
|
||||||
document.body.appendChild(tHTML(`
|
document.body.appendChild(buildPage());
|
||||||
<div class="container">
|
|
||||||
<div class="header">
|
|
||||||
<h1>
|
|
||||||
${escapeHtml(style.name)}
|
|
||||||
<small class="meta-version">v${escapeHtml(style.version)}</small>
|
|
||||||
</h1>
|
|
||||||
<p>${escapeHtml(style.description)}</p>
|
|
||||||
<h3 i18n-text="author"></h3>
|
|
||||||
${escapeHtml(style.author)}
|
|
||||||
<h3 i18n-text="license"></h3>
|
|
||||||
${escapeHtml(style.license)}
|
|
||||||
<h3 i18n-text="appliesLabel"></h3>
|
|
||||||
<ul>
|
|
||||||
${getAppliesTo(style).map(s => `<li>${escapeHtml(s)}</li>`)}
|
|
||||||
</ul>
|
|
||||||
<div class="actions">
|
|
||||||
<button class="install">${t(
|
|
||||||
!dup ? 'installButton' : versionTest > 0 ?
|
|
||||||
'installButtonUpdate' : 'installButtonReinstall'
|
|
||||||
)}</button>
|
|
||||||
</div>
|
|
||||||
<div class="external">
|
|
||||||
<a href="${encodeURI(style.url)}" target="_blank" i18n-text="externalHomepage" rel="noopener"></a>
|
|
||||||
<a href="${encodeURI(style.supportURL)}" target="_blank" i18n-text="externalSupport" rel="noopener"></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="main">
|
|
||||||
<div class="code"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`));
|
|
||||||
if (versionTest < 0) {
|
if (versionTest < 0) {
|
||||||
$('.actions').parentNode.insertBefore(tHTML(`
|
$('.actions').parentNode.insertBefore(
|
||||||
<div class="warning" i18n-text="versionInvalidOlder"></div>
|
$element({className: 'warning', appendChild: t('versionInvalidOlder')}),
|
||||||
`), $('.actions'));
|
$('.actions')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$('.code').textContent = style.source;
|
$('.code').textContent = style.source;
|
||||||
$('button.install').onclick = () => {
|
$('button.install').onclick = () => {
|
||||||
|
@ -107,6 +78,51 @@ function initInstallPage({style, dup}, sourceLoader) {
|
||||||
if (location.protocol === 'file:') {
|
if (location.protocol === 'file:') {
|
||||||
initLiveReload(sourceLoader);
|
initLiveReload(sourceLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildPage() {
|
||||||
|
return $element({className: 'container', appendChild: [
|
||||||
|
$element({className: 'header', appendChild: [
|
||||||
|
$element({tag: 'h1', appendChild: [
|
||||||
|
style.name,
|
||||||
|
$element({tag: 'small', className: 'meta-version', appendChild: style.version})
|
||||||
|
]}),
|
||||||
|
$element({tag: 'p', appendChild: style.description}),
|
||||||
|
$element({tag: 'h3', appendChild: t('author')}),
|
||||||
|
style.author,
|
||||||
|
$element({tag: 'h3', appendChild: t('license')}),
|
||||||
|
style.license,
|
||||||
|
$element({tag: 'h3', appendChild: t('appliesLabel')}),
|
||||||
|
$element({tag: 'ul', appendChild: getAppliesTo(style).map(
|
||||||
|
pattern => $element({tag: 'li', appendChild: pattern})
|
||||||
|
)}),
|
||||||
|
$element({className: 'actions', appendChild: [
|
||||||
|
$element({tag: 'button', className: 'install', appendChild: installButtonLabel()})
|
||||||
|
]}),
|
||||||
|
$element({className: 'external', appendChild: [
|
||||||
|
externalLink('externalHomepage', style.url),
|
||||||
|
externalLink('externalSupport', style.support)
|
||||||
|
]})
|
||||||
|
]}),
|
||||||
|
$element({className: 'main', appendChild: [
|
||||||
|
$element({className: 'code'})
|
||||||
|
]})
|
||||||
|
]});
|
||||||
|
}
|
||||||
|
|
||||||
|
function externalLink(name, url) {
|
||||||
|
return $element({
|
||||||
|
tag: 'a',
|
||||||
|
href: url,
|
||||||
|
target: '_blank',
|
||||||
|
appendChild: t(name),
|
||||||
|
rel: 'noopener'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function installButtonLabel() {
|
||||||
|
return t(!dup ? 'installButton' :
|
||||||
|
versionTest > 0 ? 'installButtonUpdate' : 'installButtonReinstall');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +138,7 @@ function initLiveReload(sourceLoader) {
|
||||||
$$('.main .warning').forEach(e => e.remove());
|
$$('.main .warning').forEach(e => e.remove());
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
const oldWarning = $('.main .warning');
|
const oldWarning = $('.main .warning');
|
||||||
const warning = tHTML(`
|
const warning = buildWarning(err);
|
||||||
<div class="warning" i18n-text="parseUsercssError">
|
|
||||||
<pre>${escapeHtml(err)}</pre>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
if (oldWarning) {
|
if (oldWarning) {
|
||||||
oldWarning.replaceWith(warning);
|
oldWarning.replaceWith(warning);
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,12 +152,10 @@ function initLiveReload(sourceLoader) {
|
||||||
watcher.start();
|
watcher.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('.actions').appendChild(tHTML(`
|
$('.actions').appendChild($element({tag: 'label', className: 'live-reload', appendChild: [
|
||||||
<label class="live-reload">
|
$element({tag: 'input', type: 'checkbox', className: 'live-reload-checkbox'}),
|
||||||
<input type="checkbox" class="live-reload-checkbox">
|
$element({tag: 'span', appendChild: t('liveReloadLabel')})
|
||||||
<span i18n-text="liveReloadLabel"></span>
|
]}));
|
||||||
</label>
|
|
||||||
`));
|
|
||||||
$('.live-reload-checkbox').onchange = e => {
|
$('.live-reload-checkbox').onchange = e => {
|
||||||
if (!installed) {
|
if (!installed) {
|
||||||
return;
|
return;
|
||||||
|
@ -158,15 +168,20 @@ function initLiveReload(sourceLoader) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildWarning(err) {
|
||||||
|
return $element({className: 'warning', appendChild: [
|
||||||
|
t('parseUsercssError'),
|
||||||
|
$element({tag: 'pre', appendChild: String(err)})
|
||||||
|
]})
|
||||||
|
}
|
||||||
|
|
||||||
function initErrorPage(err, source) {
|
function initErrorPage(err, source) {
|
||||||
return pendingResource.then(() => {
|
return pendingResource.then(() => {
|
||||||
document.body.innerHTML = '';
|
document.body.innerHTML = '';
|
||||||
document.body.appendChild(tHTML(`
|
[
|
||||||
<div class="warning" i18n-text="parseUsercssError">
|
buildWarning(err),
|
||||||
<pre>${escapeHtml(err)}</pre>
|
$element({className: 'code'})
|
||||||
</div>
|
].forEach(e => document.body.appendChild(e));
|
||||||
<div class="code"></div>
|
|
||||||
`));
|
|
||||||
$('.code').textContent = source;
|
$('.code').textContent = source;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user