From f797e87099eb83cf25db264241cc6839507c4c03 Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 00:28:09 -0600 Subject: [PATCH 1/6] Reverse all handled keys except `@supportURL` * Use `unshift` to keep code simpler Applies to #210 --- controllers/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/script.js b/controllers/script.js index 6bdca3461..34f48aadf 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -73,7 +73,7 @@ var getScriptPageTasks = function (options) { } else { options.script.collaborators = []; script.meta.collaborator.forEach(function (collaborator) { - options.script.collaborators.push({ url: encodeURIComponent(collaborator), text: collaborator }); + options.script.collaborators.unshift({ url: encodeURIComponent(collaborator), text: collaborator }); }); } } @@ -85,7 +85,7 @@ var getScriptPageTasks = function (options) { } else { options.script.copyrights = []; script.meta.copyright.forEach(function (copyright) { - options.script.copyrights.push({ name: copyright }); + options.script.copyrights.unshift({ name: copyright }); }); } } @@ -97,7 +97,7 @@ var getScriptPageTasks = function (options) { } else { options.script.licenses = []; script.meta.license.forEach(function (license) { - options.script.licenses.push({ name: license }); + options.script.licenses.unshift({ name: license }); }); } } else if (!script.isLib) { @@ -120,7 +120,7 @@ var getScriptPageTasks = function (options) { script.meta.homepageURL.forEach(function (homepage) { htmlStub = ''; if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { - options.script.homepages.push({ + options.script.homepages.unshift({ url: homepage, text: decodeURI(homepage), hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(homepage) From cc3ae792d4e62c1464c7889010d0ae6f74b3763c Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 00:41:48 -0600 Subject: [PATCH 2/6] Reverse multiple handled key order and match code point to display points * Last value is primary for all multiple shown keys in script source but display reversed. Using last as primary will save us headaches down the line. * `supportURL` is only using last one in our `script.support` so no need to mess with that. Closes #210 --- controllers/script.js | 96 +++++++++++++++++----------------- views/pages/newScriptPage.html | 8 +-- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/controllers/script.js b/controllers/script.js index 34f48aadf..bb0ccbdfc 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -65,15 +65,47 @@ var getScriptPageTasks = function (options) { .caseInsensitive(script.issuesCategorySlug), open: {$ne: false} }); tasks.push(countTask(scriptOpenIssueCountQuery, options, 'issueCount')); - // Show collaborators of the script - if (script.meta.author && script.meta.collaborator) { - options.hasCollab = true; - if (typeof script.meta.collaborator === 'string') { - options.script.collaborators = [{ url: encodeURIComponent(script.meta.collaborator), text: script.meta.collaborator }]; + // Show the groups the script belongs to + tasks.push(function (callback) { + script.hasGroups = false; + script.groups = []; + + Group.find({ + _scriptIds: script._id + }, function (err, scriptGroupList) { + if (err) return callback(err); + + scriptGroupList = _.map(scriptGroupList, modelParser.parseGroup); + + script.hasGroups = scriptGroupList.length > 0; + script.groups = scriptGroupList; + + callback(); + }); + }); + + // Show homepages of the script + if (script.meta.homepageURL) { + if (typeof script.meta.homepageURL === 'string') { + htmlStub = ''; + if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { + options.script.homepages = [{ + url: script.meta.homepageURL, + text: decodeURI(script.meta.homepageURL), + hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org\//i.test(script.meta.homepageURL) + }]; + } } else { - options.script.collaborators = []; - script.meta.collaborator.forEach(function (collaborator) { - options.script.collaborators.unshift({ url: encodeURIComponent(collaborator), text: collaborator }); + options.script.homepages = []; + script.meta.homepageURL.forEach(function (homepage) { + htmlStub = ''; + if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { + options.script.homepages.unshift({ + url: homepage, + text: decodeURI(homepage), + hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(homepage) + }); + } }); } } @@ -104,51 +136,19 @@ var getScriptPageTasks = function (options) { options.script.licenses = [{ name: 'MIT License (Expat)' }]; } - // Show homepages of the script - if (script.meta.homepageURL) { - if (typeof script.meta.homepageURL === 'string') { - htmlStub = ''; - if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { - options.script.homepages = [{ - url: script.meta.homepageURL, - text: decodeURI(script.meta.homepageURL), - hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org\//i.test(script.meta.homepageURL) - }]; - } + // Show collaborators of the script + if (script.meta.author && script.meta.collaborator) { + options.hasCollab = true; + if (typeof script.meta.collaborator === 'string') { + options.script.collaborators = [{ url: encodeURIComponent(script.meta.collaborator), text: script.meta.collaborator }]; } else { - options.script.homepages = []; - script.meta.homepageURL.forEach(function (homepage) { - htmlStub = ''; - if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { - options.script.homepages.unshift({ - url: homepage, - text: decodeURI(homepage), - hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(homepage) - }); - } + options.script.collaborators = []; + script.meta.collaborator.forEach(function (collaborator) { + options.script.collaborators.unshift({ url: encodeURIComponent(collaborator), text: collaborator }); }); } } - // Show the groups the script belongs to - tasks.push(function (callback) { - script.hasGroups = false; - script.groups = []; - - Group.find({ - _scriptIds: script._id - }, function (err, scriptGroupList) { - if (err) return callback(err); - - scriptGroupList = _.map(scriptGroupList, modelParser.parseGroup); - - script.hasGroups = scriptGroupList.length > 0; - script.groups = scriptGroupList; - - callback(); - }); - }); - // Show which libraries hosted on the site a script uses if (!script.isLib && script.uses && script.uses.length > 0) { script.usesLibs = true; diff --git a/views/pages/newScriptPage.html b/views/pages/newScriptPage.html index 9f368ecdf..5525d4129 100644 --- a/views/pages/newScriptPage.html +++ b/views/pages/newScriptPage.html @@ -31,7 +31,7 @@

