Fix update url (fix #3122)

This commit is contained in:
the1812 2022-03-14 23:33:15 +08:00
parent 0b45a3862c
commit 2ef5779b41
2 changed files with 6 additions and 3 deletions

View File

@ -1,3 +1,4 @@
import { cdnRoots } from '@/core/cdn-types'
import { ComponentMetadata, componentsTags } from '../types'
export const component: ComponentMetadata = {
@ -24,15 +25,17 @@ export const component: ComponentMetadata = {
const { monkey } = await import('@/core/ajax')
const { meta } = await import('@/core/meta')
const { Toast } = await import('@/core/toast')
const { getGeneralSettings } = await import('@/core/settings')
const now = Number(new Date())
const duration = now - options.lastUpdateCheck
if (duration < options.minimumDuration) { // 未到间隔期
return
}
const updateUrl = GM_info.scriptUpdateURL
if (!updateUrl) { // 本地调试版没有 updateUrl
// 本地调试版不检查
if (!GM_info.scriptUpdateURL) {
return
}
const updateUrl = `${cdnRoots[getGeneralSettings().cdnRoot](meta.compilationInfo.branch)}dist/${meta.originalFilename}`
const scriptText: string = await monkey({ url: updateUrl, responseType: 'text' })
options.lastUpdateCheck = Number(new Date())
const versionMatch = scriptText.match(/^\/\/ @version\s*([\d\.]+)$/m)

View File

@ -24,7 +24,7 @@ export const meta = {
if (branch === branches.stable) {
return 'bilibili-evolved.user.js'
}
return `bilibili-evolved.${branch}.user.js`
return `bilibili-evolved.${branches.preview}.user.js`
},
/** 检查更新的链接 */
get updateURL(): string {