stuppid_bot

Untitled

Mar 30th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isUrl(url) {
  2.   var re = new RegExp('http(s?)\://*/*');
  3.   return re.test(url);
  4. }
  5.  
  6. /**
  7. * Disable browser action
  8. */
  9. function disable() {
  10.   chrome.browserAction.setPopup({
  11.     popup: ''
  12.   });
  13.   chrome.browserAction.setIcon({
  14.     path: 'icons/toolbar_icon_inactive.png'
  15.   });
  16. }
  17.  
  18. /**
  19. * Enable browser action
  20. */
  21. function enable() {
  22.   chrome.browserAction.setPopup({
  23.     popup: 'browser_action.html'
  24.   });
  25.   chrome.browserAction.setIcon({
  26.     path: 'icons/toolbar_icon_active.png'
  27.   });
  28. }
  29.  
  30. function isBrowserActionActive(url) {
  31.   if (!isUrl(url)) {
  32.     disable();
  33.   } else {
  34.     enable();
  35.   }
  36. }
  37.  
  38. chrome.windows.onFocusChanged.addListener(function(windowId) {
  39.   if (-1 != windowId) {
  40.     chrome.windows.get(windowId, {
  41.       populate: true
  42.     }, function(window) {
  43.       for (var i = 0; i != window.tabs.length; i++) {
  44.         if (window.tabs[i].active) {
  45.           isBrowserActionActive(window.tabs[i].url);
  46.         }
  47.       }
  48.     })
  49.   } else {
  50.     disable();
  51.   }
  52. });
  53.  
  54. chrome.tabs.getSelected(null, function(tab) {
  55.   isBrowserActionActive(tab.url);
  56. });
  57.  
  58. chrome.tabs.onActivated.addListener(function(activeInfo) {
  59.   chrome.tabs.get(activeInfo.tabId, function(tab) {
  60.     isBrowserActionActive(tab.url);
  61.   });
  62. });
  63.  
  64. chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  65.   isBrowserActionActive(tab.url);
  66. });
Advertisement
Add Comment
Please, Sign In to add comment