diff --git a/docs/en/shopping.md b/docs/en/shopping.md index d27c8196a..ea5c0d44a 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -88,6 +88,12 @@ All brands, see [Brand list](https://www.mercari.com/jp/brand/) +## ShopBack + +### Store + + + ## The Independent ### PS5 stock UK diff --git a/docs/shopping.md b/docs/shopping.md index 3e3fb2e58..33996d821 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -105,6 +105,12 @@ For instance, in +## ShopBack + +### Store + + + ## The Independent ### PS5 stock UK diff --git a/lib/v2/shopback/maintainer.js b/lib/v2/shopback/maintainer.js new file mode 100644 index 000000000..5be23c6ea --- /dev/null +++ b/lib/v2/shopback/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:store': ['nczitzk'], +}; diff --git a/lib/v2/shopback/radar.js b/lib/v2/shopback/radar.js new file mode 100644 index 000000000..01988eb54 --- /dev/null +++ b/lib/v2/shopback/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'shopback.com.tw': { + _name: 'ShopBack', + '.': [ + { + title: 'Store', + docs: 'https://docs.rsshub.app/shopping.html#shopback-store', + source: ['/:category', '/'], + target: '/shopback/:store', + }, + ], + }, +}; diff --git a/lib/v2/shopback/router.js b/lib/v2/shopback/router.js new file mode 100644 index 000000000..3322a3e11 --- /dev/null +++ b/lib/v2/shopback/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:store', require('./store')); +}; diff --git a/lib/v2/shopback/store.js b/lib/v2/shopback/store.js new file mode 100644 index 000000000..126692f5e --- /dev/null +++ b/lib/v2/shopback/store.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const store = ctx.params.store; + + const rootUrl = 'https://www.shopback.com.tw'; + const currentUrl = `${rootUrl}/${store}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + $('table').remove(); + + const items = $('div[data-content-name]') + .map((_, item) => { + item = $(item); + + return { + title: item.attr('data-content-name'), + author: item.attr('data-content-merchant'), + description: `

${item.find('.mb-3').text()}

`, + link: `${rootUrl}/login?redirect=/redirect/alink/${item.attr('data-content-id')}`, + }; + }) + .get(); + + ctx.state.data = { + title: `${$('h1').text()} - ShopBack`, + link: currentUrl, + item: items, + }; +};