-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JDuchniewicz/master
Merge changes from main repo
- Loading branch information
Showing
6 changed files
with
210 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
var opened = false; | ||
var pluginPanelId = null | ||
|
||
async function find(query) { | ||
browser.runtime.sendMessage({msg: "clear-results"}); | ||
|
||
if (!query) | ||
return; | ||
|
||
let this_tab_url = browser.runtime.getURL("find-tab.html"); | ||
let tabs = await browser.tabs.query({}).then(allTabs => findMatchingTab(query, allTabs, this_tab_url)); | ||
|
||
} | ||
|
||
async function findMatchingTab(query, allTabs, thisTabUrl) { | ||
const regex = RegExp(query); | ||
for (let tab of allTabs) { // just search through tabs titles for now, maybe add in depth tab searching later? | ||
if (tab.url == thisTabUrl) | ||
{ | ||
continue; | ||
} | ||
if (regex.test(tab.title) || tab.title.toLowerCase().includes(query)) { | ||
browser.runtime.sendMessage({ | ||
msg: "found-result", | ||
title: tab.title, | ||
id: tab.id, | ||
url: tab.url, | ||
query: query | ||
}); | ||
} | ||
} | ||
browser.runtime.sendMessage({ | ||
msg: "results-complete" | ||
}); | ||
//console.log("Handled find " + query); | ||
} | ||
var pluginPanelId = null; | ||
var tabsFromLastWindow = null; | ||
var tabsFromAllWindows = null; | ||
|
||
function createNewWindow() { | ||
let createData = { | ||
type: "detached_panel", | ||
url: "find-tab.html", | ||
width: window.screen.width / 2, // find reasonable size | ||
height: window.screen.height / 2 | ||
height: window.screen.height / 2, | ||
// current bug 1271047 prevents from pos being set | ||
left: window.screen.width / 2, // position in the centre | ||
top: window.screen.height / 2 | ||
}; | ||
let pluginPanel = browser.windows.create(createData); | ||
waitForPanelId(pluginPanel) | ||
waitForPanelId(pluginPanel); | ||
opened = true; | ||
}; | ||
|
||
async function waitForPanelId(pluginPanel) { | ||
pluginPanelId = await pluginPanel.then(pluginPanel => pluginPanel.id); | ||
} | ||
|
||
// Requests tabs, from all windows and the current one. | ||
async function getTabs() { | ||
await browser.tabs.query({currentWindow: true}).then((allT) => {tabsFromLastWindow = allT}); | ||
await browser.tabs.query({currentWindow: false}).then((allT) => {tabsFromAllWindows = allT}); | ||
} | ||
|
||
function sendTabs() { | ||
browser.runtime.sendMessage({ | ||
msg: "all-tabs", | ||
tabsLastW: tabsFromLastWindow, | ||
tabsAllW: tabsFromAllWindows | ||
}); | ||
} | ||
|
||
// Listeners | ||
browser.browserAction.onClicked.addListener(() => { | ||
// check if already open | ||
if (opened) | ||
return; | ||
createNewWindow(); | ||
getTabs(); | ||
}); | ||
|
||
browser.commands.onCommand.addListener(function (command) { | ||
if (opened) | ||
return; | ||
|
||
if (command == "toggle-plugin") { | ||
createNewWindow(); | ||
// Toggle the plugin on and off | ||
if (opened) | ||
{ | ||
browser.windows.remove(pluginPanelId); | ||
// opened is set to false and handled by find-tab.js by handlePanelClose | ||
} | ||
else { | ||
createNewWindow(); | ||
getTabs(); | ||
} | ||
} | ||
}); | ||
else if (command == "close-Tab") { | ||
if (opened) | ||
browser.runtime.sendMessage({msg: "close-tab"}); | ||
} | ||
else if (command == "toggle-search-mode") { | ||
if (opened) | ||
browser.runtime.sendMessage({msg: "toggle-search-mode"}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.