Skip to content

Commit

Permalink
Create critical notices conditionals
Browse files Browse the repository at this point in the history
* Little less prominent for warnings vs. possible critical issue
* More in line with the docs that mostly say "blue install button"
* Add `updateURL` check for all modes and display if present
* Reorder the UI notices a bit.
* Some line length conformance


Post OpenUserJS#1632 and applies to OpenUserJS#1548 OpenUserJS#432
  • Loading branch information
Martii committed Jul 1, 2019
1 parent 396f609 commit 17bc4da
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 52 deletions.
103 changes: 64 additions & 39 deletions libs/modelParser.js
Expand Up @@ -223,6 +223,8 @@ var parseScript = function (aScript) {

var updateURL = null;
var updateUtf = null;
var updateURLForceCheck = process.env.FORCE_BUSY_UPDATEURL_CHECK === 'true';

var downloadURL = null;
var downloadUtf = null;
var rAnyLocalScriptUrl = new RegExp(
Expand Down Expand Up @@ -442,50 +444,73 @@ var parseScript = function (aScript) {
}

// 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;
}
// `@updateURL` must be exact here for OUJS hosted checks with updateURLForceCheck
// 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.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = true;

script.showSourceNotices = true;
script.showSourceNoticesCritical = 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 meta
} else {
// Allow offsite checks
updateURL = new URL(updateURL);
if (rSameOrigin.test(updateURL.origin)) {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
script.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

}
script.showSourceNotices = true;
script.showSourceNoticesCritical = updateURLForceCheck;
}
} else {
// Allow offsite checks
updateURL = new URL(updateURL);
if (rSameOrigin.test(updateURL.origin)) {
script.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

script.showSourceNotices = true;
script.showSourceNoticesCritical = true;
} else {
script.hasAlternateUpdateURL = 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;
}
}
} else {
if (!script.isLib) {
// If updateURLForceCheck is true don't serve the script anywhere in this mode and if absent
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

script.showSourceNotices = updateURLForceCheck;
script.showSourceNoticesCritical = updateURLForceCheck;
}
}

Expand Down
1 change: 1 addition & 0 deletions views/includes/scriptList.html
Expand Up @@ -15,6 +15,7 @@
<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}}
{{#showSourceNoticesCritical}}<span class="pull-right"><i class="fa fa-fw fa-exclamation-circle" title="Critical Source Code notices"></i></span>{{/showSourceNoticesCritical}}
{{#_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
12 changes: 6 additions & 6 deletions views/includes/scriptPageHeader.html
Expand Up @@ -2,17 +2,17 @@ <h2 class="page-heading">
{{#isScriptPage}}
{{^script.isLib}}
<div class="btn-group pull-right">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-{{^script.showSourceNoticesCritical}}info{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}">
<i class="fa fa-download"></i> Install
</a>
<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">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/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.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>
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/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.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
Expand All @@ -26,17 +26,17 @@ <h2 class="page-heading">
{{/isScriptPage}}
{{#isScriptViewSourcePage}}
<div class="btn-group pull-right">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNoticesCritical}}info{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}">
<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-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/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.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>
<a href="{{{script.scriptRawPageXUrl}}}" class="btn btn-{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/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.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
Expand Down
19 changes: 12 additions & 7 deletions views/includes/scriptPageHeaderSourceNotices.html
@@ -1,22 +1,27 @@
<div class="alert alert-warning" role="alert">
{{#script.hasInvalidUpdateURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid update target
<i class="fa fa-fw fa-exclamation-circle"></i> Invalid update target.
</p>
{{/script.hasInvalidUpdateURL}}
{{#script.hasAlternateUpdateURL}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.UserScript.updateURL.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate update target.
</p>
{{/script.hasAlternateUpdateURL}}
{{#script.hasInvalidDownloadURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid download target
<i class="fa fa-fw fa-exclamation-circle"></i> Invalid download target.
</p>
{{/script.hasInvalidDownloadURL}}
{{#script.hasUnstableMinify}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.OpenUserJS.unstableMinify.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
<p>
{{/script.hasUnstableMinify}}
{{#script.hasAlternateDownloadURL}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.UserScript.downloadURL.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate download target.
</p>
{{/script.hasAlternateDownloadURL}}
{{#script.hasUnstableMinify}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.OpenUserJS.unstableMinify.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
<p>
{{/script.hasUnstableMinify}}
</div>

0 comments on commit 17bc4da

Please sign in to comment.