Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tab search & styling improvements #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<numTabs; i++) {
var row = table.insertRow(i);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);

cell1.innerHTML = "<img src=" + tabs[i].favIconUrl + " width='16' height='16'>";
cell2.innerHTML = "<span style=cursor:pointer><font color=red>X</font></span>";
cell3.innerHTML = "<span style=cursor:pointer title='" + tabs[i].url + "'>" + tabs[i].title + "</span>";
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 = "<img src=" + tabs[i].favIconUrl + " width='16' height='16'>";
cell2.innerHTML = "<span style=cursor:pointer><font color=red>X</font></span>";
cell3.innerHTML = "<span style=cursor:pointer title='" + tabs[i].url + "'>" + tabs[i].title + "</span>";

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));
}
}
}

Expand All @@ -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);
}
29 changes: 23 additions & 6 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,38 @@
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;
}
</style>
<script src="js/popup.js"></script>
</head>

<body>
<p class='box' id='windowTabs'></p>
<input type="search" id="search" placeholder="Search" autofocus>
<table id='tabsTable'></table>
</body>

</html>