@description This script even does the

@copyright Year, Author (Author Website)

-

[Wiki Link] Specially formatted on the script page. All values shown.

+

[Wiki Link] Specially formatted on the script page. All values shown in reverse order.

@icon url

@@ -39,11 +39,11 @@

@icon url

@license License Type; License Homepage

-

[Wiki Link] Specially formatted on the script page. All values shown. If absent MIT License (Expat) is implied.

+

[Wiki Link] Specially formatted on the script page. All values shown in reverse order. If absent MIT License (Expat) is implied.

@homepageURL url

-

A url of http, https or mailto protocol. Specially formatted on the script page. All values shown.

+

A url of http, https or mailto protocol. Specially formatted on the script page. All values shown in reverse order.

@supportURL url

@@ -55,7 +55,7 @@

@author {{#authedUser}}{{authedUser.na

@collaborator username

-

Can be defined multiple times. Required for Collaboration. All values shown. This key is subject to change.

+

Can be defined multiple times. Required for Collaboration. All values shown in reverse order. This key is subject to change.

From 4b3bbee113f65ecfe352c782bfa6e636612c1ef3 Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 13:07:02 -0600 Subject: [PATCH 3/6] Use alternate reversal method * Use `push` then `reverse` as client side jsperf claims that to be faster than `unshift`. Don't know the validity of this since our ECMAScript implementation is server side but adjusting on the side of caution just in case. Applies to #210 --- controllers/script.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/script.js b/controllers/script.js index bb0ccbdfc..8fef31639 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -100,11 +100,12 @@ var getScriptPageTasks = function (options) { script.meta.homepageURL.forEach(function (homepage) { htmlStub = ''; if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { - options.script.homepages.unshift({ + options.script.homepages.push({ url: homepage, text: decodeURI(homepage), hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(homepage) }); + options.script.homepages = options.script.homepages.reverse(); } }); } @@ -117,8 +118,9 @@ var getScriptPageTasks = function (options) { } else { options.script.copyrights = []; script.meta.copyright.forEach(function (copyright) { - options.script.copyrights.unshift({ name: copyright }); + options.script.copyrights.push({ name: copyright }); }); + options.script.copyrights = options.script.copyrights.reverse(); } } @@ -129,8 +131,9 @@ var getScriptPageTasks = function (options) { } else { options.script.licenses = []; script.meta.license.forEach(function (license) { - options.script.licenses.unshift({ name: license }); + options.script.licenses.push({ name: license }); }); + options.script.licenses = options.script.licenses.reverse(); } } else if (!script.isLib) { options.script.licenses = [{ name: 'MIT License (Expat)' }]; @@ -144,8 +147,9 @@ var getScriptPageTasks = function (options) { } else { options.script.collaborators = []; script.meta.collaborator.forEach(function (collaborator) { - options.script.collaborators.unshift({ url: encodeURIComponent(collaborator), text: collaborator }); + options.script.collaborators.push({ url: encodeURIComponent(collaborator), text: collaborator }); }); + options.script.collaborators = options.script.collaborators.reverse(); } } From 9b63b5eaf185d78614b4b4291c095b7626bc13de Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 14:04:18 -0600 Subject: [PATCH 4/6] Reverting last commit as it is shorter according to two other tests. * JsPerf is incorrect as I've seen before * Using 100 `@homepageURL` entries and `console.timer("needforspeed")` and `console.timerEnd("needforspeed")` around the entire handled keys block the results in the console are: 11ms for `push` with `reverse` and 9ms for `unshift` * Unlikely that anyone will use this many but used in this benchmark --- controllers/script.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/controllers/script.js b/controllers/script.js index 8fef31639..bb0ccbdfc 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -100,12 +100,11 @@ var getScriptPageTasks = function (options) { script.meta.homepageURL.forEach(function (homepage) { htmlStub = ''; if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) { - options.script.homepages.push({ + options.script.homepages.unshift({ url: homepage, text: decodeURI(homepage), hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(homepage) }); - options.script.homepages = options.script.homepages.reverse(); } }); } @@ -118,9 +117,8 @@ var getScriptPageTasks = function (options) { } else { options.script.copyrights = []; script.meta.copyright.forEach(function (copyright) { - options.script.copyrights.push({ name: copyright }); + options.script.copyrights.unshift({ name: copyright }); }); - options.script.copyrights = options.script.copyrights.reverse(); } } @@ -131,9 +129,8 @@ var getScriptPageTasks = function (options) { } else { options.script.licenses = []; script.meta.license.forEach(function (license) { - options.script.licenses.push({ name: license }); + options.script.licenses.unshift({ name: license }); }); - options.script.licenses = options.script.licenses.reverse(); } } else if (!script.isLib) { options.script.licenses = [{ name: 'MIT License (Expat)' }]; @@ -147,9 +144,8 @@ var getScriptPageTasks = function (options) { } else { options.script.collaborators = []; script.meta.collaborator.forEach(function (collaborator) { - options.script.collaborators.push({ url: encodeURIComponent(collaborator), text: collaborator }); + options.script.collaborators.unshift({ url: encodeURIComponent(collaborator), text: collaborator }); }); - options.script.collaborators = options.script.collaborators.reverse(); } } From 1af274b85ce8636fdf5cd782b791945113fa3006 Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 17:31:55 -0600 Subject: [PATCH 5/6] Remove SF links as SourceForge EOLd mediawiki * I just heard back from SF and this is going to take some time for me to migrate and I'd rather just have a simple set of urls to other defined metadata block keys somewhere else. Applies to #210 --- views/pages/newScriptPage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/pages/newScriptPage.html b/views/pages/newScriptPage.html index 5525d4129..9f2da4fc6 100644 --- a/views/pages/newScriptPage.html +++ b/views/pages/newScriptPage.html @@ -31,7 +31,7 @@

@description This script even does the

@copyright Year, Author (Author Website)

-

[Wiki Link] Specially formatted on the script page. All values shown in reverse order.

+

Specially formatted on the script page. All values shown in reverse order.

@icon url

@@ -39,7 +39,7 @@

@icon url

@license License Type; License Homepage

-

[Wiki Link] Specially formatted on the script page. All values shown in reverse order. If absent MIT License (Expat) is implied.

+

Specially formatted on the script page. All values shown in reverse order. If absent MIT License (Expat) is implied.

@homepageURL url

From e5ad3487f00145aafe3ae0ef799bd291d48b43a0 Mon Sep 17 00:00:00 2001 From: Martii Date: Fri, 27 Jun 2014 18:11:50 -0600 Subject: [PATCH 6/6] Point general link to Project App Wiki and change a few verbages Applies to #210 --- views/pages/newScriptPage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/pages/newScriptPage.html b/views/pages/newScriptPage.html index 9f2da4fc6..25762a141 100644 --- a/views/pages/newScriptPage.html +++ b/views/pages/newScriptPage.html @@ -19,7 +19,7 @@

Script Metadata

-

You can read about most userscript metadata blocks on the greasespot wiki and at the greasemonkey sourceforge wiki.

+

You can read about most userscript metadata blocks on the Greasespot wiki and at the Greasemonkey on SourceForge wiki.

OpenUserJS.org Specific