From d99326fa764a0e5761c0e6c92d0d7c2fba8c4660 Mon Sep 17 00:00:00 2001 From: Marti Martz Date: Wed, 28 Aug 2019 23:07:53 -0600 Subject: [PATCH] Add `@downloadURL` common values to Script Author Tools (#1680) * Some Authors are copying the trailing `#` from raw view... so give them the correct ones for .user.js engines. Also inclusive of minification routine. Post #1654 and additional for #432 Auto-merge --- controllers/user.js | 55 ++++++++++++++++++++-- views/includes/scriptAuthorToolsPanel.html | 22 +++++++++ views/includes/scriptPageHeader.html | 4 +- views/includes/scripts/clipboard.html | 1 + views/includes/scripts/selectInstall.html | 53 +++++++++++++++++++++ views/pages/scriptViewSourcePage.html | 1 + 6 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 views/includes/scripts/selectInstall.html diff --git a/controllers/user.js b/controllers/user.js index a953ea9e6..55bfcae93 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -2076,6 +2076,7 @@ exports.editScript = function (aReq, aRes, aNext) { var script = null; var scriptOpenIssueCountQuery = null; var collaborators = null; + var downloadURL = null; var licenses = null; var licensePrimary = null; var copyrights = null; @@ -2125,19 +2126,65 @@ exports.editScript = function (aReq, aRes, aNext) { || collaborators.indexOf(authedUser.name) > -1); modelParser.renderScript(script); script.installNameSlug = installNameBase; + script.scriptPermalinkInstallPageUrl = 'https://' + aReq.get('host') + script.scriptInstallPageUrl; - script.scriptPermalinkInstallPageXUrl = 'https://' + aReq.get('host') + - script.scriptInstallPageXUrl; + script.scriptPermalinkInstallPageUrlMin = 'https://' + aReq.get('host') + + script.scriptInstallPageXUrl + ".min.user.js"; + script.scriptRawPageUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/' + scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) + - (isLib ? '.js#' : '.user.js#'); + (isLib ? '.js' : '.user.js'); script.scriptRawPageXUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/' + scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) + - (isLib ? '.min.js#' : '.min.user.js#'); + (isLib ? '.min.js' : '.min.user.js'); + + script.scriptPermalinkRawPageUrl = 'https://' + aReq.get('host') + + script.scriptRawPageUrl; + script.scriptPermalinkRawPageUrlMin = 'https://' + aReq.get('host') + + script.scriptRawPageXUrl; + script.scriptPermalinkMetaPageUrl = 'https://' + aReq.get('host') + script.scriptMetaPageUrl; + script.availableScriptPermalinkInstallPageUrl = []; + + downloadURL = scriptStorage.findMeta(script.meta, 'UserScript.downloadURL.0.value'); + if (downloadURL) { + switch (downloadURL) { + case script.scriptPermalinkInstallPageUrl: + /* falls through */ + case script.scriptPermalinkInstallPageUrlMin: + /* falls through */ + case script.scriptPermalinkRawPageUrl: + /* falls through */ + case script.scriptPermalinkRawPageUrlMin: + break; + default: + script.availableScriptPermalinkInstallPageUrl.push({ + label: 'Custom', + url: downloadURL + }); + } + } + script.availableScriptPermalinkInstallPageUrl.push({ + label: 'Normal', + url: script.scriptPermalinkInstallPageUrl, + default: !downloadURL + }); + script.availableScriptPermalinkInstallPageUrl.push({ + label: 'Minified', + url: script.scriptPermalinkInstallPageUrlMin + }); + script.availableScriptPermalinkInstallPageUrl.push({ + label: 'Normal with counter skip', + url: script.scriptPermalinkRawPageUrl + }); + script.availableScriptPermalinkInstallPageUrl.push({ + label: 'Minified with counter skip', + url: script.scriptPermalinkRawPageUrlMin + }); + script.scriptAcceptableOSILicense = []; SPDX.forEach(function (aElement, aIndex, aArray) { if (blockSPDX.indexOf(aElement) === -1) { diff --git a/views/includes/scriptAuthorToolsPanel.html b/views/includes/scriptAuthorToolsPanel.html index 7c67be333..c9e8d69c5 100644 --- a/views/includes/scriptAuthorToolsPanel.html +++ b/views/includes/scriptAuthorToolsPanel.html @@ -33,6 +33,28 @@

UserScript Block

+ +
+
+ + + + + + + + + + + + + +
+
{{/newScript}} {{/script.isLib}} diff --git a/views/includes/scriptPageHeader.html b/views/includes/scriptPageHeader.html index f20e8b1ff..e3227deca 100644 --- a/views/includes/scriptPageHeader.html +++ b/views/includes/scriptPageHeader.html @@ -26,7 +26,7 @@

{{/isScriptPage}} {{#isScriptViewSourcePage}}
- + Raw Source