Skip to content

Instantly share code, notes, and snippets.

@acgotaku
Created August 24, 2014 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acgotaku/09f2b5c3964fa5e5a437 to your computer and use it in GitHub Desktop.
Save acgotaku/09f2b5c3964fa5e5a437 to your computer and use it in GitHub Desktop.
Promise example
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