File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,11 @@ var parseScript = function (aScript) {
184
184
var icon = null ;
185
185
var supportURL = null ;
186
186
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
+
187
192
// Temporaries
188
193
var htmlStub = null ;
189
194
@@ -199,6 +204,7 @@ var parseScript = function (aScript) {
199
204
200
205
var folders = null ;
201
206
207
+ var matches = null ;
202
208
203
209
if ( ! aScript ) {
204
210
return ;
@@ -362,6 +368,39 @@ var parseScript = function (aScript) {
362
368
script . isUpdated = true ;
363
369
}
364
370
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
+
365
404
return script ;
366
405
} ;
367
406
parseModelFnMap . Script = parseScript ;
Original file line number Diff line number Diff line change @@ -12,15 +12,25 @@ <h2 class="page-heading">
12
12
< ul class ="dropdown-menu ">
13
13
< li >
14
14
< 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 >
16
16
</ div >
17
17
{{#script.showMinficationNotices}}
18
18
< 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}}
19
24
{{#script.hasUnstableMinify}}
20
25
< p >
21
26
< i class ="fa fa-fw fa-exclamation-triangle "> </ i > The script author suggests that minification of this script may be unstable.
22
27
< p >
23
28
{{/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}}
24
34
</ div >
25
35
{{/script.showMinficationNotices}}
26
36
</ li >
You can’t perform that action at this time.
0 commit comments