Skip to content

Commit

Permalink
Add @downloadURL common values to Script Author Tools
Browse files Browse the repository at this point in the history
* 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 OpenUserJS#1654 and additional for OpenUserJS#432
  • Loading branch information
Martii committed Aug 29, 2019
1 parent 30637d0 commit a4abaae
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 6 deletions.
55 changes: 51 additions & 4 deletions controllers/user.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions views/includes/scriptAuthorToolsPanel.html
Expand Up @@ -33,6 +33,28 @@ <h4>UserScript Block</h4>
</span>
</div>
</div>

<div class="form-group">
<div class="input-group col-xs-12">
<span class="input-group-btn">
<button class="btn btn-default" id="downloadurl-raw" data-clipboard-text="// @downloadURL {{#script.meta.UserScript.downloadURL}}{{{script.meta.UserScript.downloadURL.0.value}}}{{/script.meta.UserScript.downloadURL}}{{^script.meta.UserScript.downloadURL}}{{{script.scriptPermalinkInstallPageUrl}}}{{/script.meta.UserScript.downloadURL}}" title="Copy key and raw URL to clipboard"><i class="octicon octicon-clippy"></i> // @downloadURL</button>
</span>
<input type="text" class="form-control" id="downloadurl" value="{{#script.meta.UserScript.downloadURL}}{{{script.meta.UserScript.downloadURL.0.value}}}{{/script.meta.UserScript.downloadURL}}{{^script.meta.UserScript.downloadURL}}{{{script.scriptPermalinkInstallPageUrl}}}{{/script.meta.UserScript.downloadURL}}" readonly="readonly">
<span class="input-group-btn dropup">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Alternate download source targets"><span class="caret"></span> <span class="sr-only">Toggle Dropdown</span> </button>
<ul class="dropdown-menu scrollable-menu dropdown-menu-right" id="install-targets">
{{#script.availableScriptPermalinkInstallPageUrl}}<li {{#default}}class="active"{{/default}}><a href="#" title="{{{url}}">{{label}}</a></li>{{/script.availableScriptPermalinkInstallPageUrl}}
</ul>
</span>
<span class="input-group-btn">
<a class="btn btn-default"
title="How do I use this?"
href="/about/Frequently-Asked-Questions#q-is-there-a-way-to-not-count-script-updates-with-this-sites-install-counter-">
<i class="fa fa-question-circle"></i>
</a>
</span>
</div>
</div>
{{/newScript}}
{{/script.isLib}}

Expand Down
4 changes: 2 additions & 2 deletions views/includes/scriptPageHeader.html
Expand Up @@ -26,7 +26,7 @@ <h2 class="page-heading">
{{/isScriptPage}}
{{#isScriptViewSourcePage}}
<div class="btn-group pull-right">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNoticesCritical}}info{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}">
<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}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand All @@ -36,7 +36,7 @@ <h2 class="page-heading">
<ul class="dropdown-menu dropdown-menu-right">
<li>
<div class="btn-group btn-group-justified">
<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>
<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
1 change: 1 addition & 0 deletions views/includes/scripts/clipboard.html
Expand Up @@ -7,6 +7,7 @@

var allowedIds = [
'#copyright-raw',
'#downloadurl-raw',
'#groupid-raw',
'#groupid-urn',
'#license-raw',
Expand Down
53 changes: 53 additions & 0 deletions views/includes/scripts/selectInstall.html
@@ -0,0 +1,53 @@
<script type="text/javascript">
(function () {

{{> includes/scripts/polyfillElementClosest.js }}

function onClick(aEv) {
aEv.preventDefault();

var containerNode = aEv.target.closest('li');
var listInstallTargets = document.querySelectorAll('#install-targets li');
var inputInstall = document.querySelector('#downloadurl');
var copyDownloadURLButton = document.querySelector('#downloadurl-raw');
var i = null;
var thisItem = null;

if (containerNode && listInstallTargets && inputInstall && copyDownloadURLButton) {
inputInstall.value = aEv.target.title;
copyDownloadURLButton.setAttribute(
'data-clipboard-text',
'// @downloadURL ' + aEv.target.title
);

for (i = 0; thisItem = listInstallTargets[i++];) {
if (thisItem.classList.contains('active')) {
thisItem.classList.remove('active');
}
}

containerNode.classList.add('active');
}
}

function onDOMContentLoaded(aEv) {
var listInstallTargets = document.querySelectorAll('#install-targets li');
var thisItem = null;
var i = null;
var thisAnchor = null;

for (i = 0; thisItem = listInstallTargets[i++];) {
thisItem.addEventListener('click', onClick);

thisAnchor = thisItem.querySelector('a');

if (thisAnchor.title === '{{script.meta.UserScript.downloadURL.0.value}}') {
thisItem.classList.add('active');
}
}
}

document.addEventListener('DOMContentLoaded', onDOMContentLoaded);

})();
</script>
1 change: 1 addition & 0 deletions views/pages/scriptViewSourcePage.html
Expand Up @@ -62,6 +62,7 @@
{{> includes/scripts/lazyIconScript.html }}
{{> includes/scripts/clipboard.html }}
{{#authorTools}}
{{ > includes/scripts/selectInstall.html}}
{{ > includes/scripts/selectSPDX.html}}
{{/authorTools}}
{{> includes/scripts/scriptEditor.html }}
Expand Down

0 comments on commit a4abaae

Please sign in to comment.