Skip to content

Commit

Permalink
Merge pull request #2 from JDuchniewicz/master
Browse files Browse the repository at this point in the history
Merge changes from main repo
  • Loading branch information
Willmish authored May 14, 2020
2 parents ff335bb + 7a69471 commit c98b0ee
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 105 deletions.
2 changes: 2 additions & 0 deletions auto-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function setStyle(theme) {
let documentBody = document.body;
let inputFieldStyle = document.getElementById("find-input").style;
let generalBodyStyle = document.body.style;
let modeIndicatorStyle = document.getElementById("mode-indicator").style;

let sSheets = document.styleSheets[0];
// General body style
Expand All @@ -15,6 +16,7 @@ function setStyle(theme) {
// default text color
generalBodyStyle.color = theme.colors.toolbar_field_text;
inputFieldStyle.color = theme.colors.toolbar_field_text;
modeIndicatorStyle.color = theme.colors.toolbar_field_text;
}

// Input field style
Expand Down
84 changes: 42 additions & 42 deletions background.js
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"});
}
});
5 changes: 3 additions & 2 deletions find-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<div class="container">
<form id="find-form">
<div class="form-group" id="form">
<input type="text" class="form-control" id="find-input" placeholder="What to find..." autofocus autocomplete="off"/>
<input type="text" class="form-control" id="find-input" placeholder="Search through: All Windows" autofocus autocomplete="off"/>
<div id="mode-indicator">A</div>
</div>
</form>
<hr>
</form>
<table id="result-list"></table>
</div>
<script src="find-tab.js"></script>
Expand Down
Loading

0 comments on commit c98b0ee

Please sign in to comment.