Skip to content

Commit

Permalink
show currently focused window first in list
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshellerhoff committed Jan 20, 2023
1 parent 63a0f21 commit 1eafaa8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
function getTabs() {
chrome.tabs.query({}, function(tabs) {
appendTabs(tabs);
chrome.windows.getAll(windows => {
appendTabs(tabs, windows);
})
});
}

Expand Down Expand Up @@ -50,23 +52,23 @@ function getFaviconUrl(tab) {
return "chrome://favicon/" + tab.url;
}

function appendTabs(tabs) {
async function appendTabs(tabs, windows) {
var html = "";

// get a list of all window IDs
windowIds = [...new Set(tabs.map(tab => tab.windowId))];
windowIds = windows.map(window => window.id)
currentWindowId = windows.filter(window => window.focused)[0].id

// sort the window IDs so that the current window is first
// currentWindowId = 1
// windowIds = windowIds.sort((a, b) => {
// if (a == currentWindowId) {
// return -1;
// } else if (b == currentWindowId) {
// return 1;
// } else {
// return 0;
// }
// });
windowIds = windowIds.sort((a, b) => {
if (a == currentWindowId) {
return -1;
} else if (b == currentWindowId) {
return 1;
} else {
return 0;
}
});

// cycle through all the windows first
windowIds.forEach(windowId => {
Expand Down

0 comments on commit 1eafaa8

Please sign in to comment.