diff --git a/js/popup.js b/js/popup.js index 359ebd9..49dc4c6 100644 --- a/js/popup.js +++ b/js/popup.js @@ -20,31 +20,53 @@ function getAllTabs(callback) { }); } -function displayResults(tabs){ +//search tab +function searchTab(tab, search){ + if (typeof search === 'undefined') return true; + var tabText = (tab.url + tab.title).toLowerCase(); + if (tabText.indexOf(search.toLowerCase()) > -1){ + return true; + } + return false; +} + +function createPopup(tabs){ + document.getElementById('search').addEventListener("input", (function(tabs) { + return function() { + var search = event.target.value; + displayResults(tabs, search); + } + })(tabs)); + displayResults(tabs); +} + +function displayResults(tabs, search){ getCurrentWindowTabCount(); numTabs = tabs.length; var table = document.getElementById('tabsTable'); + table.innerHTML = ""; for (var i=0; i"; - cell2.innerHTML = "X"; - cell3.innerHTML = "" + tabs[i].title + ""; + if (searchTab(tabs[i], search)){ + var row = table.insertRow(); + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + var cell3 = row.insertCell(2); + cell1.innerHTML = ""; + cell2.innerHTML = "X"; + cell3.innerHTML = "" + tabs[i].title + ""; + + cell2.addEventListener("click", (function(tabID) { + return function() { + closeTab(tabID); + } + })(tabs[i].id)); - cell2.addEventListener("click", (function(tabID) { - return function() { - closeTab(tabID); - } - })(tabs[i].id)); - - cell3.addEventListener("click", (function(tabID, windowID) { - return function() { - openTab(tabID, windowID); - } - })(tabs[i].id, tabs[i].windowId)); + cell3.addEventListener("click", (function(tabID, windowID) { + return function() { + openTab(tabID, windowID); + } + })(tabs[i].id, tabs[i].windowId)); + } } } @@ -64,8 +86,8 @@ function closeTab(tabID) { var tabsDisplayOption = localStorage["popupDisplayOption"]; // if extension is just installed or reloaded, tabsDisplayOption will not be set if (typeof tabsDisplayOption == "undefined" || tabsDisplayOption == "currentWindow") { - getCurrentWindowTabs(displayResults); + getCurrentWindowTabs(createPopup); } else { //getCurrentWindowTabCount(); - getAllTabs(displayResults); + getAllTabs(createPopup); } \ No newline at end of file diff --git a/popup.html b/popup.html index 4df5fbe..8562241 100644 --- a/popup.html +++ b/popup.html @@ -11,10 +11,26 @@ padding: 0 10px 0 10px; } p.box { - background-color:#F0F0F0; - margin:10px; - padding:10px; - border:1px solid #606060; + margin: 15px 0px 10px 0px; + } + #search { + margin: 0px 0px 10px 0px; + padding: 5px; + width: 100%; + border: 1px solid #ccc; + border-radius: 4px; + } + #tabsTable { + position: relative; + margin-bottom: 5px; + right: 3px; + } + #tabsTable tr { + display: block; + width: 300px; + } + #tabsTable td { + padding: 0px 1px; } a.redlink { color: #FF0000; @@ -22,10 +38,11 @@ - +

+
- + \ No newline at end of file