Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ab3e48812 | |||
e950136ad2 | |||
3fcdc86679 | |||
1efcc58dc8 | |||
dd8c8b8d2c | |||
9c12be5c90 | |||
b0541bea2a | |||
16253ceea9 | |||
482901e626 | |||
8cb464f66e | |||
516190f38c | |||
ec9990bdb9 | |||
ea6c20ae51 | |||
9cd33f531b |
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2024 Rose / Tangent
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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()
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 546 B After Width: | Height: | Size: 546 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
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}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,9 @@
|
|||||||
# snap
|
# snap
|
||||||
|
|
||||||
The Snap balances your browsing habits by clearing tabs.
|
The Snap balances your browsing habits by clearing tabs.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This repo is hosted at https://gitea.tangentfox.com/tangent/The-Snap and force-pushed to GitHub when commits are made.
|
||||||
|
|
||||||
|
Feel free to submit pull requests or whatever, but know that I would have to manage them over there.
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* Randomly shuffle an array
|
|
||||||
* https://stackoverflow.com/a/2450976/1293256
|
|
||||||
* @param {Array} array The array to shuffle
|
|
||||||
* @return {String} The first item in the shuffled array
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
chrome.browserAction.onClicked.addListener(function() {
|
|
||||||
chrome.tabs.query({}, function(tabs) {
|
|
||||||
chrome.browserAction.getBadgeText({}, function(text) {
|
|
||||||
ok = confirm("Are you sure you want to snap " + text + " tabs?")
|
|
||||||
if (ok) {
|
|
||||||
shuffle(tabs)
|
|
||||||
let count = Math.floor(tabs.length / 2) + 1
|
|
||||||
tabs = tabs.slice(1, count)
|
|
||||||
let ids = [];
|
|
||||||
for (tab in tabs) {
|
|
||||||
ids.push(tabs[tab].id)
|
|
||||||
}
|
|
||||||
chrome.tabs.remove(ids)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
function updateCount() {
|
|
||||||
chrome.tabs.query({}, function(tabs) {
|
|
||||||
chrome.browserAction.setBadgeText({ text: "" + Math.floor(tabs.length / 2) })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.tabs.onCreated.addListener(function() {
|
|
||||||
updateCount()
|
|
||||||
})
|
|
||||||
chrome.tabs.onRemoved.addListener(function() {
|
|
||||||
updateCount()
|
|
||||||
})
|
|
||||||
chrome.windows.onCreated.addListener(function() {
|
|
||||||
updateCount()
|
|
||||||
})
|
|
||||||
chrome.windows.onRemoved.addListener(function() {
|
|
||||||
updateCount()
|
|
||||||
})
|
|
||||||
|
|
||||||
updateCount()
|
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 1.1 KiB |
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"manifest_version": 2,
|
|
||||||
"name": "The Snap",
|
|
||||||
"description": "Too many tabs open? Halve your workload.",
|
|
||||||
"version": "1.0",
|
|
||||||
"icons": {
|
|
||||||
"16": "images/gauntlet16.png",
|
|
||||||
"32": "images/gauntlet32.png",
|
|
||||||
"48": "images/gauntlet48.png",
|
|
||||||
"128": "images/gauntlet128.png"
|
|
||||||
},
|
|
||||||
"browser_action": {},
|
|
||||||
"permissions": [ "tabs" ],
|
|
||||||
"background": {
|
|
||||||
"scripts": [ "background.js" ],
|
|
||||||
"persistent": false
|
|
||||||
}
|
|
||||||
}
|
|