diff --git a/lib/v2/greasyfork/maintainer.js b/lib/v2/greasyfork/maintainer.js
index d17e37b05..43ca727f8 100644
--- a/lib/v2/greasyfork/maintainer.js
+++ b/lib/v2/greasyfork/maintainer.js
@@ -2,4 +2,5 @@ module.exports = {
'/:language/:domain?': ['imlonghao', 'miles170'],
'/scripts/:script/feedback': ['miles170'],
'/scripts/:script/versions': ['miles170'],
+ '/scripts/sort/:sort/:language?': ['ingjieye'],
};
diff --git a/lib/v2/greasyfork/router.js b/lib/v2/greasyfork/router.js
index 0443d66a4..3ba05300e 100644
--- a/lib/v2/greasyfork/router.js
+++ b/lib/v2/greasyfork/router.js
@@ -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'));
};
diff --git a/lib/v2/greasyfork/scripts.js b/lib/v2/greasyfork/scripts.js
index b3d065926..7a6db5b48 100644
--- a/lib/v2/greasyfork/scripts.js
+++ b/lib/v2/greasyfork/scripts.js
@@ -1,39 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
-const queryString = require('query-string');
+const { parseDate } = require('@/utils/parse-date');
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({
+ searchParams: {
filter_locale,
- sort: 'updated',
- }),
+ sort,
+ },
});
const $ = cheerio.load(res.data);
- const list = $('.script-list').find('h2');
+ const list = $('.script-list').find('article');
ctx.state.data = {
title: $('title').first().text(),
link: currentUrl,
description: $('meta[name=description]').attr('content'),
- item:
- list &&
- list
- .map((_, item) => {
- item = $(item);
- return {
- title: item.find('a').text(),
- description: item.find('.description').text(),
- link: item.find('a').attr('href'),
- };
- })
- .get(),
+ item: list?.toArray().map((item) => {
+ item = $(item);
+ const h2 = item.find('h2');
+ return {
+ title: h2.find('a').text(),
+ description: h2.find('.description').text(),
+ link: new URL(h2.find('a').attr('href'), 'https://greasyfork.org').href,
+ pubDate: parseDate(item.find('.script-list-created-date relative-time').attr('datetime')),
+ updated: parseDate(item.find('.script-list-updated-date relative-time').attr('datetime')),
+ author: item
+ .find('.script-list-author a')
+ .toArray()
+ .map((a) => $(a).text())
+ .join(', '),
+ };
+ }),
};
};
diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx
index 34fe34842..05e138712 100644
--- a/website/docs/routes/program-update.mdx
+++ b/website/docs/routes/program-update.mdx
@@ -351,6 +351,19 @@ Language
+### Script Ranking {#greasy-fork-script-ranking}
+
+
+
+| 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}