Created
August 24, 2014 09:59
-
-
Save acgotaku/09f2b5c3964fa5e5a437 to your computer and use it in GitHub Desktop.
Promise example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | |
console.log(tab); | |
if (changeInfo.status === 'loading' && tab.url.indexOf("n.baidu.com") != -1) { | |
var site1 = "http://pan.baidu.com/"; | |
var name1 = "BDUSS"; | |
var site2 = "http://pcs.baidu.com/"; | |
var name2 = "pcsett"; | |
Promise.all([get_cookie(site1,name1), get_cookie(site2,name2)]).then(function(value){ | |
console.log(value); | |
},function(){}); | |
} | |
}); | |
function get_cookie(site,name){ | |
return new Promise(function(resolve, reject) { | |
chrome.cookies.get({"url": site, "name": name}, function(cookies) { | |
if (cookies) { | |
var data = cookies.name + "=" + cookies.value; | |
resolve(data); | |
}else{ | |
reject(); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment