Support launching url in a new tab (#46)
This commit is contained in:
@@ -408,6 +408,7 @@ async function handleMessage(settings, message, sendResponse) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "launch":
|
case "launch":
|
||||||
|
case "launchInNewTab":
|
||||||
try {
|
try {
|
||||||
var url = message.login.fields.url || message.login.domain;
|
var url = message.login.fields.url || message.login.domain;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -416,20 +417,25 @@ async function handleMessage(settings, message, sendResponse) {
|
|||||||
if (!url.match(/:\/\//)) {
|
if (!url.match(/:\/\//)) {
|
||||||
url = "http://" + url;
|
url = "http://" + url;
|
||||||
}
|
}
|
||||||
if (authListeners[settings.tab.id]) {
|
|
||||||
chrome.tabs.onUpdated.removeListener(authListeners[settings.tab.id]);
|
const tab =
|
||||||
delete authListeners[settings.tab.id];
|
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,
|
url: url,
|
||||||
login: message.login
|
login: message.login
|
||||||
});
|
});
|
||||||
chrome.webRequest.onAuthRequired.addListener(
|
chrome.webRequest.onAuthRequired.addListener(
|
||||||
authListeners[settings.tab.id],
|
authListeners[tab.id],
|
||||||
{ urls: ["*://*/*"], tabId: settings.tab.id },
|
{ urls: ["*://*/*"], tabId: tab.id },
|
||||||
["blocking"]
|
["blocking"]
|
||||||
);
|
);
|
||||||
chrome.tabs.update(settings.tab.id, { url: url });
|
|
||||||
sendResponse({ status: "ok" });
|
sendResponse({ status: "ok" });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
@@ -525,7 +531,7 @@ async function parseFields(settings, login) {
|
|||||||
lines.forEach(function(line) {
|
lines.forEach(function(line) {
|
||||||
// split key / value
|
// split key / value
|
||||||
var parts = line
|
var parts = line
|
||||||
.split(":")
|
.split(/:(.*)?/, 2)
|
||||||
.map(value => value.trim())
|
.map(value => value.trim())
|
||||||
.filter(value => value.length);
|
.filter(value => value.length);
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
|
@@ -355,7 +355,9 @@ function keyHandler(e) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "KeyG":
|
case "KeyG":
|
||||||
this.doAction("launch");
|
if (e.ctrlKey) {
|
||||||
|
this.doAction(e.shiftKey ? "launchInNewTab" : "launch");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -130,6 +130,9 @@ async function withLogin(action) {
|
|||||||
case "launch":
|
case "launch":
|
||||||
handleError("Launching URL...", "notice");
|
handleError("Launching URL...", "notice");
|
||||||
break;
|
break;
|
||||||
|
case "launchInNewTab":
|
||||||
|
handleError("Launching URL in a new tab...", "notice");
|
||||||
|
break;
|
||||||
case "copyPassword":
|
case "copyPassword":
|
||||||
handleError("Copying password to clipboard...", "notice");
|
handleError("Copying password to clipboard...", "notice");
|
||||||
break;
|
break;
|
||||||
|
@@ -105,6 +105,14 @@ function view(ctl, params) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "KeyG":
|
||||||
|
if (e.ctrlKey && e.target.selectionStart == e.target.selectionEnd) {
|
||||||
|
e.preventDefault();
|
||||||
|
self.popup.results[0].doAction(
|
||||||
|
e.shiftKey ? "launchInNewTab" : "launch"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user