Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkrist committed Sep 19, 2019
0 parents commit 7a3037e
Show file tree
Hide file tree
Showing 11 changed files with 1,462 additions and 0 deletions.
674 changes: 674 additions & 0 deletions COPYING.txt

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
# Chromium Update Notifications

This extension will periodically check [Woolyss' website](https://chromium.woolyss.com/) and display a "New" icon badge once the version for the configured platform and tag is different to the one you're currently using. Nothing more, nothing less.

## Installation

1. Review source code of this extension
2. Clone repository or download a [release](https://github.com/kkkrist/chromium-notifier/releases) and unpack it into a local folder
3. Navigate to [chrome://extensions](chrome://extensions)
4. Enable developer mode
4. Drag-and-drop the folder into the browser window or click on "Load unpacked extension" and select folder

## Configuration

Click on the extension's icon, select platform (mac, win32 or win64) and tag – i.e. the Chromium version you're using.
Binary file added img/icon128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions js/background.js
@@ -0,0 +1,89 @@
const getMetaInfo = (div, arch, tag) => {
const id = `#${arch}-${tag}`
let textContent = div.querySelector(id).querySelector('details summary')
.textContent

if (!textContent.match(/\([0-9]+\)/)) {
textContent = textContent.replace(//, ' () • ')
}

const info = textContent
.split(' (')
.map(a => a.split(/\) . /))
.flat()
.map(a => a.split(' • '))
.flat()

return {
build: info[1],
date: new Date(info[2]).getTime(),
link: div.querySelector(id).querySelector('b a, strong a').href,
tag,
version: info[0].trimStart().trimEnd()
}
}

const getVersions = div =>
Array.from(div.querySelectorAll('.chromium'))
.filter(a => a.id.match(/^(mac|win)/))
.reduce((acc, el) => {
const arr = el.id.split('-')
const arch = arr.shift()
const item = getMetaInfo(div, arch, arr.join('-'))
if (acc[arch]) {
acc[arch].push(item)
} else {
acc[arch] = [item]
}
return acc
}, {})

const getWrapper = () =>
fetch('https://chromium.woolyss.com/')
.then(res => res.text())
.then(text => {
const wrapper = document.createElement('div')
wrapper.innerHTML = text
.replace(/^.*<body>/, '')
.replace(/<\/body>.*$/, '')
.replace(/<script.*<\/script>/g, '')
return wrapper
})
.catch(handleError)

const handleError = e => {
console.error(e)
localStorage.setItem('error', e.message)
chrome.browserAction.setBadgeBackgroundColor({ color: [180, 0, 20, 255] });
chrome.browserAction.setBadgeText({ text: 'Error!' })
}

const main = () => {
const arch = localStorage.getItem('arch')
const tag = localStorage.getItem('tag')
const timestamp = Number(localStorage.getItem('timestamp'))
const versions = JSON.parse(localStorage.getItem('versions'))
const current = versions && arch && versions[arch].find(v => v.tag === tag)

if (!versions || timestamp + 3 * 60 * 60 * 1000 < new Date().getTime()) {
getWrapper().then(div => {
const newVersions = getVersions(div)
const currentVersion = window.navigator.userAgent.match(
/Chrome\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
)[1]

localStorage.removeItem('error')
localStorage.setItem('timestamp', new Date().getTime())
localStorage.setItem('versions', JSON.stringify(newVersions))


if (current && currentVersion !== current.version) {
chrome.browserAction.setBadgeBackgroundColor({ color: [0, 150, 180, 255] })
chrome.browserAction.setBadgeText({ text: 'New' })
}
}, handleError)
}
}

main()
setInterval(main, 30 * 60 * 1000)
165 changes: 165 additions & 0 deletions js/popup.js
@@ -0,0 +1,165 @@
import { h, app } from './vendor/hyperapp-2.0.1.js'

chrome.browserAction.setBadgeText({ text: '' })
chrome.browserAction.setBadgeBackgroundColor({ color: [0, 150, 180, 255] })

const arch = localStorage.getItem('arch')
const currentVersion = window.navigator.userAgent.match(
/Chrome\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
)[1]
const error = localStorage.getItem('error')
const selectStyle = {
display: 'block',
height: '2em',
marginBottom: '0.5rem',
width: '100%'
}
const tag = localStorage.getItem('tag')
const timestamp = Number(localStorage.getItem('timestamp'))
const versions = JSON.parse(localStorage.getItem('versions'))

const getMeta = state => {
const current =
state.arch && versions[state.arch].find(({ tag }) => tag === state.tag)
return current
? [
h('ul', { style: { listStyleType: 'none', paddingLeft: 0 } }, [
h('li', {}, [
h('span', {}, 'Latest: '),
h('a', { href: current.link, target: '_blank' }, current.version)
]),

h(
'li',
{},
`Build: ${current.build} (${new Date(
current.date
).toLocaleDateString()})`
),

h(
'li',
{
style: {
color: currentVersion !== current.version ? 'red' : undefined,
marginTop: '0.5em'
}
},
[
h('span', {}, `Yours: ${currentVersion} `),
h('span', {}, currentVersion !== current.version ? '⚠️' : '✅')
]
)
])
]
: []
}

app({
init: { arch, tag },
view: state =>
h('div', {}, [
h(
'h1',
{ style: { fontSize: '1.2em', margin: 0 } },
'Chromium Update Notifications'
),

h('p', { style: { marginTop: 0 } }, [
h('span', {}, 'based on '),
h(
'a',
{ href: 'https://chromium.woolyss.com/', target: '_blank' },
'Woolyss'
)
]),

h('label', {}, [
h('span', {}, 'Platform'),
h(
'select',
{
disabled: !versions,
onChange: (state, e) => {
localStorage.setItem('arch', e.target.value)
localStorage.removeItem('tag')
chrome.browserAction.setBadgeText({ text: '' })
return {
...state,
arch: e.target.value,
tag: undefined
}
},
style: selectStyle
},
[
h(
'option',
{ disabled: state.arch, value: '' },
'Choose platform…'
),
...Object.keys(versions || {}).map(arch =>
h(
'option',
{ selected: arch === state.arch ? true : undefined },
arch
)
)
]
)
]),

h('label', {}, [
h('span', {}, 'Tag'),
h(
'select',
{
disabled: !state.arch,
onChange: (state, e) => {
localStorage.setItem('tag', e.target.value)
const current =
state.arch &&
versions[state.arch].find(({ tag }) => tag === e.target.value)

if (current && current.version !== currentVersion) {
chrome.browserAction.setBadgeText({ text: 'New' })
} else {
chrome.browserAction.setBadgeText({ text: '' })
}

return {
...state,
tag: e.target.value
}
},
style: selectStyle
},
[
h('option', { disabled: state.tag, value: '' }, 'Choose tag…'),
...(state.arch
? versions[state.arch].map(item =>
h(
'option',
{ selected: item.tag === state.tag ? true : undefined },
item.tag
)
)
: [])
]
)
]),

getMeta(state),

h(
'p',
{ style: { color: 'gray' } },
timestamp
? `Last Update: ${new Date(timestamp).toLocaleString()}`
: 'Waiting for data…'
),

error && h('p', { style: { color: 'red' } }, error)
]),
node: document.getElementById('app')
})

0 comments on commit 7a3037e

Please sign in to comment.