Manager: "Edit" button re-uses existing tabs, shift-click opens a new window
This commit is contained in:
parent
fec5306037
commit
8e6e1f97b2
|
@ -33,6 +33,9 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
|||
case "healthCheck":
|
||||
getDatabase(function() { sendResponse(true); }, function() { sendResponse(false); });
|
||||
break;
|
||||
case "openURL":
|
||||
openURL(request);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -321,3 +324,22 @@ chrome.tabs.onAttached.addListener(function(tabId, data) {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
function openURL(options) {
|
||||
chrome.tabs.query({currentWindow: true, url: options.url}, function(tabs) {
|
||||
// switch to an existing tab with the requested url
|
||||
if (tabs.length) {
|
||||
chrome.tabs.highlight({windowId: tabs[0].windowId, tabs: tabs[0].index}, function (window) {});
|
||||
} else {
|
||||
delete options.method;
|
||||
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
|
||||
// re-use an active new tab page
|
||||
if (tabs.length && tabs[0].url.match(/^chrome:\/\/newtab\/?$/)) {
|
||||
chrome.tabs.update(options);
|
||||
} else {
|
||||
chrome.tabs.create(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
25
manage.js
25
manage.js
|
@ -93,6 +93,31 @@ function createStyleElement(style) {
|
|||
}
|
||||
var editLink = e.querySelector(".style-edit-link");
|
||||
editLink.setAttribute("href", editLink.getAttribute("href") + style.id);
|
||||
editLink.addEventListener("click", function(event) {
|
||||
if (!event.altKey) {
|
||||
var left = event.button == 0, middle = event.button == 1,
|
||||
shift = event.shiftKey, ctrl = event.ctrlKey;
|
||||
var openWindow = left && shift && !ctrl;
|
||||
var openBackgroundTab = (middle && !shift) || (left && ctrl && !shift);
|
||||
var openForegroundTab = (middle && shift) || (left && ctrl && shift);
|
||||
if (openWindow || openBackgroundTab || openForegroundTab) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var url = event.target.href || event.target.parentNode.href;
|
||||
if (openWindow) {
|
||||
var options = prefs.getPref('windowPosition', {});
|
||||
options.url = url;
|
||||
chrome.windows.create(options);
|
||||
} else {
|
||||
chrome.extension.sendMessage({
|
||||
method: "openURL",
|
||||
url: url,
|
||||
active: openForegroundTab
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
e.querySelector(".enable").addEventListener("click", function(event) { enable(event, true); }, false);
|
||||
e.querySelector(".disable").addEventListener("click", function(event) { enable(event, false); }, false);
|
||||
e.querySelector(".check-update").addEventListener("click", doCheckUpdate, false);
|
||||
|
|
10
popup.js
10
popup.js
|
@ -156,14 +156,8 @@ function openLinkInTabOrWindow(event) {
|
|||
|
||||
function openLink(event) {
|
||||
event.preventDefault();
|
||||
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
|
||||
if (tabs && tabs.length && tabs[0].url.match(/^chrome:\/\/newtab\/?$/)) {
|
||||
chrome.tabs.update({url: event.target.href});
|
||||
close(); // close the popup
|
||||
} else {
|
||||
chrome.tabs.create({url: event.target.href});
|
||||
}
|
||||
});
|
||||
chrome.extension.sendMessage({method: "openURL", url: event.target.href});
|
||||
close();
|
||||
}
|
||||
|
||||
function handleUpdate(style) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user