-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to allow opening of the popup in new tab as default
- Loading branch information
Showing
3 changed files
with
69 additions
and
17 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
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 |
---|---|---|
|
@@ -115,25 +115,44 @@ function tabActiveChanged(tab) { | |
updateTabCountDebounce(); | ||
} | ||
|
||
async function openAsOwnTab() { | ||
var tabs = await browser.tabs.query({}); | ||
for (var i = 0; i < tabs.length; i++) { | ||
var tab = tabs[i]; | ||
if (tab.url.indexOf("popup.html") > -1) { | ||
await browser.windows.update(tab.windowId, { focused: true }); | ||
await browser.tabs.highlight({ windowId: tab.windowId, tabs: tab.index }); | ||
return; | ||
} | ||
} | ||
await browser.tabs.create({ url: "popup.html" }); | ||
} | ||
|
||
async function setupPopup() { | ||
if (typeof localStorage["openInOwnTab"] === "undefined") localStorage["openInOwnTab"] = "0"; | ||
var openInOwnTab = false | ||
try { | ||
openInOwnTab = !!JSON.parse(localStorage["openInOwnTab"]); | ||
} catch (e) { | ||
openInOwnTab = false; | ||
} | ||
console.log(openInOwnTab); | ||
if(openInOwnTab) { | ||
await browser.browserAction.setPopup({ popup: "" }); | ||
await browser.browserAction.onClicked.addListener(openAsOwnTab); | ||
}else{ | ||
await browser.browserAction.setPopup({ popup: "popup.html?popup=true" }); | ||
await browser.browserAction.onClicked.removeListener(openAsOwnTab); | ||
} | ||
} | ||
|
||
async function setupListeners() { | ||
|
||
await browser.browserAction.setPopup({ popup: "popup.html?popup=true" }); | ||
await browser.contextMenus.removeAll(); | ||
await browser.contextMenus.create({ | ||
title: "Open in own tab", | ||
contexts: ["browser_action"], | ||
onclick: async function onclick() { | ||
var tabs = await browser.tabs.query({}); | ||
for (var i = 0; i < tabs.length; i++) { | ||
var tab = tabs[i]; | ||
if (tab.url.indexOf("popup.html") > -1) { | ||
await browser.windows.update(tab.windowId, { focused: true }); | ||
await browser.tabs.highlight({ windowId: tab.windowId, tabs: tab.index }); | ||
return; | ||
} | ||
} | ||
await browser.tabs.create({ url: "popup.html" }); | ||
} }); | ||
onclick: openAsOwnTab }); | ||
await browser.contextMenus.create({ | ||
title: "Donate to keep Extensions Alive", | ||
"contexts": ["browser_action"], | ||
|
@@ -166,7 +185,7 @@ async function setupListeners() { | |
chrome.tabs.create({ url: 'mailto:[email protected]' }); | ||
} }); | ||
|
||
// browser.browserAction.onClicked.addListener(); | ||
setupPopup(); | ||
|
||
browser.tabs.onCreated.removeListener(tabAdded); | ||
browser.tabs.onUpdated.removeListener(tabRemoved); | ||
|
@@ -194,8 +213,6 @@ async function setupListeners() { | |
updateTabCountDebounce(); | ||
} | ||
|
||
|
||
|
||
// Returns a function, that, as long as it continues to be invoked, will not | ||
// be triggered. The function will be called after it stops being called for | ||
// N milliseconds. If `immediate` is passed, trigger the function on the | ||
|
@@ -374,6 +391,12 @@ browser.commands.onCommand.addListener(function (command) { | |
} | ||
}); | ||
|
||
browser.runtime.onMessage.addListener(function(request, sender, sendResponse) { | ||
if (request.command == "reload_popup_controls") { | ||
setupPopup(); | ||
} | ||
}); | ||
|
||
(async function () { | ||
var windows = await browser.windows.getAll({ populate: true }); | ||
localStorage["windowAge"] = JSON.stringify([]); | ||
|