// Global variables only exist for the life of the page, so they get reset
// each time the page is unloaded.
const attachedTabs = {};
let scriptInjected = false;

// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener((tab) => {
  const tabId = tab.id;
  if (!scriptInjected) {
    chrome.tabs.executeScript(tabId, { file: 'src/bg/injecthtml.js' }, (response) => {
      scriptInjected = response;
      chrome.browserAction.setIcon({ tabId, path: 'icons/continue.png' });
      chrome.browserAction.setTitle({ tabId, title: 'Enable collapsing' });
      chrome.tabs.insertCSS(tabId, { file: 'css/toggle.css' });
      chrome.tabs.executeScript(tabId, { file: 'src/bg/toggle_collapse.js' });
    });
  } else if (!attachedTabs[tabId]) {
    attachedTabs[tabId] = 'collapsed';
    chrome.browserAction.setIcon({ tabId, path: 'icons/pause.png' });
    chrome.browserAction.setTitle({ tabId, title: 'Pause collapsing' });
    chrome.tabs.sendMessage(tabId, { collapse: true });
  } else if (attachedTabs[tabId]) {
    delete attachedTabs[tabId];
    chrome.browserAction.setIcon({ tabId, path: 'icons/continue.png' });
    chrome.browserAction.setTitle({ tabId, title: 'Enable collapsing' });
    chrome.tabs.sendMessage(tabId, { collapse: false });
  }
});

@@ -110,23 +110,21 @@
 %0Aconst a
-ttached
+ctive
 Tabs = %7B
@@ -130,19 +130,15 @@
 %7B%7D;%0A
-let scriptI
+const i
 njec
@@ -143,21 +143,18 @@
 ected = 
-false
+%7B%7D
 ;%0A%0A// Ca
@@ -287,30 +287,31 @@
 %0A  if (!
-scriptInjected
+injected%5BtabId%5D
 ) %7B%0A    
@@ -403,22 +403,23 @@
     
-scriptInjected
+injected%5BtabId%5D
  = r
@@ -744,23 +744,21 @@
 e if (!a
-ttached
+ctive
 Tabs%5Btab
@@ -769,23 +769,21 @@
  %7B%0A    a
-ttached
+ctive
 Tabs%5Btab
@@ -792,19 +792,12 @@
 %5D = 
-'collapsed'
+true
 ;%0A  
@@ -1007,23 +1007,21 @@
 se if (a
-ttached
+ctive
 Tabs%5Btab
@@ -1035,23 +1035,14 @@
     
-delete attached
+active
 Tabs
@@ -1048,16 +1048,24 @@
 s%5BtabId%5D
+ = false
 ;%0A    ch

Fix issue of not working for multipe tabs