Skip to content

Commit

Permalink
Show script notices a little more prominently (#1632)
Browse files Browse the repository at this point in the history
* Change a few classes around for UI coloring and display
* Shows exclamation on script homepage and script lists that there **may** be user initiated, system initiated, etc. notices on the Install button or Raw Source button e.g. the Source Code tab contents.
* Few mustache identifier name changes for symmetry

Applies to #1548 #432

Auto-merge
  • Loading branch information
Martii authored Jul 1, 2019
1 parent 3c42cb6 commit 396f609
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 19 deletions.
68 changes: 63 additions & 5 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,22 @@ var parseScript = function (aScript) {
var supportURL = null;
var contributionURL = null;

var updateURL = null;
var updateUtf = null;
var downloadURL = null;
var downloadUtf = null;
var rAnyLocalScriptUrl = new RegExp(
'^' + patternHasSameOrigin +
'/(?:install|src/scripts)/(.+?)/(.+?)((?:\.min)?(?:\.user)?\.js)$'
);
var rAnyLocalMetaUrl = new RegExp(
'^' + patternHasSameOrigin +
'/(?:meta|install|src/scripts)/(.+?)/(.+?)\.meta\.js$'
);

var rSameOrigin = new RegExp(
'^' + patternHasSameOrigin
);

// Temporaries

Expand Down Expand Up @@ -317,7 +327,7 @@ var parseScript = function (aScript) {
// OpenUserJS metadata block checks
if (findMeta(script.meta, 'OpenUserJS.unstableMinify.0.value')) {
script.hasUnstableMinify = true;
script.showMinficationNotices = true;
script.showSourceNotices = true;
}

//
Expand Down Expand Up @@ -431,6 +441,54 @@ var parseScript = function (aScript) {
script.isUpdated = true;
}

// Update Url
if (process.env.FORCE_BUSY_UPDATEURL_CHECK === 'true') {
// `@updateURL` must be exact here for OUJS hosted checks
// e.g. no `search`, no `hash`

updateURL = findMeta(script.meta, 'UserScript.updateURL.0.value');
if (updateURL) {
// Check for decoding error
try {
updateUtf = decodeURIComponent(updateURL);

} catch (aE) {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;

} finally {
if (!script.hasInvalidUpdateURL) {

// Validate `author` and `name` (installNameBase) to this scripts meta only
matches = updateUtf.match(rAnyLocalMetaUrl);
if (matches) {
if (script.authorSlug.toLowerCase() + '/' + script.nameSlug === matches[1].toLowerCase() + '/' + matches[2])
{
// Same script
} else {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
}
} else {
// Allow offsite checks
updateURL = new URL(updateURL);
if (rSameOrigin.test(updateURL.origin)) {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;

}
}
}
}
} else {
if (!script.isLib) {
// Don't serve the script anywhere in this mode and if absent
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
}
}
}

// Download Url
downloadURL = findMeta(script.meta, 'UserScript.downloadURL.0.value');
if (downloadURL) {
Expand All @@ -439,7 +497,7 @@ var parseScript = function (aScript) {

} catch (aE) {
script.hasInvalidDownloadURL = true;
script.showMinficationNotices = true;
script.showSourceNotices = true;

} finally {
if (!script.hasInvalidDownloadURL) {
Expand All @@ -451,15 +509,15 @@ var parseScript = function (aScript) {
// Same script
} else {
script.hasAlternateDownloadURL = true;
script.showMinficationNotices = true;
script.showSourceNotices = true;
}
} else {
script.hasAlternateDownloadURL = true;
script.showMinficationNotices = true;
script.showSourceNotices = true;
}
} else {
script.hasAlternateDownloadURL = true;
script.showMinficationNotices = true;
script.showSourceNotices = true;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions views/includes/scriptList.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{#scriptList}}
<tr class="tr-link">
<td>
{{#showSourceNotices}}<span class="pull-right"><i class="fa fa-fw fa-exclamation-triangle" title="Source Code notices"></i></span>{{/showSourceNotices}}
{{#_issueCount}}<span class="pull-right"><a href="{{{scriptIssuesPageUri}}}/open" title="Open issue discussions"><i class="fa fa-fw fa-commenting"></i>{{_issueCount}}</a></span>{{/_issueCount}}
<span class="script-icon hidden-xs" {{#icon16Url}}data-icon-src="{{{icon16Url}}}" data-icon-size="16"{{/icon16Url}}>
{{#isLib}}<i class="fa fa-fw fa-file-excel-o"></i>{{/isLib}}{{^isLib}}<i class="fa fa-fw fa-file-code-o"></i>{{/isLib}}
Expand Down
24 changes: 12 additions & 12 deletions views/includes/scriptPageHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ <h2 class="page-heading">
{{#isScriptPage}}
{{^script.isLib}}
<div class="btn-group pull-right">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-info">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<i class="fa fa-download"></i> Install
</a>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<div class="btn-group btn-group-justified">
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showMinficationNotices}}warning{{/script.showMinficationNotices}}{{^script.showMinficationNotices}}primary{{/script.showMinficationNotices}}" title="EXPERIMENTAL INSTALLATION FORKING"><i class="fa fa-fw fa-download"></i> Install {{#script.hasAlternateDownloadURL}}once {{/script.hasAlternateDownloadURL}} with minification</a>
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL INSTALLATION FORKING"><i class="fa fa-fw fa-download"></i> Install {{#script.hasAlternateDownloadURL}}once {{/script.hasAlternateDownloadURL}} with minification</a>
</div>
{{#script.showMinficationNotices}}
{{> includes/scriptPageHeaderMinificationNotices.html }}
{{/script.showMinficationNotices}}
{{#script.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
{{/script.showSourceNotices}}
</li>
<li role="separator" class="divider"></li>
<li><a href="/about/Userscript-Beginners-HOWTO"><em class="fa fa-fw fa-question-circle"></em> Userscript Beginners HOWTO</a></li>
Expand All @@ -26,21 +26,21 @@ <h2 class="page-heading">
{{/isScriptPage}}
{{#isScriptViewSourcePage}}
<div class="btn-group pull-right">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-info">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Raw Source
</a>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<div class="btn-group btn-group-justified">
<a href="{{{script.scriptRawPageXUrl}}}" class="btn btn-{{#script.showMinficationNotices}}warning{{/script.showMinficationNotices}}{{^script.showMinficationNotices}}primary{{/script.showMinficationNotices}}" title="EXPERIMENTAL"><i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Minified Source</a>
<a href="{{{script.scriptRawPageXUrl}}}" class="btn btn-{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL"><i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Minified Source</a>
</div>
{{#script.showMinficationNotices}}
{{> includes/scriptPageHeaderMinificationNotices.html }}
{{/script.showMinficationNotices}}
{{#script.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
{{/script.showSourceNotices}}
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<div class="alert alert-warning" role="alert">
{{#script.hasInvalidUpdateURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid update target
</p>
{{/script.hasInvalidUpdateURL}}
{{#script.hasInvalidDownloadURL}}
<p>
<i class="fa fa-fw fa-exclamation"></i> Invalid download target
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid download target
</p>
{{/script.hasInvalidDownloadURL}}
{{#script.hasUnstableMinify}}
Expand Down
2 changes: 1 addition & 1 deletion views/pages/scriptPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="input-group col-xs-12">
<span class="input-group-btn">
<button class="btn btn-info" id="require-raw" data-clipboard-text="// @require {{{script.scriptPermalinkInstallPageUrl}}}" title="Copy key and raw URL to clipboard"><i class="octicon octicon-clippy"></i> // @require</button>
<button class="btn btn-warning" id="require-min" data-clipboard-text="// @require {{{script.scriptPermalinkInstallPageXUrl}}}.min.js" title="EXPERIMENTAL: Copy key and minified URL to clipboard"><i class="octicon octicon-clippy"></i></button>
<button class="btn btn-info" id="require-min" data-clipboard-text="// @require {{{script.scriptPermalinkInstallPageXUrl}}}.min.js" title="EXPERIMENTAL: Copy key and minified URL to clipboard"><i class="octicon octicon-clippy"></i></button>
</span>
<input type="text" class="form-control" id="require" value="{{{script.scriptPermalinkInstallPageUrl}}}" readonly="readonly">
</div>
Expand Down

0 comments on commit 396f609

Please sign in to comment.