Support launching url in a new tab (#46)

This commit is contained in:
Maxim Baz
2019-03-19 21:48:56 +01:00
committed by GitHub
parent c3cd5f77df
commit 22a33a81bd
4 changed files with 28 additions and 9 deletions

View File

@@ -408,6 +408,7 @@ async function handleMessage(settings, message, sendResponse) {
break;
case "launch":
case "launchInNewTab":
try {
var url = message.login.fields.url || message.login.domain;
if (!url) {
@@ -416,20 +417,25 @@ async function handleMessage(settings, message, sendResponse) {
if (!url.match(/:\/\//)) {
url = "http://" + url;
}
if (authListeners[settings.tab.id]) {
chrome.tabs.onUpdated.removeListener(authListeners[settings.tab.id]);
delete authListeners[settings.tab.id];
const tab =
message.action === "launch"
? await chrome.tabs.update(settings.tab.id, { url: url })
: await chrome.tabs.create({ url: url });
if (authListeners[tab.id]) {
chrome.tabs.onUpdated.removeListener(authListeners[tab.id]);
delete authListeners[tab.id];
}
authListeners[settings.tab.id] = handleModalAuth.bind({
authListeners[tab.id] = handleModalAuth.bind({
url: url,
login: message.login
});
chrome.webRequest.onAuthRequired.addListener(
authListeners[settings.tab.id],
{ urls: ["*://*/*"], tabId: settings.tab.id },
authListeners[tab.id],
{ urls: ["*://*/*"], tabId: tab.id },
["blocking"]
);
chrome.tabs.update(settings.tab.id, { url: url });
sendResponse({ status: "ok" });
} catch (e) {
sendResponse({
@@ -525,7 +531,7 @@ async function parseFields(settings, login) {
lines.forEach(function(line) {
// split key / value
var parts = line
.split(":")
.split(/:(.*)?/, 2)
.map(value => value.trim())
.filter(value => value.length);
if (parts.length != 2) {

View File

@@ -355,7 +355,9 @@ function keyHandler(e) {
}
break;
case "KeyG":
this.doAction("launch");
if (e.ctrlKey) {
this.doAction(e.shiftKey ? "launchInNewTab" : "launch");
}
break;
}
}

View File

@@ -130,6 +130,9 @@ async function withLogin(action) {
case "launch":
handleError("Launching URL...", "notice");
break;
case "launchInNewTab":
handleError("Launching URL in a new tab...", "notice");
break;
case "copyPassword":
handleError("Copying password to clipboard...", "notice");
break;

View File

@@ -105,6 +105,14 @@ function view(ctl, params) {
);
}
break;
case "KeyG":
if (e.ctrlKey && e.target.selectionStart == e.target.selectionEnd) {
e.preventDefault();
self.popup.results[0].doAction(
e.shiftKey ? "launchInNewTab" : "launch"
);
}
break;
}
}
})