Skip to content

Commit

Permalink
Find tab works now
Browse files Browse the repository at this point in the history
  • Loading branch information
xennygrimmato committed Jun 28, 2020
1 parent 1ca1b78 commit b90b294
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
51 changes: 51 additions & 0 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,54 @@ export async function openTabWithUrl(url) {
chrome.tabs.create({ url: url });
}
}

function get_search_confidence(tab, text) {
// 1. Get all content in <body>...</body> tags
// 2. Get frequency of text
return 1.0;
}

async function find_tab_with_text(text) {
chrome.tabs.query({windowId: -2}, tabs => {
for (const tab of tabs) {
console.log(tab.title, tab.url)
}
// tab_confidence_map = {};
// for (tab in tabs) {
// console.log(tab.title, tab.url)
// tab_confidence_map[tab.id] = get_search_confidence(tab, text);
// }
// max_confidence = 0.0
// max_confidence_tab = -1
// for (const [key, value] of Object.entries(tab_confidence_map)) {
// if (value > max_confidence) {
// max_confidence = value
// max_confidence_tab = key
// }
// }
// return max_confidence_tab
})
}

export function openTabWithText(windowId, text) {
// Get id of tab containing text
// find_tab_with_text(text, (tabId => {
// console.log('here2')
// chrome.tabs.update(tabId, { active: true });
// }));
chrome.tabs.query({windowId: windowId}, tabs => {
let goodIdx = -1;
for (const tab of tabs) {
if (tab.title === undefined) {
console.log(tab.index)
continue
}
if (tab.title.toLowerCase().includes(text)) {
goodIdx = tab.index
}
console.log(tab.title, tab.url)
}
console.log("goodIdx" + goodIdx)
chrome.tabs.update(tabs[goodIdx].id, { active: true });
});
}
13 changes: 8 additions & 5 deletions src/js/plugins/tab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { performActionWithDelay } from '../core';
import { performActionWithDelay, openTabWithText } from '../core';



Expand Down Expand Up @@ -300,6 +300,9 @@ const commands = [
chrome.tabs.query({windowId: -2}, tabs => {
let goodIdx = -1;
for (const tab of tabs) {
if (tab.title === undefined) {
console.log(tab.index)
}
if (tab.title.includes("Codeforces")) {
goodIdx = tab.index
}
Expand All @@ -314,10 +317,10 @@ const commands = [
action: 'TABS_FIND_TAB',
callback: query => {
console.log(query);
chrome.tabs.update(tabs[0].id, { active: true });
// chrome.windows.getCurrent({}, window => {
// openTabWithText(window.id, "query");
// });
// chrome.tabs.update(tabs[0].id, { active: true });
chrome.windows.getCurrent({}, window => {
openTabWithText(window.id, query);
});
}
},

Expand Down

0 comments on commit b90b294

Please sign in to comment.