Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const browser = chrome || browser
const browser = globalThis.browser || chrome

const tabQuery = (options, params = {}) => new Promise(res => {
if (!options.countPinnedTabs) params.pinned = false // only non-pinned tabs
Expand All @@ -15,15 +15,15 @@ const totalRemaining = options =>

const updateBadge = options => {
if (!options.displayBadge) {
browser.browserAction.setBadgeText({ text: "" })
browser.action.setBadgeText({ text: "" })
return;
}

Promise.all([windowRemaining(options), totalRemaining(options)])
.then(remaining => {
// console.log(remaining)
// remaining = [remainingInWindow, remainingInTotal]
browser.browserAction.setBadgeText({
browser.action.setBadgeText({
text: Math.min(...remaining).toString()
})
})
Expand Down Expand Up @@ -104,7 +104,12 @@ const displayAlert = (options, place) => new Promise((res, rej) => {
/{\s*(\S+)\s*}/g,
replacer
)
alert(renderedMessage);
chrome.notifications.create('tab-limiter-alert', {
type: 'basic',
iconUrl: 'icons/48.png',
title: 'Tab Limiter',
message: renderedMessage
}, () => res(true));
})

let tabCount = -1
Expand Down
13 changes: 6 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Tab Limiter",
"description": "Limit the number of open tabs – in total and per window",
"version": "0.3.0",
"version": "0.4.0",
"author": "Matthias Vogt",
"homepage_url": "https://github.com/matthias-vogt/tab-limiter",

Expand All @@ -10,7 +10,7 @@
"128": "icons/128.png"
},

"browser_action": {
"action": {
"default_icon": {
"48": "icons/48.png",
"128": "icons/128.png"
Expand All @@ -20,13 +20,12 @@
},
"options_page": "options.html",
"background": {
"scripts": [
"background.js"
]
"service_worker": "background.js"
},
"permissions": [
"storage"
"storage",
"notifications"
],

"manifest_version": 2
"manifest_version": 3
}
2 changes: 1 addition & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<meta charset="utf-8">
<link rel="stylesheet" href="options.css">
<script src="options.js"></script>
</head>

<body>
Expand Down Expand Up @@ -56,4 +55,5 @@ <h1>Options</h1>
<p class="message hidden">
Hello everyone, welcome to version 0.3.0! See the changelog at the <a href="https://github.com/matthias-vogt/tab-limiter/releases" target="_blank">github repo</a>. Thanks for using Tab Limiter! :)
</p>
<script src="options.js"></script>
</body>
6 changes: 3 additions & 3 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const browser = chrome || browser
const browser = globalThis.browser || chrome

const tabQuery = (options, params = {}) => new Promise(res => {
if (!options.countPinnedTabs) params.pinned = false // only non-pinned tabs
Expand All @@ -15,15 +15,15 @@ const totalRemaining = options =>

const updateBadge = options => {
if (!options.displayBadge) {
browser.browserAction.setBadgeText({ text: "" })
browser.action.setBadgeText({ text: "" })
return;
}

Promise.all([windowRemaining(options), totalRemaining(options)])
.then(remaining => {
// console.log(remaining)
// remaining = [remainingInWindow, remainingInTotal]
browser.browserAction.setBadgeText({
browser.action.setBadgeText({
text: Math.min(...remaining).toString()
})
})
Expand Down