Skip to content

Commit

Permalink
feat(route): Add script sorting for greasyfork
Browse files Browse the repository at this point in the history
  • Loading branch information
ingjieye committed Nov 29, 2023
1 parent 56d25ed commit ae83239
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/v2/greasyfork/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
'/:language/:domain?': ['imlonghao', 'miles170'],
'/scripts/:script/feedback': ['miles170'],
'/scripts/:script/versions': ['miles170'],
'/scripts/sort/:sort/:language?': ['ingjieye'],
};
1 change: 1 addition & 0 deletions lib/v2/greasyfork/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = (router) => {
router.get('/:language/:domain?', require('./scripts'));
router.get('/scripts/:script/feedback', require('./feedback'));
router.get('/scripts/:script/versions', require('./versions'));
router.get('/scripts/sort/:sort/:language?', require('./scripts'));
};
9 changes: 5 additions & 4 deletions lib/v2/greasyfork/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ const cheerio = require('cheerio');
const queryString = require('query-string');

module.exports = async (ctx) => {
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language;
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language || 'zh-CN';
const domain = ctx.params.domain;
const filter_locale = ctx.params.language === 'all' ? 0 : 1;
const url = domain ? `by-site/${domain}` : '';
const currentUrl = `https://greasyfork.org/${language}/scripts/${url}`;
const sort = ctx.params.sort ? ctx.params.sort : 'updated';
const url = domain ? `/by-site/${domain}` : '';
const currentUrl = `https://greasyfork.org/${language}/scripts` + url;
const res = await got({
method: 'get',
url: currentUrl,
searchParams: queryString.stringify({
filter_locale,
sort: 'updated',
sort,
}),
});
const $ = cheerio.load(res.data);
Expand Down
13 changes: 13 additions & 0 deletions website/docs/routes/program-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,19 @@ Language

<Route author="miles170" example="/greasyfork/scripts/431691-bypass-all-shortlinks/feedback" path="/greasyfork/scripts/:script/feedback" paramsDesc={['Script id, can be found in URL']} radar="1" />

### Script Ranking {#greasy-fork-script-ranking}

<Route author="ingjieye" example="/greasyfork/scripts/sort/today/all" path="/greasyfork/scripts/sort/:sort/:language?" paramsDesc={['Sort method, see below table', 'Language, located on the top right corner of Greasy Fork\'s search page, set to all for including all languages']} />

| Sort | Description |
| -------------- | ---------------- |
| today | Daily installs |
| total_installs | Total installs |
| ratings | Ratings |
| created | Created date |
| updated | Updated date |
| name | Name |

## Hugo {#hugo}

### Release News {#hugo-release-news}
Expand Down

0 comments on commit ae83239

Please sign in to comment.