From 43c561b3cefe0bc6d63c668741aa811194c041ef Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Tue, 16 Sep 2014 12:53:21 +0400 Subject: [PATCH] Initial commit --- background.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 18 +++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 background.js create mode 100644 manifest.json diff --git a/background.js b/background.js new file mode 100644 index 0000000..b05d4d4 --- /dev/null +++ b/background.js @@ -0,0 +1,53 @@ +sym = '^'; +chrome.runtime.getPlatformInfo(function(info) { + if (info.os === 'mac') { + sym = '⌘'; + } +}); + +var update = function(info) { + // Ignore pinned tabs + if (info.pinned) { + return; + } + + // Ignore chrome pages + if (!info.url.match(/^http/)) { + return; + } + + // Ignore Chrome Web Store (restricted) + if (info.url.indexOf("https://chrome.google.com/webstore/") === 0) { + return; + } + + var title = info.title, + regexp = new RegExp('^' + (sym === '^' ? '\\^' : sym) + '\\d+\\s(.*)'), + m = regexp.exec(title); + + if (m && m.length == 2) { + title = m[1]; + } + + title = sym + (info.index + 1) +' ' + title; + + chrome.tabs.executeScript(info.id, { + code: "document.title = '" + title + "';" + }); +}; + +function updateAll() { + chrome.tabs.query({}, function(tabs) { + for (var i = 0, tab; tab = tabs[i]; i++) { + update(tab); + } + }); +} + +chrome.tabs.onMoved.addListener(updateAll); +chrome.tabs.onRemoved.addListener(updateAll); +chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tabInfo) { + update(tabInfo); +}); + +updateAll(); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..be2a5d1 --- /dev/null +++ b/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + + "name": "Numered Tabs", + "description": "Shows tab numbers for fast switching", + "version": "1.0", + + "permissions": [ + "tabs", + "http://*/*", + "https://*/*" + ], + + "background": { + "persistent": false, + "scripts": ["background.js"] + } +}