1 Star 0 Fork 0

lunny / SmartRss

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
background.html 4.20 KB
一键复制 编辑 原始数据 按行查看 历史
lunny 提交于 2013-03-15 16:37 . init
<html>
<head>
<script>
// The Page Action ID.
var pageActionId = "RssPageAction";
// The icon to use. This corresponds to the icon listed in the manifest.
var subscribeId = 0;
var subscribedId = 1;
// A dictionary keyed off of tabId that keeps track of data per tab (for
// example what feedUrl was detected in the tab).
var feedData = {};
localStorage["lastLoginCheckTime"] = (new Date()).getTime();
if (localStorage["black_list"] == undefined) {
var blacklist = new Array("http://www.google.com/reader/*", "https://www.google.com/reader/*");
localStorage["black_list"] = JSON.stringify(blacklist);
}
function getSubList() {
var xhr = new XMLHttpRequest();
xhr.open("GET", 'https://www.google.com/reader/api/0/token', true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var xhr2 = new XMLHttpRequest();
xhr2.open("GET", 'http://www.google.com/reader/api/0/subscription/list', true);
xhr2.onreadystatechange = function() {
if (xhr2.readyState == 4 && xhr2.status == 200) {
localStorage["lastSubLists"] = xhr2.responseText;
}
}
xhr2.send();
}
}
}
xhr.send();
}
if (localStorage["check_option_interval"] > 0) {
getSubList();
}
chrome.extension.onConnect.addListener(function(port) {
// determine if the site need to be check
var blacklist = JSON.parse(localStorage["black_list"]);
for (var i = 0; i < blacklist.length; i++) {
var re = new RegExp(blacklist[i]);
if (re.test(port.tab.url)) {
return;
}
}
if (localStorage["check_option_interval"] > 0) {
// Detemine if user is logged in
var curTime = (new Date()).getTime();
if (curTime - localStorage["lastLoginCheckTime"] > localStorage["check_option_interval"] * 1000) {
localStorage["lastLoginCheckTime"] = curTime;
getSubList();
}
}
// This will get called from the content script using PostMessage.
// |feedUrls| is a list of URL feeds found on the page. We only need 1 to
// enable the PageAction icon in the Omnibox.
port.onMessage.addListener(function(feedUrls) {
feedUrl = feedUrls[0];
// Let Chrome know that the PageAction needs to be enabled for this tabId
// and for the url of this page.
if (feedUrl) {
var idx = 0;
if (localStorage["check_option_interval"] > 0) {
if (localStorage["lastSubLists"] != undefined && localStorage["lastSubLists"].length > 0) {
idx = localStorage["lastSubLists"].indexOf(feedUrl);
}
}
feedData[port.tab.id] = {pageUrl: port.tab.url,
feedUrl: feedUrl};
chrome.pageActions.enableForTab(
pageActionId, {tabId: port.tab.id,
url: port.tab.url,
title: (idx > 0) ? "You have subscribed...." : "Click to subscribe....",
iconId: (idx > 0) ? subscribedId : subscribeId});
}
});
});
// Chrome will call into us when the user clicks on the icon in the OmniBox.
chrome.pageActions["RssPageAction"].addListener(function(pageActionId,
pageActionInfo) {
chrome.windows.getCurrent(function(window) {
chrome.tabs.get(pageActionInfo.tabId, function(tab) {
// We need to know if we are the active window, because the tab may
// have moved to another window and we don't want to execute this
// action multiple times.
if (window.focused) {
// Create a new tab showing the subscription page with the right
// feed URL.
var url = localStorage["current_protocol"] + "://www.google.com/reader/view/feed/" +
encodeURIComponent(feedData[pageActionInfo.tabId].feedUrl);
if (localStorage["tab_option"] == "new") {
chrome.tabs.create({url: url, windowId: window.windowId});
} else {
chrome.tabs.update(pageActionInfo.tabId, {url: url});
}
}
});
});
});
chrome.tabs.onRemoved.addListener(function(reply) {
feedData[reply.tabId] = null;
});
if ((localStorage["firstrun_grss"]!="false") && (localStorage["firstrun_grss"]!=false)){
chrome.tabs.create({url: "options.html", selected:true})
localStorage["firstrun_grss"] = false;
localStorage["ver"] = "1.0";
}
</script>
</head>
</html>
JavaScript
1
https://gitee.com/lunny/smartrss.git
git@gitee.com:lunny/smartrss.git
lunny
smartrss
SmartRss
master

搜索帮助