|
|
|
@ -1,69 +1,60 @@ |
|
|
|
|
import * as tabCompletions from './completions/tabs'; |
|
|
|
|
|
|
|
|
|
const closeTab = (id) => { |
|
|
|
|
return browser.tabs.get(id).then((tab) => { |
|
|
|
|
const closeTab = async(id) => { |
|
|
|
|
let tab = await browser.tabs.get(id); |
|
|
|
|
if (!tab.pinned) { |
|
|
|
|
return browser.tabs.remove(id); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const closeTabForce = (id) => { |
|
|
|
|
return browser.tabs.remove(id); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const queryByKeyword = (keyword, excludePinned = false) => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const queryByKeyword = async(keyword, excludePinned = false) => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
return tabs.filter((t) => { |
|
|
|
|
return t.url.toLowerCase().includes(keyword.toLowerCase()) || |
|
|
|
|
t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); |
|
|
|
|
}).filter((t) => { |
|
|
|
|
return !(excludePinned && t.pinned); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const closeTabByKeywords = (keyword) => { |
|
|
|
|
return queryByKeyword(keyword, false).then((tabs) => { |
|
|
|
|
const closeTabByKeywords = async(keyword) => { |
|
|
|
|
let tabs = await queryByKeyword(keyword, false); |
|
|
|
|
if (tabs.length === 0) { |
|
|
|
|
throw new Error('No matching buffer for ' + keyword); |
|
|
|
|
} else if (tabs.length > 1) { |
|
|
|
|
throw new Error('More than one match for ' + keyword); |
|
|
|
|
} |
|
|
|
|
browser.tabs.remove(tabs[0].id); |
|
|
|
|
}); |
|
|
|
|
return browser.tabs.remove(tabs[0].id); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const closeTabByKeywordsForce = (keyword) => { |
|
|
|
|
return queryByKeyword(keyword, true).then((tabs) => { |
|
|
|
|
const closeTabByKeywordsForce = async(keyword) => { |
|
|
|
|
let tabs = await queryByKeyword(keyword, true); |
|
|
|
|
if (tabs.length === 0) { |
|
|
|
|
throw new Error('No matching buffer for ' + keyword); |
|
|
|
|
} else if (tabs.length > 1) { |
|
|
|
|
throw new Error('More than one match for ' + keyword); |
|
|
|
|
} |
|
|
|
|
browser.tabs.remove(tabs[0].id); |
|
|
|
|
}); |
|
|
|
|
return browser.tabs.remove(tabs[0].id); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const closeTabsByKeywords = (keyword) => { |
|
|
|
|
tabCompletions.getCompletions(keyword).then((tabs) => { |
|
|
|
|
let tabs2 = tabs.filter(tab => !tab.pinned); |
|
|
|
|
browser.tabs.remove(tabs2.map(tab => tab.id)); |
|
|
|
|
}); |
|
|
|
|
const closeTabsByKeywords = async(keyword) => { |
|
|
|
|
let tabs = await tabCompletions.getCompletions(keyword); |
|
|
|
|
tabs = tabs.filter(tab => !tab.pinned); |
|
|
|
|
return browser.tabs.remove(tabs.map(tab => tab.id)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const closeTabsByKeywordsForce = (keyword) => { |
|
|
|
|
tabCompletions.getCompletions(keyword).then((tabs) => { |
|
|
|
|
browser.tabs.remove(tabs.map(tab => tab.id)); |
|
|
|
|
}); |
|
|
|
|
const closeTabsByKeywordsForce = async(keyword) => { |
|
|
|
|
let tabs = await tabCompletions.getCompletions(keyword); |
|
|
|
|
return browser.tabs.remove(tabs.map(tab => tab.id)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const reopenTab = () => { |
|
|
|
|
let window = null; |
|
|
|
|
return browser.windows.getCurrent().then().then((w) => { |
|
|
|
|
window = w; |
|
|
|
|
return browser.sessions.getRecentlyClosed(); |
|
|
|
|
}).then((sessions) => { |
|
|
|
|
const reopenTab = async() => { |
|
|
|
|
let window = await browser.windows.getCurrent(); |
|
|
|
|
let sessions = await browser.sessions.getRecentlyClosed(); |
|
|
|
|
let session = sessions.find((s) => { |
|
|
|
|
return s.tab && s.tab.windowId === window.id; |
|
|
|
|
}); |
|
|
|
@ -74,11 +65,10 @@ const reopenTab = () => { |
|
|
|
|
return browser.sessions.restore(session.tab.sessionId); |
|
|
|
|
} |
|
|
|
|
return browser.sessions.restore(session.window.sessionId); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectAt = (index) => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const selectAt = async(index) => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
if (tabs.length < 2) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -87,11 +77,10 @@ const selectAt = (index) => { |
|
|
|
|
} |
|
|
|
|
let id = tabs[index].id; |
|
|
|
|
return browser.tabs.update(id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectByKeyword = (current, keyword) => { |
|
|
|
|
return queryByKeyword(keyword).then((tabs) => { |
|
|
|
|
const selectByKeyword = async(current, keyword) => { |
|
|
|
|
let tabs = await queryByKeyword(keyword); |
|
|
|
|
if (tabs.length === 0) { |
|
|
|
|
throw new RangeError('No matching buffer for ' + keyword); |
|
|
|
|
} |
|
|
|
@ -101,43 +90,38 @@ const selectByKeyword = (current, keyword) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return browser.tabs.update(tabs[0].id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectPrevTab = (current, count) => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const selectPrevTab = async(current, count) => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
if (tabs.length < 2) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
let select = (current - count + tabs.length) % tabs.length; |
|
|
|
|
let id = tabs[select].id; |
|
|
|
|
return browser.tabs.update(id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectNextTab = (current, count) => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const selectNextTab = async(current, count) => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
if (tabs.length < 2) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
let select = (current + count) % tabs.length; |
|
|
|
|
let id = tabs[select].id; |
|
|
|
|
return browser.tabs.update(id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectFirstTab = () => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const selectFirstTab = async() => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
let id = tabs[0].id; |
|
|
|
|
return browser.tabs.update(id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectLastTab = () => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true }).then((tabs) => { |
|
|
|
|
const selectLastTab = async() => { |
|
|
|
|
let tabs = await browser.tabs.query({ currentWindow: true }); |
|
|
|
|
let id = tabs[tabs.length - 1].id; |
|
|
|
|
return browser.tabs.update(id, { active: true }); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const selectTab = (id) => { |
|
|
|
@ -152,14 +136,11 @@ const reload = (current, cache) => { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const updateTabPinned = (current, pinned) => { |
|
|
|
|
return browser.tabs.query({ currentWindow: true, active: true }) |
|
|
|
|
.then(() => { |
|
|
|
|
return browser.tabs.update(current.id, { pinned: pinned }); |
|
|
|
|
}); |
|
|
|
|
return browser.tabs.update(current.id, { pinned }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const toggleTabPinned = (current) => { |
|
|
|
|
updateTabPinned(current, !current.pinned); |
|
|
|
|
return updateTabPinned(current, !current.pinned); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const duplicate = (id) => { |
|
|
|
|