Pith - fret
fret/fret_chrome/background.js [1.0 kb]
Modified: 17:14:08 138 026 (04 Aug 026)
19 Days Ago
const BADGE_BG = "#486860";
const tallies = new Map();

chrome.action.setBadgeBackgroundColor({ color: BADGE_BG });
chrome.action.setBadgeTextColor?.({ color: "#ffffff" });

function render(tabId) {
  let total = 0;
  for (const n of tallies.get(tabId)?.values() ?? []) total += n;
  const text = !total ? "" : total > 999 ? "999+" : String(total);
  chrome.action.setBadgeText({ tabId, text }).catch(() => {});
}

chrome.runtime.onMessage.addListener((msg, sender) => {
  if (msg?.type !== "wb-count") return;
  const tabId = sender.tab?.id;
  if (tabId === undefined) return;
  if (!tallies.has(tabId)) tallies.set(tabId, new Map());
  tallies.get(tabId).set(sender.frameId ?? 0, msg.count | 0);
  render(tabId);
});

chrome.tabs.onUpdated.addListener((tabId, info) => {
  if (info.status !== "loading") return;
  tallies.delete(tabId);
  chrome.action.setBadgeText({ tabId, text: "" }).catch(() => {});
});

chrome.tabs.onRemoved.addListener(tabId => tallies.delete(tabId));
Updates
Kerf - Android 157.026
Kiln - Android 157.026
Wedge - Android 156.026
Whittle - Linux 155.026
Grit - Firefox/Chrome 154.026

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)
0.00199
256,828 (+82)