Skip to content

Instantly share code, notes, and snippets.

@akhilstanis
Last active December 14, 2015 03:39
Show Gist options
  • Save akhilstanis/5023098 to your computer and use it in GitHub Desktop.
Save akhilstanis/5023098 to your computer and use it in GitHub Desktop.
// 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