From fcd084e318b3b77ba83bc8cd3daf8ea4f1ee6a4e Mon Sep 17 00:00:00 2001 From: Bill Kudo Date: Thu, 26 Apr 2018 11:24:13 +0900 Subject: [PATCH] Added onRemoved listener --- src/background.js | 5 +++++ src/popup/popup.js | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/background.js b/src/background.js index d6cd267..9cc1f37 100755 --- a/src/background.js +++ b/src/background.js @@ -103,6 +103,11 @@ function tabUpdated(tabId, changeInfo, tab) { } function tabRemoved(tabId, removeInfo) { + sendMessage("TAB_REMOVED", { + tabId: tabId, + windowId: removeInfo.windowId, + windowClosing: removeInfo.isWindowClosing + }); if (lastTabId === tabId) { lastTabId = undefined; } diff --git a/src/popup/popup.js b/src/popup/popup.js index 44b45bb..a913f5b 100755 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -43,6 +43,11 @@ function onMessage(request, sender, sendResponse) { case "TAB_TITLE_CHANGED": findTabEntryById(request.details.tabId).querySelector(".tab-title").textContent = request.details.title; break; + case "TAB_REMOVED": + if (!request.details.windowClosing) { + removeTab(request.details.tabId, request.details.windowId); + } + break; case "WINDOW_REMOVED": removeWindow(request.details.windowId); break; @@ -115,7 +120,7 @@ function setActiveTab(windowId, tabId) { // Remove tab function removeTab(tabId, windowId) { let tabEntry = findTabEntryById(tabId); - tabEntry.parentElement.removeChild(tabEntry); + tabEntry.outerHTML = ""; browser.tabs.query({ active: true, windowId: windowId @@ -394,11 +399,7 @@ function documentClicked(e) { } else if (e.target.id === "details-close") { document.querySelector("#details-placeholder").style.display = "inline-block"; document.querySelector("#tab-details").style.display = "none"; - browser.tabs.get(parseInt(document.querySelector("#tab-details").getAttribute("data-tab_id"))).then(function (tab){ - browser.tabs.remove(parseInt(document.querySelector("#tab-details").getAttribute("data-tab_id"))).then(function (){ - removeTab(tab.id, tab.windowId); - }); - }); + browser.tabs.remove(parseInt(document.querySelector("#tab-details").getAttribute("data-tab_id"))); } else if (e.target.classList.contains("tab-entry-remove-btn")) { let tabId = e.target.parentElement.parentElement.getAttribute("data-tab_id"); let tabDetails = document.querySelector("#tab-details"); @@ -406,9 +407,7 @@ function documentClicked(e) { tabDetails.style.display = "none"; document.querySelector("#details-placeholder").style.display = "inline-block"; } - browser.tabs.remove(parseInt(tabId)).then(function (){ - removeTab(parseInt(tabId), parseInt(e.target.parentElement.parentElement.parentElement.parentElement.getAttribute("data-window_id"))); - }); + browser.tabs.remove(parseInt(tabId)); } else if (e.target.classList.contains("tab-entry-pin-btn")) { let tabId = e.target.parentElement.parentElement.getAttribute("data-tab_id"); browser.tabs.get(parseInt(tabId)).then(function (tab){