Skip to content

Commit

Permalink
Merge pull request #4 from jmmerz/feature/version-1.4.0
Browse files Browse the repository at this point in the history
Feature/version 1.4.0
  • Loading branch information
jmmerz authored Feb 7, 2019
2 parents 7865574 + bb834f7 commit 48a8039
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 67 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tab Counter Wide

This is a fork of Loirooriol's fantastic [Tab Counter Plus](https://github.com/Loirooriol/tab-counter-plus) to do some slightly messy customization. This may not be kept entirely up to date with the original repo. Please see the README on that page for full details.
This is a fork of Loirooriol's fantastic [Tab Counter Plus](https://github.com/Loirooriol/tab-counter-plus) to do some slightly messy customization to allow for a wider tab counter. Please see the README on that page for full details.

This provides the ability to include the current tab index in addition to the total number of tabs in the window.

Expand Down Expand Up @@ -31,6 +31,12 @@ toolbarbutton#tab-counter-wide_jmmerz_github-browser-action > .toolbarbutton-bad

## Version History:

#### [1.4.0](https://github.com/jmmerz/tab-counter-wide/releases/tag/v1.4.0):
* Fix performance issue that could cause browser to slow down, especially with a moderate to large
number of tabs open.
* Switch to a better name.
* Add standardized instructions to make this this extension more usable.

#### [1.3.0](https://github.com/jmmerz/tab-counter-wide/releases/tag/v1.3.0):
* Update name to "Tab Counter Wide" to better describe what's unique about it.

Expand Down
35 changes: 11 additions & 24 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2018 Oriol Brufau
* Additions 2018 by Jonathon Merz
* Additions 2019 by Jonathon Merz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@ let HIDDEN_TABS_SHOW_WHEN_ZERO = "showWhenZero";

