Skip to content

Commit

Permalink
Add @updateURL to script homepage
Browse files Browse the repository at this point in the history
* Color changes depending upon lockdown mode ... default class vs info class *(currently white and blue respectively)*
* This is useful so there aren't mistakes post published ... many thanks to @jscher2000 for the idea on one placement... more? :)

**NOTE**
This doesn't cover dynamic searching on Source Code pages as those `@name`s can change.
Also using the `url` routines here... `uri` routines are available but need `options` link added in if needed

Applies to OpenUserJS#970
  • Loading branch information
Martii committed Apr 14, 2016
1 parent 56cdd79 commit c5b5dff
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ exports.view = function (aReq, aRes, aNext) {
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

// Lockdown
options.lockdown = {};
options.lockdown.scriptStorageRO = process.env.READ_ONLY_SCRIPT_STORAGE === 'true';
options.lockdown.updateURLCheck = process.env.FORCE_BUSY_UPDATEURL_CHECK === 'true';

// Script
options.script = script = modelParser.parseScript(aScript);
options.isOwner = authedUser && authedUser._id == script._authorId;
Expand All @@ -385,6 +390,8 @@ exports.view = function (aReq, aRes, aNext) {
script.scriptInstallPageUrl;
script.scriptPermalinkInstallPageXUrl = 'https://' + aReq.get('host') +
script.scriptInstallPageXUrl;
script.scriptPermalinkMetaPageUrl = 'https://' + aReq.get('host') +
script.scriptMetaPageUrl;

// Page metadata
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Userscripts')],
Expand Down
20 changes: 20 additions & 0 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ var getScriptInstallPageUrl = function (aScriptData) {
(isLib ? '.js' : '.user.js')
};

var getScriptMetaPageUrl = function (aScriptData) {
var isLib = aScriptData.isLib || false;

return (isLib ? null : '/meta/') +
aScriptData.authorSlugUrl +
'/' +
aScriptData.nameSlugUrl +
'.meta.js'
};


// Uris
Expand Down Expand Up @@ -173,6 +182,15 @@ var getScriptInstallPageUri = function (aScriptData) {
(isLib ? '.js' : '.user.js')
};

var getScriptMetaPageUri = function (aScriptData) {
var isLib = aScriptData.isLib || false;

return (isLib ? null : '/meta/') +
aScriptData.authorSlugUri +
'/' +
aScriptData.nameSlugUri +
'.meta.js'
};


//
Expand Down Expand Up @@ -312,6 +330,7 @@ var parseScript = function (aScript) {
script.scriptPageUrl = getScriptPageUrl(script);
script.scriptInstallPageUrl = getScriptInstallPageUrl(script);
script.scriptInstallPageXUrl = script.scriptInstallPageUrl.replace(/(\.user)?\.js/, '');
script.scriptMetaPageUrl = getScriptMetaPageUrl(script);
script.scriptViewSourcePageUrl = getScriptViewSourcePageUrl(script);

// Urls: Issues
Expand All @@ -338,6 +357,7 @@ var parseScript = function (aScript) {
script.scriptPageUri = getScriptPageUri(script);
script.scriptInstallPageUri = getScriptInstallPageUri(script);
script.scriptInstallPageXUri = script.scriptInstallPageUri.replace(/(\.user)?\.js/, '');
script.scriptMetaPageUri = getScriptMetaPageUri(script);
script.scriptViewSourcePageUri = getScriptViewSourcePageUri(script);

// Uris: Issues
Expand Down
8 changes: 8 additions & 0 deletions views/includes/scriptAuthorToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<li><a rel="nofollow" href="{{{script.scriptEditSourcePageUrl}}}"><i class="fa fa-file-text"></i> Edit Script</a></li>
</ul>
{{^script.isLib}}
<div class="form-group">
<div class="input-group col-xs-12">
<span class="input-group-btn">
<button class="btn btn-{{#lockdown.updateURLCheck}}info{{/lockdown.updateURLCheck}}{{^lockdown.updateURLCheck}}default{{/lockdown.updateURLCheck}}" id="updateurl-raw" data-clipboard-text="// @updateURL {{{script.scriptPermalinkMetaPageUrl}}}" title="Copy key and raw URL to clipboard"><i class="octicon octicon-clippy"></i> // @updateURL</button>
</span>
<input type="text" class="form-control" id="updateurl" value="{{{script.scriptPermalinkMetaPageUrl}}}" readonly="readonly">
</div>
</div>
<hr>
<h4>Installs per Version <small>effective <time title='Tue Sep 2 2014'>Sep '14</time></small></h4>
<p><code>{{script.meta.version}}{{^script.meta.version}}Current{{/script.meta.version}}</code> <span class="label label-default">{{script.installsSinceUpdate}} installs</span></p>
Expand Down
2 changes: 1 addition & 1 deletion views/includes/scripts/clipboard.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script type="text/javascript" src="/redist/npm/clipboard/dist/clipboard.js"></script>
<script type="text/javascript">
(function () {
var clipboard = new Clipboard('#require-raw, #require-min');
var clipboard = new Clipboard('#require-raw, #require-min, #updateurl-raw');
var rMin = /\.min\.js$/;

clipboard.on('success', function(aE) {
Expand Down
4 changes: 1 addition & 3 deletions views/pages/scriptPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ <h4>Userscripts Using This Library</h4>
{{> includes/scriptModals.html }}
{{> includes/footer.html }}
{{> includes/scripts/lazyIconScript.html }}
{{#script.isLib}}
{{> includes/scripts/clipboard.html }}
{{/script.isLib}}
{{> includes/scripts/clipboard.html }}
</body>
</html>

0 comments on commit c5b5dff

Please sign in to comment.