aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/background/index.js9
-rw-r--r--src/background/tabs.js22
2 files changed, 24 insertions, 7 deletions
diff --git a/src/background/index.js b/src/background/index.js
index e5b08c5..d8047a6 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -60,12 +60,11 @@ const normalizeUrl = (string) => {
const cmdBuffer = (arg) => {
if (isNaN(arg)) {
- // TODO support buffer identification by non-number value
- throw new TypeError(`${arg} is not a number`);
+ tabs.selectByKeyword(arg);
+ } else {
+ let index = parseInt(arg, 10) - 1;
+ tabs.selectAt(index);
}
-
- let index = parseInt(arg, 10) - 1;
- tabs.selectAt(index);
}
const cmdEnterHandle = (request, sender) => {
diff --git a/src/background/tabs.js b/src/background/tabs.js
index 532ad42..201fa73 100644
--- a/src/background/tabs.js
+++ b/src/background/tabs.js
@@ -24,11 +24,29 @@ const selectAt = (index) => {
return;
}
if (index < 0 || tabs.length <= index) {
- throw new RangeError(`buffer ${index} does not exist`)
+ throw new RangeError(`tab ${index} does not exist`)
}
let id = tabs[index].id;
chrome.tabs.update(id, { active: true })
});
+};
+
+const selectByKeyword = (keyword) => {
+ chrome.tabs.query({ currentWindow: true }, (tabs) => {
+ let tab = tabs.find((tab) => tab.url.includes(keyword))
+ if (tab) {
+ chrome.tabs.update(tab.id, { active: true });
+ return;
+ }
+
+ tab = tabs.find((tab) => tab.title.includes(keyword))
+ if (tab) {
+ chrome.tabs.update(tab.id, { active: true });
+ return;
+ }
+
+ throw new RangeError('No matching buffer for ' + keyword);
+ })
}
const selectPrevTab = (current, count) => {
@@ -60,4 +78,4 @@ const reload = (current, cache) => {
);
};
-export { closeTab, reopenTab, selectAt, selectNextTab, selectPrevTab, reload };
+export { closeTab, reopenTab, selectAt, selectByKeyword, selectNextTab, selectPrevTab, reload };