Skip to content

Commit 17840d2

Browse files
committed
Merge pull request #925 from Martii/Issue-432otherNotices
Readd other notices back in Auto-merge... retested on local pro as well.
2 parents 23caedd + 0737ae4 commit 17840d2

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

libs/modelParser.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ var parseScript = function (aScript) {
184184
var icon = null;
185185
var supportURL = null;
186186

187+
var downloadURL = null;
188+
var downloadUtf = null;
189+
var rAnySourceUrl = new RegExp('^https?://(?:openuserjs\.org|localhost:' +
190+
(process.env.PORT || 8080) + ')/(?:install|scr/scripts)\/(.+?)/(.+?)((?:\.min)?\.user\.js)$');
191+
187192
// Temporaries
188193
var htmlStub = null;
189194

@@ -199,6 +204,7 @@ var parseScript = function (aScript) {
199204

200205
var folders = null;
201206

207+
var matches = null;
202208

203209
if (!aScript) {
204210
return;
@@ -362,6 +368,39 @@ var parseScript = function (aScript) {
362368
script.isUpdated = true;
363369
}
364370

371+
// Download Url
372+
downloadURL = findMeta(script.meta, 'UserScript.downloadURL.0.value');
373+
if (downloadURL) {
374+
try {
375+
downloadUtf = decodeURIComponent(downloadURL);
376+
377+
} catch (aE) {
378+
script.hasInvalidDownloadURL = true;
379+
script.showMinficationNotices = true;
380+
381+
} finally {
382+
if (!script.hasInvalidDownloadURL) {
383+
matches = downloadUtf.match(rAnySourceUrl);
384+
385+
if (matches) {
386+
if (matches[1].toLowerCase() === script.authorSlug.toLowerCase() &&
387+
matches[2] === script.nameSlug) {
388+
389+
if (matches[3] === '.user.js') {
390+
script.hasAlternateDownloadURL = true;
391+
}
392+
} else {
393+
script.hasAlternateDownloadURL = true;
394+
script.showMinficationNotices = true;
395+
}
396+
} else {
397+
script.hasAlternateDownloadURL = true;
398+
script.showMinficationNotices = true;
399+
}
400+
}
401+
}
402+
}
403+
365404
return script;
366405
};
367406
parseModelFnMap.Script = parseScript;

views/includes/scriptPageHeader.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,25 @@ <h2 class="page-heading">
1212
<ul class="dropdown-menu">
1313
<li>
1414
<div class="btn-group btn-group-justified">
15-
<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 with minification</a>
15+
<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>
1616
</div>
1717
{{#script.showMinficationNotices}}
1818
<div class="alert alert-warning" role="alert">
19+
{{#script.hasInvalidDownloadURL}}
20+
<p>
21+
<i class="fa fa-fw fa-exclamation"></i> Invalid download target
22+
</p>
23+
{{/script.hasInvalidDownloadURL}}
1924
{{#script.hasUnstableMinify}}
2025
<p>
2126
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
2227
<p>
2328
{{/script.hasUnstableMinify}}
29+
{{#script.hasAlternateDownloadURL}}
30+
<p>
31+
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate download target.
32+
</p>
33+
{{/script.hasAlternateDownloadURL}}
2434
</div>
2535
{{/script.showMinficationNotices}}
2636
</li>

0 commit comments

Comments
 (0)