Skip to content

Instantly share code, notes, and snippets.

@piayo
Created December 13, 2012 06:09
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 piayo/4274463 to your computer and use it in GitHub Desktop.
Save piayo/4274463 to your computer and use it in GitHub Desktop.
toggle popup for Chrome Extension like Official Google+ notifications extensions.
var _timer = null;
var _flg_opened = false;
var _func_toggle = function(flg){
_flg_opened = flg;
clearTimeout(_timer);
_timer = setTimeout(function(){
console.log(">>_flg_opened: "+ _flg_opened);
if(_flg_opened){
chrome.browserAction.setPopup({"popup": ""});
chrome.browserAction.setBadgeText({text:"OFF"});
chrome.browserAction.setTitle({"title": "NextClick: Close"});
clearTimeout(_timer);
}else{
chrome.browserAction.setPopup({"popup": "popup.html"});
chrome.browserAction.setBadgeText({text:"ON"});
chrome.browserAction.setTitle({"title": "NextClick: OPEN"});
clearTimeout(_timer);
}
}, 200);
};
;(function(_WIN, _DOC){
var _init = function(){
console.log(">>onload: background");
_func_toggle(false);
}
_WIN.onload = _init
})(window, document);
;(function(_WIN, _DOC){
var _BG;
var _init = function(){
console.log(">>onload: popup");
_BG = chrome.extension.getBackgroundPage();
_BG._func_toggle(true);
_WIN.addEventListener("unload", function(){
_BG._func_toggle(false);
}, false);
}
_WIN.onload = _init;
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment