更新检测脚本; 分数增加因子系数

master
yutent 2023-07-18 19:38:18 +08:00
parent 0e5a2e7f4c
commit 416c9aed37
5 changed files with 68 additions and 19 deletions

View File

@ -2,15 +2,17 @@
<Topbar /> <Topbar />
<Banner /> <Banner />
<Modules /> <Modules />
<Copyright />
</template> </template>
<script> <script>
import Topbar from './components/topbar.vue' import Topbar from './components/topbar.vue'
import Banner from './components/banner.vue' import Banner from './components/banner.vue'
import Copyright from './components/footer.vue'
import Modules from './views/main.vue' import Modules from './views/main.vue'
export default { export default {
components: { Topbar, Banner, Modules } components: { Topbar, Banner, Modules, Copyright }
} }
</script> </script>

View File

@ -18,8 +18,7 @@
</section> </section>
<section class="scores"> <section class="scores">
你当前浏览器的得分为 <span class="num">{{ $store.scores }}</span 你当前浏览器的得分为 <span class="num">{{ $store.scores }}</span>
>/<span class="num total">{{ $store.total }}</span>
</section> </section>
</div> </div>

12
src/components/footer.vue Normal file
View File

@ -0,0 +1,12 @@
<template>
<footer class="copyright">&copy; Powered by yutent. 2023</footer>
</template>
<style lang="scss" scoped>
.copyright {
display: flex;
justify-content: center;
margin-top: 32px;
padding: 16px 0;
}
</style>

27
src/lib/checks.js Normal file
View File

@ -0,0 +1,27 @@
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/07/18 19:11:01
*/
// 用canvas检测图形/图象的支持
export function checkCanvas(type) {
try {
var canvas = document.createElement('canvas')
var ctx = canvas.getContext(type)
return ctx ? 1 : 0
} catch (err) {
console.log(err)
return 0
}
}
export function checkMedia(type, isAudio = true) {
let ctx = isAudio ? new Audio() : document.createElement('video')
let res = ctx.canPlayType(type)
console.log(isAudio, res)
if (res === 'maybe' || res === 'probably') {
return 1
}
return 0
}

View File

@ -1,20 +1,9 @@
import { reactive } from 'vue' import { reactive } from 'vue'
import * as env from '@/lib/env.js' import * as env from '@/lib/env.js'
import { checkCanvas, checkMedia } from '@/lib/checks.js'
function checkCanvas(type) {
try {
var canvas = document.createElement('canvas')
var ctx = canvas.getContext(type)
return ctx ? 1 : 0
} catch (err) {
console.log(err)
return 0
}
}
const store = reactive({ const store = reactive({
total: 100,
scores: 80, scores: 80,
useragent: navigator.userAgent, useragent: navigator.userAgent,
env, env,
@ -23,7 +12,16 @@ const store = reactive({
{ {
name: '音频支持', name: '音频支持',
total: 0, total: 0,
scores: [!!window.AudioContext ^ 0, 1, 1, 1, 1, 1, 1], factor: 80,
scores: [
!!window.AudioContext ^ 0,
checkMedia('audio/wav'),
checkMedia('audio/mpeg'),
checkMedia('audio/flac'),
checkMedia('audio/aac'),
checkMedia('audio/ogg'),
checkMedia('audio/webm')
],
items: [ items: [
'Web Audio API', 'Web Audio API',
'pcm audio support', 'pcm audio support',
@ -39,7 +37,15 @@ const store = reactive({
{ {
name: '视频支持', name: '视频支持',
total: 0, total: 0,
scores: [0, 1, 1, 1, 1, 1], factor: 80,
scores: [
checkMedia('video/mp4; codecs="mp4v.20.8"', 0),
checkMedia('video/mp4', 0),
checkMedia('video/mp4; codecs="hev1"', 0),
checkMedia('video/ogg', 0),
checkMedia('video/webm; codecs="vp8"', 0),
checkMedia('video/webm; codecs="vp9"', 0)
],
items: [ items: [
'MPEG-4 ASP support', 'MPEG-4 ASP support',
'H.264 support', 'H.264 support',
@ -53,6 +59,7 @@ const store = reactive({
name: '流媒体', name: '流媒体',
total: 0, total: 0,
scores: [1, 1, 0, 0], scores: [1, 1, 0, 0],
factor: 100,
items: [ items: [
'Media Source extensions', 'Media Source extensions',
'DRM support', 'DRM support',
@ -63,6 +70,7 @@ const store = reactive({
{ {
name: '自定义组件', name: '自定义组件',
total: 0, total: 0,
factor: 80,
scores: [ scores: [
!!window.customElements ^ 0, !!window.customElements ^ 0,
!!document.body.attachShadow ^ 0, !!document.body.attachShadow ^ 0,
@ -73,6 +81,7 @@ const store = reactive({
{ {
name: '图形图象支持', name: '图形图象支持',
total: 0, total: 0,
factor: 120,
scores: [ scores: [
checkCanvas('2d'), checkCanvas('2d'),
checkCanvas('webgl'), checkCanvas('webgl'),
@ -85,6 +94,7 @@ const store = reactive({
{ {
name: '网络', name: '网络',
total: 0, total: 0,
factor: 60,
scores: [ scores: [
!!window.EventSource ^ 0, !!window.EventSource ^ 0,
!!window.WebSocket ^ 0, !!window.WebSocket ^ 0,
@ -102,8 +112,7 @@ const store = reactive({
}) })
store.modules.forEach(it => (it.total = it.items.length)) store.modules.forEach(it => (it.total = it.items.length))
store.scores = store.modules.map(it => it.scores.sum()).sum() store.scores = store.modules.map(it => it.scores.sum() * it.factor).sum()
store.total = store.modules.map(it => it.total).sum()
export default function (app) { export default function (app) {
app.config.globalProperties.$store = store app.config.globalProperties.$store = store