1
0
Fork 0

Initial commit

This commit is contained in:
Gregory Eremin 2014-09-16 12:53:21 +04:00
commit 43c561b3ce
No known key found for this signature in database
GPG Key ID: 5EFA427EEC26E86C
2 changed files with 71 additions and 0 deletions

53
background.js Normal file
View File

@ -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();

18
manifest.json Normal file
View File

@ -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"]
}
}