@@ -0,0 +1,5 @@
|
||||
.github/
|
||||
.vscode/
|
||||
dist
|
||||
release
|
||||
*.config.js
|
||||
@@ -1,5 +1,64 @@
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": 0,
|
||||
"block-scoped-var": 1,
|
||||
"curly": 1,
|
||||
"eqeqeq": 1,
|
||||
"no-global-assign": 1,
|
||||
"no-implicit-globals": 1,
|
||||
"no-labels": 1,
|
||||
"no-multi-str": 1,
|
||||
"comma-spacing": 1,
|
||||
"comma-style": 1,
|
||||
"func-call-spacing": 1,
|
||||
"keyword-spacing": 1,
|
||||
"linebreak-style": 1,
|
||||
"lines-around-comment": 1,
|
||||
"no-multiple-empty-lines": 1,
|
||||
"space-infix-ops": 1,
|
||||
"arrow-spacing": 1,
|
||||
"no-var": 1,
|
||||
"prefer-const": 1,
|
||||
"no-unsafe-negation": 1,
|
||||
"array-callback-return": 1,
|
||||
"dot-notation": 1,
|
||||
"no-eval": 1,
|
||||
"no-extend-native": 1,
|
||||
"no-extra-label": 1,
|
||||
"semi": 1,
|
||||
"space-before-blocks": 1,
|
||||
"space-in-parens": 1,
|
||||
"space-unary-ops": 1,
|
||||
"spaced-comment": 1,
|
||||
"arrow-body-style": 1,
|
||||
"arrow-parens": 1,
|
||||
"no-restricted-imports": 1,
|
||||
"no-duplicate-imports": 1,
|
||||
"no-useless-computed-key": 1,
|
||||
"no-useless-rename": 1,
|
||||
"rest-spread-spacing": 1,
|
||||
"no-trailing-spaces": 1,
|
||||
"no-control-regex": 0,
|
||||
"prettier/prettier": 0,
|
||||
"no-await-in-loop": 1,
|
||||
"require-atomic-updates": 0,
|
||||
"no-prototype-builtins": 0,
|
||||
"no-undef": 0,
|
||||
"vue/no-use-v-if-with-v-for": "off",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package.json
|
||||
package-lock.json
|
||||
.github/
|
||||
.vscode/
|
||||
dist
|
||||
release
|
||||
*.config.js
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"printWidth": 233,
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"arrowParens": "always"
|
||||
}
|
||||
@@ -9,6 +9,7 @@ before_install:
|
||||
- mkdir release
|
||||
|
||||
script:
|
||||
- npm run format:check
|
||||
- npm run release
|
||||
|
||||
deploy:
|
||||
|
||||
+15
-2
@@ -6,7 +6,10 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "webpack -w --mode=production --progress --display-error-details --colors",
|
||||
"build": "webpack --mode=production --progress --display-error-details --colors",
|
||||
"release": "npm run build && zip -r release/radar.zip dist"
|
||||
"release": "npm run build && zip -r release/radar.zip dist",
|
||||
"format": "eslint \"**/*.js\" --fix && prettier \"**/*.{js,scss,less}\" --write",
|
||||
"format:staged": "eslint \"**/*.js\" --fix && pretty-quick --staged --verbose --pattern \"**/*.{js,scss,less}\"",
|
||||
"format:check": "eslint \"**/*.js\" && prettier-check \"**/*.{js,scss,less}\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -16,6 +19,9 @@
|
||||
"rsshub",
|
||||
"rss"
|
||||
],
|
||||
"gitHooks": {
|
||||
"pre-commit": "npm run format:staged"
|
||||
},
|
||||
"author": "DIYgod",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
@@ -31,13 +37,19 @@
|
||||
"copy-webpack-plugin": "5.0.4",
|
||||
"css-loader": "3.2.0",
|
||||
"cssnano": "4.1.10",
|
||||
"eslint": "6.2.0",
|
||||
"eslint-config-prettier": "6.0.0",
|
||||
"eslint-loader": "2.2.1",
|
||||
"eslint-plugin-prettier": "3.1.0",
|
||||
"file-loader": "4.2.0",
|
||||
"less": "3.9.0",
|
||||
"less-loader": "5.0.0",
|
||||
"mini-css-extract-plugin": "0.8.0",
|
||||
"node-sass": "4.12.0",
|
||||
"postcss-loader": "3.0.0",
|
||||
"prettier": "1.18.2",
|
||||
"prettier-check": "2.0.0",
|
||||
"pretty-quick": "1.11.1",
|
||||
"sass-loader": "7.2.0",
|
||||
"svg-inline-loader": "0.8.0",
|
||||
"template-string-optimize-loader": "3.0.0",
|
||||
@@ -46,7 +58,8 @@
|
||||
"vue-loader": "15.7.1",
|
||||
"vue-template-compiler": "2.6.10",
|
||||
"webpack": "4.39.2",
|
||||
"webpack-cli": "3.3.6"
|
||||
"webpack-cli": "3.3.6",
|
||||
"yorkie": "2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"clipboard": "2.0.4",
|
||||
|
||||
@@ -2,4 +2,4 @@ $--color-primary: #f5712c;
|
||||
|
||||
$--font-path: '~element-ui/lib/theme-chalk/fonts';
|
||||
|
||||
@import "~element-ui/packages/theme-chalk/src/index";
|
||||
@import '~element-ui/packages/theme-chalk/src/index';
|
||||
|
||||
+9
-9
@@ -2,7 +2,7 @@ body {
|
||||
min-width: 310px;
|
||||
margin: 0;
|
||||
padding: 20px 20px 5px;
|
||||
font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
|
||||
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
||||
|
||||
&.something {
|
||||
.no-rss {
|
||||
@@ -24,7 +24,7 @@ body {
|
||||
width: 18px;
|
||||
display: inline-block;
|
||||
fill: #666;
|
||||
transition: .3s;
|
||||
transition: 0.3s;
|
||||
margin-left: 5px;
|
||||
|
||||
&:hover {
|
||||
@@ -43,7 +43,7 @@ body {
|
||||
font-size: 16px;
|
||||
margin: 0 0 15px;
|
||||
}
|
||||
|
||||
|
||||
ul,
|
||||
li {
|
||||
padding: 0;
|
||||
@@ -70,7 +70,7 @@ body {
|
||||
}
|
||||
|
||||
a {
|
||||
color: #FF8549;
|
||||
color: #ff8549;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ body {
|
||||
border: 1px solid #f5712c;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
transition: .3s;
|
||||
transition: 0.3s;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
box-sizing: border-box;
|
||||
@@ -159,12 +159,12 @@ body {
|
||||
}
|
||||
|
||||
&.rss-submitto-inoreader {
|
||||
color: #0099EB;
|
||||
border: 1px solid #0099EB;
|
||||
color: #0099eb;
|
||||
border: 1px solid #0099eb;
|
||||
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background: #0099EB;
|
||||
background: #0099eb;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,4 +179,4 @@ body {
|
||||
.rss-action {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-12
@@ -2,20 +2,28 @@ import { handleRSS, removeRSS, addPageRSS, getAllRSS } from './utils';
|
||||
import { getConfig, saveConfig } from '../common/config';
|
||||
|
||||
chrome.tabs.onActivated.addListener((tab) => {
|
||||
chrome.tabs.sendMessage(tab.tabId, {
|
||||
text: 'getPageRSS',
|
||||
}, (feeds) => {
|
||||
handleRSS(feeds, tab.tabId, true);
|
||||
});
|
||||
chrome.tabs.sendMessage(
|
||||
tab.tabId,
|
||||
{
|
||||
text: 'getPageRSS',
|
||||
},
|
||||
(feeds) => {
|
||||
handleRSS(feeds, tab.tabId, true);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
if (changeInfo.url && tab.active) {
|
||||
chrome.tabs.sendMessage(tab.id, {
|
||||
text: 'getPageRSS',
|
||||
}, (feeds) => {
|
||||
handleRSS(feeds, tab.id);
|
||||
});
|
||||
chrome.tabs.sendMessage(
|
||||
tab.id,
|
||||
{
|
||||
text: 'getPageRSS',
|
||||
},
|
||||
(feeds) => {
|
||||
handleRSS(feeds, tab.id);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,7 +58,7 @@ getConfig((config) => {
|
||||
chrome.notifications.onClicked.addListener((id) => {
|
||||
if (id === 'RSSHubRadarUpdate') {
|
||||
chrome.tabs.create({
|
||||
url: 'https://github.com/DIYgod/RSSHub-Radar/releases'
|
||||
url: 'https://github.com/DIYgod/RSSHub-Radar/releases',
|
||||
});
|
||||
chrome.notifications.clear('RSSHubRadarUpdate');
|
||||
}
|
||||
@@ -58,4 +66,4 @@ getConfig((config) => {
|
||||
config.version = VERSION;
|
||||
saveConfig(config);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+87
-64
@@ -5,13 +5,13 @@ import { getConfig } from '../common/config';
|
||||
let config;
|
||||
let rules = {};
|
||||
import RSSParser from 'rss-parser';
|
||||
let rssParser = new RSSParser();
|
||||
const rssParser = new RSSParser();
|
||||
|
||||
window.pageRSS = {};
|
||||
window.pageRSSHub = {};
|
||||
window.websiteRSSHub = {};
|
||||
|
||||
function schedule(time = +new Date + config.refreshTimeout * 1000) {
|
||||
function schedule(time = +new Date() + config.refreshTimeout * 1000) {
|
||||
chrome.alarms.create('refreshRules', {
|
||||
when: time,
|
||||
periodInMinutes: config.refreshTimeout / 60,
|
||||
@@ -20,7 +20,7 @@ function schedule(time = +new Date + config.refreshTimeout * 1000) {
|
||||
|
||||
function initSchedule() {
|
||||
getRulesDate((lastDate) => {
|
||||
if (!lastDate || (+new Date - lastDate > config.refreshTimeout * 1000)) {
|
||||
if (!lastDate || +new Date() - lastDate > config.refreshTimeout * 1000) {
|
||||
refreshRules();
|
||||
schedule();
|
||||
} else {
|
||||
@@ -46,7 +46,7 @@ chrome.alarms.onAlarm.addListener((alarm) => {
|
||||
}
|
||||
});
|
||||
|
||||
chrome.idle.onStateChanged.addListener(newState => {
|
||||
chrome.idle.onStateChanged.addListener((newState) => {
|
||||
if (newState === 'active') {
|
||||
initSchedule();
|
||||
}
|
||||
@@ -65,13 +65,14 @@ chrome.browserAction.setBadgeBackgroundColor({
|
||||
color: '#FF2800',
|
||||
});
|
||||
|
||||
chrome.browserAction.setBadgeTextColor && chrome.browserAction.setBadgeTextColor({
|
||||
color: '#fff'
|
||||
});
|
||||
chrome.browserAction.setBadgeTextColor &&
|
||||
chrome.browserAction.setBadgeTextColor({
|
||||
color: '#fff',
|
||||
});
|
||||
|
||||
function setBadge(tabId) {
|
||||
chrome.browserAction.setBadgeText({
|
||||
text: config.notice.badge ? (((window.pageRSS[tabId].length + window.pageRSSHub[tabId].length) || (window.websiteRSSHub[tabId].length ? ' ' : '')) + '') : '',
|
||||
text: config.notice.badge ? (window.pageRSS[tabId].length + window.pageRSSHub[tabId].length || (window.websiteRSSHub[tabId].length ? ' ' : '')) + '' : '',
|
||||
tabId,
|
||||
});
|
||||
}
|
||||
@@ -92,19 +93,23 @@ function ruleHandler(rule, params, tabId, url, success, fail) {
|
||||
}
|
||||
|
||||
return reaultWithParams;
|
||||
}
|
||||
};
|
||||
if (rule.script) {
|
||||
chrome.tabs.sendMessage(tabId, {
|
||||
text: 'executeScript',
|
||||
code: rule.script
|
||||
}, (result) => {
|
||||
params = Object.assign({}, result, params);
|
||||
if (!rule.verification || rule.verification(params)) {
|
||||
success(run());
|
||||
} else {
|
||||
fail();
|
||||
chrome.tabs.sendMessage(
|
||||
tabId,
|
||||
{
|
||||
text: 'executeScript',
|
||||
code: rule.script,
|
||||
},
|
||||
(result) => {
|
||||
params = Object.assign({}, result, params);
|
||||
if (!rule.verification || rule.verification(params)) {
|
||||
success(run());
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
} else {
|
||||
if (!rule.verification || rule.verification(params)) {
|
||||
success(run());
|
||||
@@ -127,10 +132,12 @@ function getPageRSSHub(url, tabId, done) {
|
||||
if (ru.source instanceof Array) {
|
||||
ru.source.forEach((source) => {
|
||||
const router = new RouteRecognizer();
|
||||
router.add([{
|
||||
path: source,
|
||||
handler: index,
|
||||
}]);
|
||||
router.add([
|
||||
{
|
||||
path: source,
|
||||
handler: index,
|
||||
},
|
||||
]);
|
||||
const result = router.recognize(new URL(url).pathname.replace(/\/$/, ''));
|
||||
if (result && result[0]) {
|
||||
recognized.push(result[0]);
|
||||
@@ -138,10 +145,12 @@ function getPageRSSHub(url, tabId, done) {
|
||||
});
|
||||
} else if (typeof ru.source === 'string') {
|
||||
const router = new RouteRecognizer();
|
||||
router.add([{
|
||||
path: ru.source,
|
||||
handler: index,
|
||||
}]);
|
||||
router.add([
|
||||
{
|
||||
path: ru.source,
|
||||
handler: index,
|
||||
},
|
||||
]);
|
||||
const result = router.recognize(new URL(url).pathname.replace(/\/$/, ''));
|
||||
if (result && result[0]) {
|
||||
recognized.push(result[0]);
|
||||
@@ -150,27 +159,37 @@ function getPageRSSHub(url, tabId, done) {
|
||||
}
|
||||
});
|
||||
const result = [];
|
||||
Promise.all(recognized.map((recog) => {
|
||||
return new Promise((resolve) => {
|
||||
ruleHandler(rule[recog.handler], recog.params, tabId, url, (parsed) => {
|
||||
if (parsed) {
|
||||
result.push({
|
||||
title: formatBlank(rules[domain]._name ? '当前' : '', rule[recog.handler].title),
|
||||
url: '{rsshubDomain}' + parsed,
|
||||
});
|
||||
} else {
|
||||
result.push({
|
||||
title: formatBlank(rules[domain]._name ? '当前' : '', rule[recog.handler].title),
|
||||
url: rule[recog.handler].docs,
|
||||
isDocs: true,
|
||||
});
|
||||
}
|
||||
resolve();
|
||||
}, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
})).then(() => {
|
||||
Promise.all(
|
||||
recognized.map(
|
||||
(recog) =>
|
||||
new Promise((resolve) => {
|
||||
ruleHandler(
|
||||
rule[recog.handler],
|
||||
recog.params,
|
||||
tabId,
|
||||
url,
|
||||
(parsed) => {
|
||||
if (parsed) {
|
||||
result.push({
|
||||
title: formatBlank(rules[domain]._name ? '当前' : '', rule[recog.handler].title),
|
||||
url: '{rsshubDomain}' + parsed,
|
||||
});
|
||||
} else {
|
||||
result.push({
|
||||
title: formatBlank(rules[domain]._name ? '当前' : '', rule[recog.handler].title),
|
||||
url: rule[recog.handler].docs,
|
||||
isDocs: true,
|
||||
});
|
||||
}
|
||||
resolve();
|
||||
},
|
||||
() => {
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
})
|
||||
)
|
||||
).then(() => {
|
||||
done(result);
|
||||
});
|
||||
} else {
|
||||
@@ -183,7 +202,7 @@ function getPageRSSHub(url, tabId, done) {
|
||||
|
||||
function formatBlank(str1, str2) {
|
||||
if (str1 && str2) {
|
||||
return str1 + ((str1[str1.length - 1].match(/[a-zA-Z0-9]/) || str2[0].match(/[a-zA-Z0-9]/)) ? ' ' : '') + str2;
|
||||
return str1 + (str1[str1.length - 1].match(/[a-zA-Z0-9]/) || str2[0].match(/[a-zA-Z0-9]/) ? ' ' : '') + str2;
|
||||
} else {
|
||||
return (str1 || '') + (str2 || '');
|
||||
}
|
||||
@@ -218,10 +237,11 @@ export function handleRSS(feeds, tabId, useCache) {
|
||||
setBadge(tabId);
|
||||
} else {
|
||||
chrome.tabs.get(tabId, (tab) => {
|
||||
feeds && feeds.forEach((feed) => {
|
||||
feed.image = tab.favIconUrl || feed.image;
|
||||
});
|
||||
window.pageRSS[tabId] = feeds && feeds.filter((feed) => !feed.uncertain) || [];
|
||||
feeds &&
|
||||
feeds.forEach((feed) => {
|
||||
feed.image = tab.favIconUrl || feed.image;
|
||||
});
|
||||
window.pageRSS[tabId] = (feeds && feeds.filter((feed) => !feed.uncertain)) || [];
|
||||
|
||||
window.websiteRSSHub[tabId] = getWebsiteRSSHub(tab.url) || [];
|
||||
|
||||
@@ -231,15 +251,18 @@ export function handleRSS(feeds, tabId, useCache) {
|
||||
});
|
||||
});
|
||||
|
||||
feeds && feeds.filter((feed) => feed.uncertain).forEach((feed) => {
|
||||
rssParser.parseURL(feed.url, (err, result) => {
|
||||
if (!err) {
|
||||
feed.title = result.title;
|
||||
window.pageRSS[tabId].push(feed);
|
||||
setBadge(tabId);
|
||||
}
|
||||
});
|
||||
});
|
||||
feeds &&
|
||||
feeds
|
||||
.filter((feed) => feed.uncertain)
|
||||
.forEach((feed) => {
|
||||
rssParser.parseURL(feed.url, (err, result) => {
|
||||
if (!err) {
|
||||
feed.title = result.title;
|
||||
window.pageRSS[tabId].push(feed);
|
||||
setBadge(tabId);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,5 +287,5 @@ export function getAllRSS(tabId) {
|
||||
pageRSS: window.pageRSS[tabId] || {},
|
||||
websiteRSSHub: window.websiteRSSHub[tabId] || {},
|
||||
pageRSSHub: window.pageRSSHub[tabId] || {},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+11
-8
@@ -12,7 +12,7 @@ export const defaultConfig = {
|
||||
refreshTimeout: 5 * 60 * 60,
|
||||
};
|
||||
|
||||
export function getConfig (success) {
|
||||
export function getConfig(success) {
|
||||
if (chrome.storage) {
|
||||
chrome.storage.sync.get('config', (result) => {
|
||||
success(Object.assign({}, defaultConfig, result.config));
|
||||
@@ -22,16 +22,19 @@ export function getConfig (success) {
|
||||
}
|
||||
}
|
||||
|
||||
export function saveConfig (config, success) {
|
||||
export function saveConfig(config, success) {
|
||||
if (!config.rsshubDomain) {
|
||||
config.rsshubDomain = defaultConfig.rsshubDomain;
|
||||
}
|
||||
config.rsshubDomain = config.rsshubDomain.replace(/\/$/, '');
|
||||
if (chrome.storage) {
|
||||
chrome.storage.sync.set({
|
||||
config,
|
||||
}, () => {
|
||||
success && success();
|
||||
});
|
||||
chrome.storage.sync.set(
|
||||
{
|
||||
config,
|
||||
},
|
||||
() => {
|
||||
success && success();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-15
@@ -1,18 +1,16 @@
|
||||
export function refreshRules (success) {
|
||||
fetch('https://raw.githubusercontent.com/DIYgod/RSSHub/master/assets/radar-rules.js')
|
||||
.then((response) => {
|
||||
response.text()
|
||||
.then((text) => {
|
||||
chrome.storage.local.set({
|
||||
rules: text,
|
||||
rulesDate: +new Date(),
|
||||
});
|
||||
success && success();
|
||||
});
|
||||
export function refreshRules(success) {
|
||||
fetch('https://raw.githubusercontent.com/DIYgod/RSSHub/master/assets/radar-rules.js').then((response) => {
|
||||
response.text().then((text) => {
|
||||
chrome.storage.local.set({
|
||||
rules: text,
|
||||
rulesDate: +new Date(),
|
||||
});
|
||||
success && success();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function getRules (success) {
|
||||
export function getRules(success) {
|
||||
chrome.storage.local.get('rules', (result) => {
|
||||
if (result && result.rules) {
|
||||
success(eval(result.rules), result.rules);
|
||||
@@ -24,7 +22,7 @@ export function getRules (success) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getRulesDate (success) {
|
||||
export function getRulesDate(success) {
|
||||
chrome.storage.local.get('rulesDate', (result) => {
|
||||
if (result && result.rulesDate) {
|
||||
success(result.rulesDate);
|
||||
@@ -34,9 +32,9 @@ export function getRulesDate (success) {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateRules (text, success) {
|
||||
export function updateRules(text, success) {
|
||||
chrome.storage.local.set({
|
||||
rules: text,
|
||||
});
|
||||
success && success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function secondToTime (second) {
|
||||
export function secondToTime(second) {
|
||||
const hour = Math.floor(second / 3600);
|
||||
const min = Math.floor((second - hour * 3600) / 60);
|
||||
return `${hour ? hour + '小时' : ''}${min}分钟`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||
chrome.runtime.sendMessage(null, {
|
||||
text: 'setPageRSS',
|
||||
feeds: getPageRSS(),
|
||||
});
|
||||
});
|
||||
|
||||
+28
-20
@@ -1,28 +1,34 @@
|
||||
import RSSParser from 'rss-parser';
|
||||
let rssParser = new RSSParser();
|
||||
const rssParser = new RSSParser();
|
||||
|
||||
let pageRSS = null;
|
||||
const defaultTitle = document.querySelector('title') && document.querySelector('title').innerHTML && document.querySelector('title').innerHTML.replace(/<!\[CDATA\[(.*)]]>/, (match, p1) => p1).trim();
|
||||
const image = document.querySelector('link[rel~="icon"]') && handleUrl(document.querySelector('link[rel~="icon"]').getAttribute('href')) || document.location.origin + '/favicon.ico';
|
||||
const defaultTitle =
|
||||
document.querySelector('title') &&
|
||||
document.querySelector('title').innerHTML &&
|
||||
document
|
||||
.querySelector('title')
|
||||
.innerHTML.replace(/<!\[CDATA\[(.*)]]>/, (match, p1) => p1)
|
||||
.trim();
|
||||
const image = (document.querySelector('link[rel~="icon"]') && handleUrl(document.querySelector('link[rel~="icon"]').getAttribute('href'))) || document.location.origin + '/favicon.ico';
|
||||
|
||||
function handleUrl (url) {
|
||||
function handleUrl(url) {
|
||||
if (url.startsWith('//')) {
|
||||
url = document.location.protocol + url;
|
||||
} else if (url.startsWith('/')) {
|
||||
url = document.location.origin + url;
|
||||
} else if (!(/^(http|https):\/\//i.test(url))) {
|
||||
} else if (!/^(http|https):\/\//i.test(url)) {
|
||||
url = document.location.href + '/' + url.replace(/^\//g, '');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function getPageRSS () {
|
||||
export function getPageRSS() {
|
||||
if (!pageRSS) {
|
||||
pageRSS = [];
|
||||
const saved = {};
|
||||
|
||||
// links
|
||||
let types = [
|
||||
const types = [
|
||||
'application/rss+xml',
|
||||
'application/atom+xml',
|
||||
'application/rdf+xml',
|
||||
@@ -34,15 +40,15 @@ export function getPageRSS () {
|
||||
'text/rdf+xml',
|
||||
'text/rss',
|
||||
'text/atom',
|
||||
'text/rdf'
|
||||
'text/rdf',
|
||||
];
|
||||
let links = document.querySelectorAll('link[type]');
|
||||
const links = document.querySelectorAll('link[type]');
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
if (links[i].hasAttribute('type') && types.indexOf(links[i].getAttribute('type')) !== -1) {
|
||||
let feed_url = links[i].getAttribute('href');
|
||||
const feed_url = links[i].getAttribute('href');
|
||||
|
||||
if (feed_url) {
|
||||
let feed = {
|
||||
const feed = {
|
||||
url: handleUrl(feed_url),
|
||||
title: links[i].getAttribute('title') || defaultTitle,
|
||||
image,
|
||||
@@ -54,17 +60,19 @@ export function getPageRSS () {
|
||||
}
|
||||
|
||||
// a
|
||||
let aEles = document.querySelectorAll('a');
|
||||
const aEles = document.querySelectorAll('a');
|
||||
const check = /([^a-zA-Z]|^)rss([^a-zA-Z]|$)/i;
|
||||
for (let i = 0; i < aEles.length; i++) {
|
||||
if (aEles[i].hasAttribute('href')) {
|
||||
const href = aEles[i].getAttribute('href');
|
||||
|
||||
if (href.match(/\/(feed|rss|atom)(\.(xml|rss|atom))?$/)
|
||||
|| aEles[i].hasAttribute('title') && aEles[i].getAttribute('title').match(check)
|
||||
|| aEles[i].hasAttribute('class') && aEles[i].getAttribute('class').match(check)
|
||||
|| aEles[i].innerText && aEles[i].innerText.match(check)) {
|
||||
let feed = {
|
||||
if (
|
||||
href.match(/\/(feed|rss|atom)(\.(xml|rss|atom))?$/) ||
|
||||
(aEles[i].hasAttribute('title') && aEles[i].getAttribute('title').match(check)) ||
|
||||
(aEles[i].hasAttribute('class') && aEles[i].getAttribute('class').match(check)) ||
|
||||
(aEles[i].innerText && aEles[i].innerText.match(check))
|
||||
) {
|
||||
const feed = {
|
||||
url: handleUrl(href),
|
||||
title: aEles[i].innerText || aEles[i].getAttribute('title') || defaultTitle,
|
||||
image,
|
||||
@@ -99,7 +107,7 @@ export function getPageRSS () {
|
||||
},
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
saved[document.location.href] = 1;
|
||||
@@ -107,11 +115,11 @@ export function getPageRSS () {
|
||||
return pageRSS;
|
||||
}
|
||||
|
||||
export function runCode (code) {
|
||||
export function runCode(code) {
|
||||
try {
|
||||
return eval(code);
|
||||
} catch (e) {
|
||||
console.warn('RSS Radar error: ', e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import '../../css/options.scss'
|
||||
import '../../css/options.scss';
|
||||
import Vue from 'vue';
|
||||
import VueRouter from 'vue-router';
|
||||
import App from './App.vue';
|
||||
@@ -27,17 +27,12 @@ Vue.prototype.$loading = Loading.service;
|
||||
Vue.prototype.$message = Message;
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
const routes = [
|
||||
{ path: '/', redirect: '/setting' },
|
||||
{ path: '/setting', component: Setting },
|
||||
{ path: '/list', component: List },
|
||||
{ path: '/about', component: About },
|
||||
];
|
||||
const routes = [{ path: '/', redirect: '/setting' }, { path: '/setting', component: Setting }, { path: '/list', component: List }, { path: '/about', component: About }];
|
||||
const router = new VueRouter({
|
||||
routes,
|
||||
});
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
render: (h) => h(App),
|
||||
router,
|
||||
}).$mount('#app');
|
||||
|
||||
+55
-41
@@ -17,13 +17,20 @@ function generateList(type, list) {
|
||||
<div class="rss-title">${item.title}</div>
|
||||
<div class="rss-url">${url.replace('https://', '').replace('http://', '')}</div>
|
||||
</a>
|
||||
${item.isDocs ? `<a href="${url}" class="rss-action">文档</a>` : `<div class="rss-action rss-copy" data-clipboard-text="${url}">复制</div>
|
||||
${config.submitto.ttrss && config.submitto.ttrssDomain ? `<a href="${config.submitto.ttrssDomain.replace(/\/$/, '')}/public.php?op=subscribe&feed_url=${url}" class="rss-action rss-submitto-ttrss">订阅到 TTRSS</a>` : ''}
|
||||
${
|
||||
item.isDocs
|
||||
? `<a href="${url}" class="rss-action">文档</a>`
|
||||
: `<div class="rss-action rss-copy" data-clipboard-text="${url}">复制</div>
|
||||
${
|
||||
config.submitto.ttrss && config.submitto.ttrssDomain
|
||||
? `<a href="${config.submitto.ttrssDomain.replace(/\/$/, '')}/public.php?op=subscribe&feed_url=${url}" class="rss-action rss-submitto-ttrss">订阅到 TTRSS</a>`
|
||||
: ''
|
||||
}
|
||||
${config.submitto.feedly ? `<a href="https://feedly.com/i/subscription/feed/${url}" class="rss-action rss-submitto-feedly">订阅到 Feedly</a>` : ''}
|
||||
${config.submitto.inoreader ? `<a href="https://www.inoreader.com/?add_feed=${url}" class="rss-action rss-submitto-inoreader">订阅到 Inoreader</a>` : ''}`
|
||||
}
|
||||
</li>
|
||||
`
|
||||
`;
|
||||
});
|
||||
document.querySelector(`.${type} ul`).innerHTML = result;
|
||||
document.querySelector(`.${type}`).style.display = 'block';
|
||||
@@ -34,45 +41,52 @@ function generateList(type, list) {
|
||||
document.querySelector('.icons-setting').innerHTML = settingIcon;
|
||||
document.querySelector('.icons-about').innerHTML = aboutIcon;
|
||||
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, (tabs) => {
|
||||
const tabId = tabs[0].id;
|
||||
chrome.tabs.query(
|
||||
{
|
||||
active: true,
|
||||
currentWindow: true,
|
||||
},
|
||||
(tabs) => {
|
||||
const tabId = tabs[0].id;
|
||||
|
||||
getConfig((conf) => {
|
||||
config = conf;
|
||||
chrome.runtime.sendMessage(null, {
|
||||
text: 'getAllRSS',
|
||||
tabId: tabId
|
||||
}, (feeds) => {
|
||||
generateList('page-rss', feeds.pageRSS);
|
||||
generateList('page-rsshub', feeds.pageRSSHub);
|
||||
generateList('website-rsshub', feeds.websiteRSSHub);
|
||||
|
||||
const clipboard = new ClipboardJS('.rss-copy');
|
||||
clipboard.on('success', function (e) {
|
||||
e.trigger.innerHTML = '已复制';
|
||||
setTimeout(() => {
|
||||
e.trigger.innerHTML = '复制';
|
||||
}, 1000);
|
||||
});
|
||||
getConfig((conf) => {
|
||||
config = conf;
|
||||
chrome.runtime.sendMessage(
|
||||
null,
|
||||
{
|
||||
text: 'getAllRSS',
|
||||
tabId: tabId,
|
||||
},
|
||||
(feeds) => {
|
||||
generateList('page-rss', feeds.pageRSS);
|
||||
generateList('page-rsshub', feeds.pageRSSHub);
|
||||
generateList('website-rsshub', feeds.websiteRSSHub);
|
||||
|
||||
document.querySelectorAll('.rss-image').forEach((ele) => {
|
||||
ele.addEventListener('error', function () {
|
||||
this.setAttribute('src', './rsshub.png');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('a').forEach((ele) => {
|
||||
ele.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
chrome.tabs.create({
|
||||
url: ele.getAttribute('href'),
|
||||
const clipboard = new ClipboardJS('.rss-copy');
|
||||
clipboard.on('success', function(e) {
|
||||
e.trigger.innerHTML = '已复制';
|
||||
setTimeout(() => {
|
||||
e.trigger.innerHTML = '复制';
|
||||
}, 1000);
|
||||
});
|
||||
window.close();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.rss-image').forEach((ele) => {
|
||||
ele.addEventListener('error', function() {
|
||||
this.setAttribute('src', './rsshub.png');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('a').forEach((ele) => {
|
||||
ele.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
chrome.tabs.create({
|
||||
url: ele.getAttribute('href'),
|
||||
});
|
||||
window.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user