I have wrote a small extension for numbering the tabs and it works fine. However when using with your add on, I notice the title on discarded tabs are not updated at all.
Do you aware why this is the case? Thank you.
const browser = window.browser || window.chrome
var update = function(details) {
var oldTitle = details.title
var newTitle = oldTitle
if(!newTitle) {
return
}
var numbers = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','9. ','10. ','11. ','12. ','13. ','14. ','15. ','16. ','17. ','18. ','19. ','20. ','21. ','22. ','23. ','24. ','25. ','26. ','27. ','28. ','29. ','30. ']
if (newTitle) {
if (numbers.includes(newTitle.substr(0,3)))
newTitle = newTitle.substr(3)
else if (numbers.includes(newTitle.substr(0,4)))
newTitle = newTitle.substr(4)
}
if(details.index < 31 && !newTitle.startsWith(numbers[details.index])) {
newTitle = numbers[details.index] + newTitle
}
if(oldTitle !== newTitle) {
try {
browser.tabs.executeScript(
details.id,
{
code : `document.title = ${JSON.stringify(newTitle)}`
}
)
console.log("executed: " + details.id)
} catch(e) {
console.log("Tab numbering error:", e)
}
}
}
function updateAll() {
browser.tabs.query({}, function(tabs) {
tabs.forEach(update)
})
}
browser.tabs.onMoved.addListener(updateAll)
browser.tabs.onCreated.addListener(updateAll)
browser.tabs.onAttached.addListener(updateAll)
browser.tabs.onDetached.addListener(updateAll)
browser.tabs.onDetached.addListener(updateAll)
// firefox seems to do this inconsistently, thus this setTimeout kludge:
browser.tabs.onRemoved.addListener(() => {
updateAll()
setTimeout(updateAll, 100)
setTimeout(updateAll, 500)
setTimeout(updateAll, 1000)
})
browser.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
update(tab)
})
updateAll()