是否可以根据lastFocused窗口对getAllWindows的结果进行排序?
chrome.windows.getAll(null, (windows) => {
/* how to sort the windows absed on lastFocused */
})
答案 0 :(得分:0)
您可以在阵列中维护集中的Windows历史记录。然后按历史记录数组中的索引对窗口项进行排序:
var focusedWindowHistoty=[];
chrome.windows.onFocusChanged.addListener(function(window) {
focusedWindowHistoty = focusedWindowHistoty.filter(function(it){
return it != window;
});
focusedWindowHistoty.push(window);
});
chrome.windows.getAll(null, (windows) => {
var sorted=windows.sort(function(a,b){
return getIndex(a)>getIndex(b);
});
})
function getIndex(item){
var foundIndex=-1;
focusedWindowHistoty.forEach(function(it,index){
if(it==item){
foundIndex=index;
}
})
return foundIndex;
}