feat: disable remote rules for firefox
This commit is contained in:
@@ -23,6 +23,7 @@ export const defaultConfig = {
|
||||
local: false,
|
||||
},
|
||||
refreshTimeout: 5 * 60 * 60,
|
||||
enableRemoteRules: !navigator.userAgent.match(/firefox/i),
|
||||
};
|
||||
|
||||
export function getConfig(success) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+27
-16
@@ -1,25 +1,36 @@
|
||||
import { defaultConfig } from './config';
|
||||
import defaultRules from './radar-rules';
|
||||
|
||||
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(),
|
||||
if (defaultConfig.enableRemoteRules) {
|
||||
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();
|
||||
});
|
||||
success && success();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
success && success();
|
||||
}
|
||||
}
|
||||
|
||||
export function getRules(success) {
|
||||
chrome.storage.local.get('rules', (result) => {
|
||||
if (result && result.rules) {
|
||||
success(result.rules);
|
||||
} else {
|
||||
refreshRules(() => {
|
||||
getRules(success);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (defaultConfig.enableRemoteRules) {
|
||||
chrome.storage.local.get('rules', (result) => {
|
||||
if (result && result.rules) {
|
||||
success(result.rules);
|
||||
} else {
|
||||
refreshRules(() => {
|
||||
getRules(success);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
success(defaultRules);
|
||||
}
|
||||
}
|
||||
|
||||
export function getRulesDate(success) {
|
||||
|
||||
@@ -12,6 +12,14 @@ window.addEventListener('message', (event) => {
|
||||
});
|
||||
});
|
||||
export function commandSandbox(command, data, callback) {
|
||||
if (data.rules && typeof data.rules === 'object') {
|
||||
try {
|
||||
callback(iframe.contentWindow[command](data));
|
||||
return;
|
||||
} catch (e) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
iframe.contentWindow.postMessage(
|
||||
{
|
||||
command: command,
|
||||
|
||||
@@ -54,13 +54,19 @@ export default {
|
||||
this.refreshTime();
|
||||
});
|
||||
getRules((rules) => {
|
||||
this.rulesText = rules;
|
||||
commandSandbox('getList', {
|
||||
rules,
|
||||
}, (rules) => {
|
||||
if (typeof rules === 'string') {
|
||||
this.rulesText = rules;
|
||||
commandSandbox('getList', {
|
||||
rules,
|
||||
}, (rules) => {
|
||||
this.rules = rules;
|
||||
this.loading = false;
|
||||
});
|
||||
} else {
|
||||
this.rulesText = JSON.stringify(rules, null, 4);
|
||||
this.rules = rules;
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -24,10 +24,11 @@
|
||||
</div>
|
||||
<div class="subtitle">规则更新</div>
|
||||
<div class="setting-item">
|
||||
<div class="setting-name">我会自动更新,你也可以</div>
|
||||
<div class="setting-input">
|
||||
<div class="setting-name" v-if="config.enableRemoteRules">我会自动更新,你也可以</div>
|
||||
<div class="setting-input" v-if="config.enableRemoteRules">
|
||||
<el-button style="width: 98px" size="medium" @click="refreshRu" :disabled="refreshDisabled">{{ refreshDisabled ? '更新中' : '立即更新' }}</el-button><el-progress :text-inside="true" :stroke-width="20" :percentage="percentage"></el-progress><span class="time">{{ time }}前更新,{{ leftTime }}后自动更新</span>
|
||||
</div>
|
||||
<div class="setting-name" v-if="!config.enableRemoteRules">远程更新被禁用</div>
|
||||
</div>
|
||||
<div class="subtitle">一键订阅</div>
|
||||
<div class="setting-item">
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { getPageRSSHub, getWebsiteRSSHub, getList } from './utils';
|
||||
|
||||
window.getPageRSSHub = getPageRSSHub;
|
||||
window.getWebsiteRSSHub = getWebsiteRSSHub;
|
||||
window.getList = getList;
|
||||
|
||||
window.addEventListener('message', function (event) {
|
||||
const command = event.data.command;
|
||||
switch (command) {
|
||||
|
||||
@@ -41,9 +41,13 @@ function formatBlank(str1, str2) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseRules(rules) {
|
||||
return typeof rules === 'string' ? window['lave'.split('').reverse().join('')](rules) : rules;
|
||||
}
|
||||
|
||||
export function getPageRSSHub(data) {
|
||||
const { url, html } = data;
|
||||
const rules = window['lave'.split('').reverse().join('')](data.rules);
|
||||
const rules = parseRules(data.rules);
|
||||
|
||||
const parsedDomain = psl.parse(new URL(url).hostname);
|
||||
if (parsedDomain && parsedDomain.domain) {
|
||||
@@ -62,7 +66,7 @@ export function getPageRSSHub(data) {
|
||||
const recognized = [];
|
||||
rule.forEach((ru, index) => {
|
||||
if (ru.source !== undefined) {
|
||||
if (ru.source instanceof Array) {
|
||||
if (Object.prototype.toString.call(ru.source) === '[object Array]') {
|
||||
ru.source.forEach((source) => {
|
||||
const router = new RouteRecognizer();
|
||||
router.add([
|
||||
@@ -138,7 +142,7 @@ export function getPageRSSHub(data) {
|
||||
|
||||
export function getWebsiteRSSHub(data) {
|
||||
const { url } = data;
|
||||
const rules = window['lave'.split('').reverse().join('')](data.rules);
|
||||
const rules = parseRules(data.rules);
|
||||
const parsedDomain = psl.parse(new URL(url).hostname);
|
||||
if (parsedDomain && parsedDomain.domain) {
|
||||
const domain = parsedDomain.domain;
|
||||
@@ -163,7 +167,7 @@ export function getWebsiteRSSHub(data) {
|
||||
}
|
||||
|
||||
export function getList(data) {
|
||||
const rules = window['lave'.split('').reverse().join('')](data.rules);
|
||||
const rules = parseRules(data.rules);
|
||||
for (const rule in rules) {
|
||||
for (const subrule in rules[rule]) {
|
||||
if (subrule[0] !== '_') {
|
||||
|
||||
Reference in New Issue
Block a user