feat: detect website rsshub

This commit is contained in:
DIYgod
2019-07-21 16:50:56 +08:00
parent 8ecfa5774b
commit 3624bd3188
4 changed files with 47 additions and 9 deletions
+10 -4
View File
@@ -1,7 +1,7 @@
body {
width: 310px;
margin: 0;
padding: 15px 20px 10px;
padding: 15px 20px 0;
font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
}
@@ -9,6 +9,7 @@ body {
.page-rsshub,
.website-rsshub {
display: none;
margin-bottom: 20px;
h2 {
font-size: 16px;
@@ -28,6 +29,8 @@ body {
}
.no-rss {
margin-bottom: 20px;
h2 {
font-size: 16px;
margin: 0 0 15px;
@@ -48,7 +51,7 @@ body {
display: flex;
justify-content: space-between;
height: 30px;
margin-bottom: 10px;
margin-bottom: 15px;
.rss-image {
width: 30px;
@@ -58,16 +61,18 @@ body {
.rss-info {
width: 180px;
cursor: pointer;
display: block;
display: flex;
text-decoration: none;
color: #000;
line-height: 1;
flex-direction: column;
justify-content: space-between;
.rss-title {
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-bottom: 1px;
}
.rss-url {
@@ -92,6 +97,7 @@ body {
border-radius: 4px;
cursor: pointer;
box-sizing: border-box;
text-decoration: none;
&:hover {
color: #fff;
+7
View File
@@ -2,6 +2,7 @@ module.exports = {
'bilibili.com': {
www: [{
title: 'bilibili - 分区视频',
description: 'https://docs.rsshub.app/social-media.html#%E5%88%86%E5%8C%BA%E8%A7%86%E9%A2%91',
source: '/v/*tpath',
target: (params) => {
let tid;
@@ -9,16 +10,20 @@ module.exports = {
case 'douga/mad':
tid = '24';
break;
default:
return false;
}
return `/bilibili/partion/${tid}`;
},
}],
space: [{
title: 'bilibili - UP 主动态',
description: 'https://docs.rsshub.app/social-media.html#up-%E4%B8%BB%E5%8A%A8%E6%80%81',
source: '/:uid',
target: '/bilibili/user/dynamic/:uid'
}, {
title: 'bilibili - UP 主投稿',
description: 'https://docs.rsshub.app/social-media.html#up-%E4%B8%BB%E6%8A%95%E7%A8%BF',
source: '/:uid',
target: '/bilibili/user/video/:uid'
}],
@@ -26,12 +31,14 @@ module.exports = {
'weibo.com': {
'.': [{
title: '微博 - 博主',
description: 'https://docs.rsshub.app/social-media.html#%E5%8D%9A%E4%B8%BB',
source: '/u/:id',
target: '/weibo/user/:uid',
script: '{uid: $CONFIG.uid}',
}],
'.': [{
title: '微博 - 博主',
description: 'https://docs.rsshub.app/social-media.html#%E5%8D%9A%E4%B8%BB',
source: '/:id',
target: '/weibo/user/:uid',
script: '({uid: document.querySelector(\'head\').innerHTML.match(/\\$CONFIG\\[\'uid\']=\'(\\d+)\'/)[1]})',
+25 -4
View File
@@ -12,7 +12,7 @@ chrome.browserAction.setBadgeBackgroundColor({
function setBadge (id) {
chrome.browserAction.setBadgeText({
text: ((window.pageRSS.length + window.pageRSSHub.length) || '') + '',
text: ((window.pageRSS.length + window.pageRSSHub.length) || (window.websiteRSSHub.length ? '·' : '')) + '',
tabId: id,
});
}
@@ -26,8 +26,10 @@ function ruleHandler (rule, params, tabId, done) {
reaultWithParams = rule.target;
}
for (const param in params) {
reaultWithParams = reaultWithParams.replace(`/:${param}`, `/${params[param]}`);
if (reaultWithParams) {
for (const param in params) {
reaultWithParams = reaultWithParams.replace(`/:${param}`, `/${params[param]}`);
}
}
return reaultWithParams;
@@ -59,6 +61,7 @@ function getPageRSSHub (url, tabId, done) {
path: ru.source,
handler: index,
}]);
console.log(url);
const result = router.recognize(new URL(url).pathname.replace(/\/$/, ''));
if (result && result[0]) {
recognized.push(result[0]);
@@ -89,7 +92,25 @@ function getPageRSSHub (url, tabId, done) {
}
function getWebsiteRSSHub (url) {
return [];
const parsedDomain = parseDomain(url);
if (parsedDomain) {
const domain = parsedDomain.domain + '.' + parsedDomain.tld;
if (rules[domain]) {
const domainRules = [];
for (const subdomainRules in rules[domain]) {
domainRules.push(...rules[domain][subdomainRules]);
}
console.log(domainRules);
return domainRules.map((rule) => ({
title: rule.title,
url: rule.description,
}));
} else {
return [];
}
} else {
return [];
}
}
export function handleRSS (feeds) {
+5 -1
View File
@@ -12,7 +12,10 @@ function generateList (type, list) {
<div class="rss-title">${item.title}</div>
<div class="rss-url">${item.url}</div>
</a>
<div class="rss-action rss-copy" data-clipboard-text="${item.url}">复制</div>
${type === 'website-rsshub' ?
`<a href="${item.url}" class="rss-action">文档</a>` :
'<div class="rss-action rss-copy" data-clipboard-text="${item.url}">复制</div>'
}
</li>
`
});
@@ -25,6 +28,7 @@ function generateList (type, list) {
const background = chrome.extension.getBackgroundPage();
generateList('page-rss', background.pageRSS);
generateList('page-rsshub', background.pageRSSHub);
generateList('website-rsshub', background.websiteRSSHub);
const clipboard = new ClipboardJS('.rss-copy');
clipboard.on('success', function(e) {