代码拉取完成,页面将自动刷新
function focusOrCreateTab(url) {
chrome.windows.getAll({"populate":true}, function(windows) {
var existing_tab = null;
for (var i in windows) {
var tabs = windows[i].tabs;
for (var j in tabs) {
var tab = tabs[j];
if (tab.url == url) {
existing_tab = tab;
break;
}
}
}
if (existing_tab) {
chrome.tabs.update(existing_tab.id, {"selected":true});
} else {
chrome.tabs.create({"url":url, "selected":true});
}
});
}
function getDomainFromUrl(url){
var host = "null";
if(typeof url == "undefined" || null == url)
url = window.location.href;
var regex = /.*\:\/\/([^\/]*).*/;
var match = url.match(regex);
if(typeof match != "undefined" && null != match)
host = match[1];
return host;
}
var adzoneid = '';
var siteid = '';
chrome.storage.sync.get('adzoneid',function (item) {
adzoneid = item.adzoneid;
console.log(item);
});
chrome.storage.sync.get('siteid',function (item) {
siteid = item.siteid;
});
var msg = {
type: "setting",
adzoneid : adzoneid,
siteid:siteid
};
chrome.browserAction.onClicked.addListener(function(tab) {
var manager_url = chrome.extension.getURL("setting.html");
console.log(tab);
focusOrCreateTab(manager_url);
});
chrome.tabs.onCreated.addListener(function(tab){
console.log(tab);
if(getDomainFromUrl(tab.url).toLowerCase()=="pub.alimama.com"){
chrome.runtime.sendMessage(msg);
}
});
console.log('back');
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo,tab) {
console.log(tab);
if(getDomainFromUrl(tab.url).toLowerCase()=="pub.alimama.com"){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id,msg, function(response) {
console.log(response.farewell);
});
});
}
});
chrome.tabs.onReload.addListener(function(tab){
console.log(tab);
if(getDomainFromUrl(tab.url).toLowerCase()=="pub.alimama.com"){
chrome.runtime.sendMessage(msg);
}
});
chrome.tabs.onActive.addListener(function(tab){
console.log(tab);
if(getDomainFromUrl(tab.url).toLowerCase()=="pub.alimama.com"){
chrome.runtime.sendMessage(msg);
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。