Update metadata

This commit is contained in:
the1812 2021-10-26 13:42:56 +08:00
parent 86f96caae8
commit 78ea139b72
4 changed files with 209 additions and 49 deletions

104
dist/bilibili-evolved.preview.user.js vendored Normal file

File diff suppressed because one or more lines are too long

104
dist/bilibili-evolved.user.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{
"name": "Bilibili Evolved (v2)",
"name": "Bilibili Evolved",
"description": "强大的哔哩哔哩增强脚本",
"updateURL": "https://cdn.jsdelivr.net/gh/the1812/Bilibili-Evolved@master/dist/bilibili-evolved.user.js",
"downloadURL": "https://cdn.jsdelivr.net/gh/the1812/Bilibili-Evolved@master/dist/bilibili-evolved.user.js"

View File

@ -1,48 +0,0 @@
import { meta, defaultBranch } from './meta'
import { monkey } from './ajax'
import { Version } from './version'
import { settings } from './settings'
import { fullyLoaded } from './life-cycle'
const checkVersionUpdate = (update: PackageUpdate) => {
const version = new Version(update.meta.version)
const current = new Version(meta.version)
if (version.greaterThan(current)) {
console.log(`New version available: v${update.meta.version}`)
// TODO: notify new version
return true
}
return false
}
const installPackageUpdate = (packageCodes: string) => {
settings.update = packageCodes
}
export const checkUpdate = (() => {
const update = async () => {
console.log('Checking for update...')
const { getGeneralSettings } = await import('./settings')
const { cdnRoots } = await import('./cdn-types')
const { cdnRoot } = getGeneralSettings()
const updateUrl = `${cdnRoots[cdnRoot]}dist/package.js`
const packageCodes = await monkey({
url: updateUrl,
})
eval(packageCodes)
const updatePackage = window.bilibiliEvolvedUpdate
if (checkVersionUpdate(updatePackage)) { // 检查版本, 有新版本时不再进行组件更新
return
}
if (meta.branch === defaultBranch) { // 主分支需要安装组件更新
installPackageUpdate(packageCodes)
console.log('Installed package update.')
}
}
return () => {
// Violentmonkey 不兼容 requestIdleCallback
if ('requestIdleCallback' in unsafeWindow && GM_info.scriptHandler !== 'Violentmonkey') {
unsafeWindow.requestIdleCallback(update)
} else {
fullyLoaded(update)
}
}
})()