let prefs = {
actionIconHeightPx: 28,
actionIconWidthPx: 84,
actionIconWidthPx: 56,
bgColor: "#ffffff",
bgColorEnabled: false,
textColor: "#000000",
Expand All @@ -61,24 +61,6 @@ let hiddenTabCounts = new Map();
let tabIndexes = new Map();
let lastTime = new Map();
let removedTabIds = new Set();
/**
* This is unfortunately necessary to handle tracking hidden/un-hidden tabs
* since there is no tabs.onHidden/onUnhidden event.
*/
let windowRecountIntervals = new Map();

function clearWindowRecountInterval(windowId) {
clearInterval(windowId);
windowRecountIntervals.delete(windowId);
}

function setWindowRecountInterval(windowId) {
windowRecountIntervals.set(windowId,
setInterval(() => {
updateTabCountsAndIndexForWindow(windowId);
}, 500)
);
}


function updateIcon(windowId, tabNum = -1, tabCount = -1, hiddenTabCount = -1) {
Expand Down Expand Up @@ -119,12 +101,13 @@ function updateIcon(windowId, tabNum = -1, tabCount = -1, hiddenTabCount = -1) {
let fontSize = 26-len;
if(fontSize > prefs.maxFontSize) fontSize = prefs.maxFontSize;
// for text-anchor below: Can use 'start' and replace x="50%" below with x="0%"...
// TODO: Try making font selectable? Other font: Consolas
let path = "data:image/svg+xml," + encodeURIComponent(`<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="${prefs.actionIconWidthPx}" height="${prefs.actionIconHeightPx}">
<style type="text/css"><![CDATA[
text {
dominant-baseline: central;
font-family: Consolas, monospace;
font-family: monospace;
font-size: ${fontSize}px;
font-weight: ${prefs.fontWeight};
text-anchor: middle;
Expand Down Expand Up @@ -209,6 +192,7 @@ function updateTabCountsAndIndexForTabsInWindow(windowId, tabs, updateInfo = DEF
try {
browser.browserAction.getBadgeText({windowId: browser.windows.WINDOW_ID_CURRENT});
} catch (error) {
console.log("setting polyfill");
windowIdPolyfill({
title: "setTitle",
text: "setBadgeText",
Expand All @@ -227,12 +211,10 @@ function updateTabCountsAndIndexForTabsInWindow(windowId, tabs, updateInfo = DEF
browser.windows.onCreated.addListener(function ({id}) {
//console.log("windows.onCreated: windowId: " + id);
updateTabCountsAndIndexForWindow(id);
setWindowRecountInterval(id);
});

browser.windows.onRemoved.addListener(function (windowId) {
//console.log("windows.onRemoved: windowId: " + windowId);
clearWindowRecountInterval(windowId);
visibleTabCounts.delete(windowId);
hiddenTabCounts.delete(windowId);
tabIndexes.delete(windowId);
Expand Down Expand Up @@ -278,11 +260,16 @@ function updateTabCountsAndIndexForTabsInWindow(windowId, tabs, updateInfo = DEF
updateTabCountsAndIndexForWindow(oldWindowId);
});

// Use onUpdated with a filter to catch only for the "hidden" property as an
// "onHidden"/"onUnhidden" handler.
browser.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
updateTabCountsAndIndexForWindow(tab.windowId);
}, {properties: ["hidden"]});

// Initialize the counts at startup
let windows = await browser.windows.getAll({populate: true});
for (let {id, tabs} of windows) {
updateTabCountsAndIndexForTabsInWindow(id, tabs);
setWindowRecountInterval(id);
}

})();
Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ IGNORE_FILES[${#IGNORE_FILES[@]}]='**/*.vim'
IGNORE_FILES[${#IGNORE_FILES[@]}]='artifacts'
IGNORE_FILES[${#IGNORE_FILES[@]}]='docs'
IGNORE_FILES[${#IGNORE_FILES[@]}]='build.sh'
IGNORE_FILES[${#IGNORE_FILES[@]}]='*.txt'
IGNORE_FILES[${#IGNORE_FILES[@]}]='*.md'


manifest="./manifest.json"
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"short_name": "Tab Counter Wide",
"author": "Jonathon Merz",
"homepage_url": "https://github.com/jmmerz/tab-counter-wide",
"version": "1.3.0",
"description": "Shows the number of tabs in the window, current tab index and optionally the number of hidden tabs.",
"version": "1.4.0",
"description": "Shows the number of tabs in each window and current tab index.",
"manifest_version": 2,
"applications": {
"gecko": {
Expand Down
75 changes: 39 additions & 36 deletions options.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright 2018 Oriol Brufau
Additions 2018 by Jonathon Merz
Additions 2019 by Jonathon Merz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,6 +74,44 @@ <h2>Counter style</h3>
<br />
-->

<div>
<h3>Counter Size</h3>
<b><i>Must match the values set in your userChrome.css file. See the Readme file at Add-on Homepage above for instructions.</i></b>
<br />
<label for="actionIconWidthPx">Counter icon width (px)</label>
<input type="number" id="actionIconWidthPx" value="84" />
<label for="actionIconWidthPx"><i>(Set to the <b>width:</b> attribute used in userChrome.css)</i></label>
<br />

<label for="actionIconHeightPx">Counter icon height (px)</label>
<input type="number" id="actionIconHeightPx" value="28" />
<label for="actionIconHeightPx"><i>(Set to the <b>height:</b> attribute used in userChrome.css)</i></label>
<br />

<h3>Counter Colors</h3>

<label for="bgColor">Background color:</label>
<input type="checkbox" id="bgColorEnabled" />
<input type="color" id="bgColor" value="#ffffff" data-if="bgColorEnabled" />
<input type="color" id="bgColorDisabled" value="#ffffff" data-if="bgColorDisabled" disabled />
<br />

<label for="textColor">Text color:</label>
<input type="checkbox" id="textColorEnabled" checked />
<input type="color" id="textColor" value="#000000" data-if="textColorEnabled" />
<input type="color" id="textColorDisabled" value="#000000" data-if="textColorDisabled" disabled />
<br />

<h3>Counter Font</h3>
<label for="maxFontSize">Max Font Size</label>
<input type="number" id="maxFontSize" value="18" />
<br />

<label for="fontWeight">Font Weight</label>
<input type="number" id="fontWeight" min="100" max="900" step="100" value="100" />
<br />
</div>

<div>
<h3>Hidden Tab Behavior</h3>
<input type="radio" name="hiddenTabsOption" id="hiddenTabsOption-doNotShow" value="doNotShow" checked />
Expand Down Expand Up @@ -101,41 +139,6 @@ <h3>Tooltip data</h3>
<input type="text" id="titleHiddenTabsPrefix" value="Hidden tabs: " />
<br data-bigger />

<h3>Counter colors</h3>
</div>

<div>
<label for="bgColor">Background color:</label>
<input type="checkbox" id="bgColorEnabled" />
<input type="color" id="bgColor" value="#ffffff" data-if="bgColorEnabled" />
<input type="color" id="bgColor" value="#ffffff" data-if="bgColorDisabled" disabled />
<br />

<label for="textColor">Text color:</label>
<input type="checkbox" id="textColorEnabled" checked />
<input type="color" id="textColor" value="#000000" data-if="textColorEnabled" />
<input type="color" id="textColor" value="#000000" data-if="textColorDisabled" disabled />
<br />

<h3>Counter Size</h3> <!-- TODO: EXPLAIN: Must match userChrome.css -->
<label for="actionIconWidthPx">Counter icon width (px)</label>
<input type="number" id="actionIconWidthPx" value="84" />
<label for="actionIconWidthPx"><i>(Set to the <b>width:</b> attribute used in userChrome.css)</i></label>
<br />

<label for="actionIconHeightPx">Counter icon height (px)</label>
<input type="number" id="actionIconHeightPx" value="28" />
<label for="actionIconHeightPx"><i>(Set to the <b>height:</b> attribute used in userChrome.css)</i></label>
<br />

<h3>Fonts</h3>
<label for="maxFontSize">Max Font Size</label>
<input type="number" id="maxFontSize" value="18" />
<br />

<label for="fontWeight">Font Weight</label>
<input type="number" id="fontWeight" min="100" max="900" step="100" value="100" />
<br />
</div>

<!--
Expand Down
7 changes: 5 additions & 2 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2018 Oriol Brufau
* Additions 2018 by Jonathon Merz
* Additions 2019 by Jonathon Merz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,14 +24,17 @@
return item.valueAsNumber;
case undefined:
// RadioNodeList
if(item.value) {
return item.value;
}
let {value} = item;
try {
let parsed = JSON.parse(value);
if (Object(parsed) !== parsed) {
return parsed;
}
} catch (error) {}
return value;
return item.value;
default:
return item.value;
}
Expand Down
2 changes: 1 addition & 1 deletion popup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright 2018 Oriol Brufau
Additions 2018 by Jonathon Merz
Additions 2019 by Jonathon Merz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2018 Oriol Brufau
* Additions 2018 by Jonathon Merz
* Additions 2019 by Jonathon Merz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 48a8039

Please sign in to comment.