Add 油猴脚本更新 #405 (#432)

This commit is contained in:
imlonghao
2018-08-08 11:02:55 +08:00
committed by DIYgod
parent 15c7fa9468
commit 4806d73360
3 changed files with 62 additions and 0 deletions
+14
View File
@@ -1656,3 +1656,17 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
路由: `/namoc/announcement`
参数:无
## Greasy Fork
### 脚本更新
举例: [https://rsshub.app/greasyfork/zh-CN/bilibili.com](https://rsshub.app/greasyfork/zh-CN/bilibili.com)
路由: `/greasyfork/:language/:domain?`
参数:
language,语言,可在网站右上角找到, `all` 为所有语言
domain,按脚本生效域名过滤,可选
+3
View File
@@ -381,4 +381,7 @@ router.get('/dongqiudi/daily', require('./routes/dongqiudi/index'));
// 维基百科
router.get('/wikipedia/mainland', require('./routes/wikipedia/mainland'));
// Greasy Fork
router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts'));
module.exports = router;
+45
View File
@@ -0,0 +1,45 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
module.exports = async (ctx) => {
const language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language;
const domain = ctx.params.domain;
const filter_locale = ctx.params.language === 'all' ? 0 : 1;
const url = domain ? `by-site/${domain}` : '';
const res = await axios({
method: 'get',
url: `https://greasyfork.org/${language}/scripts/${url}`,
params: {
filter_locale: filter_locale,
sort: 'updated',
},
header: {
'User-Agent': config.ua,
},
});
const data = res.data;
const $ = cheerio.load(data);
const list = $('.script-list').find('h2');
ctx.state.data = {
title: $('title')
.first()
.text(),
link: `https://greasyfork.org/${language}/scripts/${url}`,
description: $('meta[name=description]').attr('content'),
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').text(),
description: item.find('.description').text(),
link: `https://greasyfork.org${item.find('a').attr('href')}`,
};
})
.get(),
};
};