Skip to content

Instantly share code, notes, and snippets.

@deathau
Created April 16, 2024 06:51
Show Gist options
  • Save deathau/e712cb7c4f020028cbb855dfca894946 to your computer and use it in GitHub Desktop.
Save deathau/e712cb7c4f020028cbb855dfca894946 to your computer and use it in GitHub Desktop.
Inoreader unread badge extension for Wavebox
chrome.runtime.onMessage.addListener(async (payload, sender)=>{
if (payload.type === "setBadge") {
// Check if my message is from an app
const {isApp} = await chrome.waveboxApps.getInfo(sender.tab.id)
if (isApp) {
const count = parseInt(payload.count)
if (isNaN(count)) await chrome.waveboxApps.setBadge(sender.tab.id, {count: 0, activity: true})
else await chrome.waveboxApps.setBadge(sender.tab.id, {count, activity: false})
}
}
})
const freq = 5 * 60 * 1000 // check for updates every five minutes
// function to get unread count from the content page
// return 0 to clear the badge, or NaN for a blank activity badge
const getCount = () => parseInt(total_unread_cnt.textContent)
// you *shouldn't* have to touch anything below here
let prevCount = null
const updateBadge = () => {
const count = getCount()
console.debug("[Wavebox] Checking new badge count", {count}) // set your console level to "verbose" if you want to see this message
if(count !== prevCount) {
chrome.runtime.sendMessage({type: "setBadge", count})
prevCount = count
}
}
updateBadge()
setInterval(updateBadge, freq)
{
"manifest_version": 3,
"version": "1",
"name": "inoreader unread count",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1oh0kyuK0Xy45BVlxTlR1rDFqs7wIPLTLzDqTL+mSyfBf6O6W50HXy2BQPLju8SD7boOH8gJkFQY9/ptHS0ghviuGpVjmg0BuJ8ymZFdd8XPmhAFqtpJti/tkW00/FXzERvkCD8K9Ww5Mn06cTcUxtE28gCjpaUHl5SpBr9Lr1Oz2k9AdBRhnslq5gFdWzwfYrVt9v0ENTNcGjl/uI7pm9bqRE+HP0gb3p40bznq0YS0KT7vkoHkpbTHN7vxHI8jd5MmhNWihfp86TWqC3ebqNhgOgFO+Hm1KMJj0Yfh+jUp5GHR7xZ4L7+IWhcyiNWNJy2UAiIFzPqziDRZ3nYPgwIDAQAB",
"background": {
"service_worker": "background.js"
},
"permissions": [
"waveboxApps"
],
"content_scripts": [
{
"matches": [
"https://*.inoreader.com/*"
],
"js": [
"contentscript.js"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment