fix: can't get RSS on Firefox private window
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { handleRSS, removeRSS, addPageRSS } from './utils';
|
||||
import { handleRSS, removeRSS, addPageRSS, getAllRSS } from './utils';
|
||||
import { getConfig, saveConfig } from '../common/config';
|
||||
|
||||
chrome.tabs.onActivated.addListener((tab) => {
|
||||
@@ -27,6 +27,9 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||
addPageRSS(msg.feed, sender.tab.id);
|
||||
}
|
||||
}
|
||||
if (msg.text === 'getAllRSS') {
|
||||
sendResponse(getAllRSS(msg.tabId));
|
||||
}
|
||||
});
|
||||
|
||||
chrome.tabs.onRemoved.addListener((tabId) => {
|
||||
|
||||
+22
-14
@@ -11,14 +11,14 @@ 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,
|
||||
});
|
||||
}
|
||||
|
||||
function initSchedule () {
|
||||
function initSchedule() {
|
||||
getRulesDate((lastDate) => {
|
||||
if (!lastDate || (+new Date - lastDate > config.refreshTimeout * 1000)) {
|
||||
refreshRules();
|
||||
@@ -69,14 +69,14 @@ chrome.browserAction.setBadgeTextColor && chrome.browserAction.setBadgeTextColor
|
||||
color: '#fff'
|
||||
});
|
||||
|
||||
function setBadge (tabId) {
|
||||
function setBadge(tabId) {
|
||||
chrome.browserAction.setBadgeText({
|
||||
text: config.notice.badge ? (((window.pageRSS[tabId].length + window.pageRSSHub[tabId].length) || (window.websiteRSSHub[tabId].length ? ' ' : '')) + '') : '',
|
||||
tabId,
|
||||
});
|
||||
}
|
||||
|
||||
function ruleHandler (rule, params, tabId, url, success, fail) {
|
||||
function ruleHandler(rule, params, tabId, url, success, fail) {
|
||||
const run = () => {
|
||||
let reaultWithParams;
|
||||
if (typeof rule.target === 'function') {
|
||||
@@ -84,13 +84,13 @@ function ruleHandler (rule, params, tabId, url, success, fail) {
|
||||
} else if (typeof rule.target === 'string') {
|
||||
reaultWithParams = rule.target;
|
||||
}
|
||||
|
||||
|
||||
if (reaultWithParams) {
|
||||
for (const param in params) {
|
||||
reaultWithParams = reaultWithParams.replace(`/:${param}`, `/${params[param]}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return reaultWithParams;
|
||||
}
|
||||
if (rule.script) {
|
||||
@@ -114,7 +114,7 @@ function ruleHandler (rule, params, tabId, url, success, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
function getPageRSSHub (url, tabId, done) {
|
||||
function getPageRSSHub(url, tabId, done) {
|
||||
const parsedDomain = parseDomain(url);
|
||||
if (parsedDomain) {
|
||||
const subdomain = parsedDomain.subdomain;
|
||||
@@ -181,7 +181,7 @@ function getPageRSSHub (url, tabId, done) {
|
||||
}
|
||||
}
|
||||
|
||||
function formatBlank (str1, str2) {
|
||||
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;
|
||||
} else {
|
||||
@@ -189,7 +189,7 @@ function formatBlank (str1, str2) {
|
||||
}
|
||||
}
|
||||
|
||||
function getWebsiteRSSHub (url) {
|
||||
function getWebsiteRSSHub(url) {
|
||||
const parsedDomain = parseDomain(url);
|
||||
if (parsedDomain) {
|
||||
const domain = parsedDomain.domain + '.' + parsedDomain.tld;
|
||||
@@ -213,7 +213,7 @@ function getWebsiteRSSHub (url) {
|
||||
}
|
||||
}
|
||||
|
||||
export function handleRSS (feeds, tabId, useCache) {
|
||||
export function handleRSS(feeds, tabId, useCache) {
|
||||
if (useCache && window.pageRSS[tabId]) {
|
||||
setBadge(tabId);
|
||||
} else {
|
||||
@@ -222,9 +222,9 @@ export function handleRSS (feeds, tabId, useCache) {
|
||||
feed.image = tab.favIconUrl || feed.image;
|
||||
});
|
||||
window.pageRSS[tabId] = feeds && feeds.filter((feed) => !feed.uncertain) || [];
|
||||
|
||||
|
||||
window.websiteRSSHub[tabId] = getWebsiteRSSHub(tab.url) || [];
|
||||
|
||||
|
||||
getPageRSSHub(tab.url, tabId, (feeds) => {
|
||||
window.pageRSSHub[tabId] = feeds || [];
|
||||
setBadge(tabId);
|
||||
@@ -243,13 +243,13 @@ export function handleRSS (feeds, tabId, useCache) {
|
||||
}
|
||||
}
|
||||
|
||||
export function removeRSS (tabId) {
|
||||
export function removeRSS(tabId) {
|
||||
delete window.pageRSS[tabId];
|
||||
delete window.websiteRSSHub[tabId];
|
||||
delete window.pageRSSHub[tabId];
|
||||
}
|
||||
|
||||
export function addPageRSS (feed, tabId) {
|
||||
export function addPageRSS(feed, tabId) {
|
||||
if (feed) {
|
||||
chrome.tabs.get(tabId, (tab) => {
|
||||
feed.image = tab.favIconUrl || feed.image;
|
||||
@@ -257,4 +257,12 @@ export function addPageRSS (feed, tabId) {
|
||||
setBadge(tabId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllRSS(tabId) {
|
||||
return {
|
||||
pageRSS: window.pageRSS[tabId] || {},
|
||||
websiteRSSHub: window.websiteRSSHub[tabId] || {},
|
||||
pageRSSHub: window.pageRSSHub[tabId] || {},
|
||||
}
|
||||
}
|
||||
+39
-37
@@ -5,7 +5,7 @@ import settingIcon from '../../svg/setting.svg';
|
||||
import aboutIcon from '../../svg/about.svg';
|
||||
let config;
|
||||
|
||||
function generateList (type, list) {
|
||||
function generateList(type, list) {
|
||||
let result = '';
|
||||
if (list && list.length) {
|
||||
list.forEach((item) => {
|
||||
@@ -17,9 +17,7 @@ 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>
|
||||
${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>` : ''}`
|
||||
@@ -36,42 +34,46 @@ function generateList (type, list) {
|
||||
document.querySelector('.icons-setting').innerHTML = settingIcon;
|
||||
document.querySelector('.icons-about').innerHTML = aboutIcon;
|
||||
|
||||
chrome.runtime.getBackgroundPage((background) => {
|
||||
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;
|
||||
generateList('page-rss', background.pageRSS[tabId]);
|
||||
generateList('page-rsshub', background.pageRSSHub[tabId]);
|
||||
generateList('website-rsshub', background.websiteRSSHub[tabId]);
|
||||
|
||||
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) => {
|
||||
console.log(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);
|
||||
});
|
||||
|
||||
document.querySelectorAll('.rss-image').forEach((ele) => {
|
||||
ele.addEventListener('error', function () {
|
||||
this.setAttribute('src', './rsshub.png');
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
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