From 6e52d48c6cf8b8cd35b3fdf5fb2327302bdf31a6 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 5 Sep 2017 10:32:30 +0800 Subject: [PATCH] Add: Add 'applies to' to install page --- content/install-user-css.css | 19 ++++++++++++++-- content/install-user-css.js | 43 +++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/content/install-user-css.css b/content/install-user-css.css index 5488964f..4cba66ab 100644 --- a/content/install-user-css.css +++ b/content/install-user-css.css @@ -24,8 +24,8 @@ body { margin-top: 0; } -.meta { - font-size: 1.4em; +h1 small { + font-size: 0.6em; } .warning { @@ -48,6 +48,21 @@ body { display: inline-block; } +.external { + text-align: center; +} + +.external > * { + margin: 0 7.5px; +} + +button.install { + display: block; + margin: 0 auto; + font-size: 2em; + padding: 0.4em 0.8em; +} + .code { padding: 2em; font-family: monospace; diff --git a/content/install-user-css.js b/content/install-user-css.js index 9247a358..e5ca4b5b 100644 --- a/content/install-user-css.js +++ b/content/install-user-css.js @@ -24,7 +24,7 @@ function install(style) { }); return communicate(request) .then(() => { - $$('.meta-version + .warning') + $$('.warning') .forEach(el => el.remove()); $('button.install').textContent = 'Installed'; $('button.install').disabled = true; @@ -46,6 +46,23 @@ function communicate(request) { }); } +function getAppliesTo(style) { + function *_gen() { + for (const section of style.sections) { + for (const type of ['urls', 'urlPrefixes', 'domains', 'regexps']) { + if (section[type]) { + yield *section[type]; + } + } + } + } + const result = [..._gen()]; + if (!result.length) { + result.push('All URLs'); + } + return result; +} + function initInstallPage({style, dup}) { pendingResource.then(() => { const versionTest = dup && usercss.semverTest(style.version, dup.version); @@ -54,21 +71,30 @@ function initInstallPage({style, dup}) { document.body.appendChild(tHTML(`
-

Install Usercss

-

Name

- ${style.name} -

Version

- ${style.version} +

${style.name} v${style.version}

+

${style.description}

+

Author

+ ${style.author} +

License

+ ${style.license} +

Applies to

+
    + ${getAppliesTo(style).map(s => `
  • ${s}
  • `)} +
+
`)); if (versionTest < 0) { // FIXME: i18n - $('.meta-version').after(tHTML(` + $('.actions').before(tHTML(`
The version is older then installed style.
@@ -93,7 +119,8 @@ function initErrorPage(err, source) { // FIXME: i18n document.body.appendChild(tHTML(`
- Stylus failed to parse usercss: ${err} + Stylus failed to parse usercss: +
${err}
`));