Last active
December 14, 2015 03:39
-
-
Save akhilstanis/5023098 to your computer and use it in GitHub Desktop.
Fork of Tab Number Chrome Extension @ https://chrome.google.com/webstore/detail/tab-number/dnndfognablbihihgnilabcegjjkiekj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Regexp for extracting title | |
var parseTitle = function(title) { | |
var parsed = title.match(/^\d+\.\s(.+)$/); | |
return ((parsed && parsed.pop()) || title); | |
}; | |
var update = function(details) { | |
var id = details.id; | |
var index = details.index; | |
var title = parseTitle(details.title); | |
title = (index + 1) + '. ' + title; | |
try { | |
chrome.tabs.executeScript( | |
id, | |
{ | |
code : "document.title = '" + title + "';" | |
} | |
); | |
console.log("executed: " + id); | |
} catch(e) {} | |
}; | |
function updateAll() { | |
chrome.tabs.query({}, function(tabs) { | |
for (var i = 0, tab; tab = tabs[i]; i++) { | |
update(tab); | |
} | |
}); | |
} | |
chrome.tabs.onMoved.addListener(function(id) { | |
updateAll(); | |
}); | |
chrome.tabs.onRemoved.addListener(function(id) { | |
updateAll(); | |
}); | |
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | |
if(changeInfo.status == 'complete') | |
update(tab); | |
}); | |
updateAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment