preparing to make Manifest v2 versions as alternatives because of how fucked the rollout of v3 is
This commit is contained in:
56
Manifest v3 version/background.js
Normal file
56
Manifest v3 version/background.js
Normal file
@@ -0,0 +1,56 @@
|
||||
// Cross-platform namespace support
|
||||
window.browser = (function () {
|
||||
return window.browser ||
|
||||
window.msBrowser ||
|
||||
window.chrome;
|
||||
})();
|
||||
|
||||
var shuffle = function (array) {
|
||||
var currentIndex = array.length;
|
||||
var temporaryValue, randomIndex;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex -= 1;
|
||||
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex];
|
||||
array[currentIndex] = array[randomIndex];
|
||||
array[randomIndex] = temporaryValue;
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
browser.action.onClicked.addListener(function() {
|
||||
browser.tabs.query({}, function(tabs) {
|
||||
let count = Math.floor(tabs.length / 2) + 1 // I don't remember why we need an extra +1 here, but it is necessary
|
||||
var ok = confirm("Are you sure you want to close " + count + " tabs?")
|
||||
if (ok) {
|
||||
shuffle(tabs)
|
||||
tabs = tabs.slice(1, count)
|
||||
let tab_identifiers = [];
|
||||
for (tab in tabs) {
|
||||
tab_identifiers.push(tabs[tab].id)
|
||||
}
|
||||
browser.tabs.remove(ids)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function updateCount() {
|
||||
browser.tabs.query({}, function(tabs) {
|
||||
let count = Math.floor(tabs.length / 2)
|
||||
browser.action.setBadgeText({ text: "" + count })
|
||||
})
|
||||
}
|
||||
|
||||
browser.tabs.onCreated.addListener(updateCount)
|
||||
browser.tabs.onRemoved.addListener(updateCount)
|
||||
browser.windows.onCreated.addListener(updateCount)
|
||||
browser.windows.onRemoved.addListener(updateCount)
|
||||
|
||||
updateCount()
|
BIN
Manifest v3 version/images/gauntlet128.png
Normal file
BIN
Manifest v3 version/images/gauntlet128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
Manifest v3 version/images/gauntlet16.png
Normal file
BIN
Manifest v3 version/images/gauntlet16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 546 B |
BIN
Manifest v3 version/images/gauntlet48.png
Normal file
BIN
Manifest v3 version/images/gauntlet48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
34
Manifest v3 version/manifest.json
Normal file
34
Manifest v3 version/manifest.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "The Snap",
|
||||
"description": "Too many tabs open? Halve your workload.",
|
||||
"version": "1.1.3",
|
||||
"icons": {
|
||||
"16": "images/gauntlet16.png",
|
||||
"48": "images/gauntlet48.png",
|
||||
"128": "images/gauntlet128.png"
|
||||
},
|
||||
"author": "rose@tangentfox.com",
|
||||
"homepage_url": "https://blog.tangentfox.com/the-snap-browser-extension/",
|
||||
"developer": {
|
||||
"name": "Rose (Tangent) Liverman",
|
||||
"url": "https://blog.tangentfox.com/the-snap-browser-extension/"
|
||||
},
|
||||
"action": {},
|
||||
"permissions": [
|
||||
"tabs"
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.js",
|
||||
"scripts": [ "background.js" ],
|
||||
"persistent": false
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "{7b9819b6-6bd3-4cb8-a5b3-9ae6eb2e75ea}"
|
||||
},
|
||||
"gecko_android": {
|
||||
"id": "{7b9819b6-6bd3-4cb8-a5b3-9ae6eb2e75e0}"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user