From c0f0990ff037f377f17dd0206192caed658705b2 Mon Sep 17 00:00:00 2001 From: Spirit Date: Fri, 6 Mar 2020 00:08:36 +0800 Subject: [PATCH] perf: optmize --- inc/api.php | 2 +- js/sakura-app.js | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/inc/api.php b/inc/api.php index a640a08..11e5ee9 100644 --- a/inc/api.php +++ b/inc/api.php @@ -402,7 +402,7 @@ function get_qq_avatar(){ $encrypted=$_GET["qq"]; if(isset($encrypted)){ $iv = str_repeat($sakura_privkey, 2); - $encrypted = urldecode(base64_decode($encrypted)); + $encrypted = base64_decode(urldecode($encrypted)); $qq_number = openssl_decrypt($encrypted, 'aes-128-cbc', $sakura_privkey, 0, $iv); preg_match('/^\d{3,}$/', $qq_number, $matches); $imgurl='https://q2.qlogo.cn/headimg_dl?dst_uin='.$matches[0].'&spec=100'; diff --git a/js/sakura-app.js b/js/sakura-app.js index b581098..97697e1 100644 --- a/js/sakura-app.js +++ b/js/sakura-app.js @@ -5,6 +5,7 @@ * @date 2019.8.3 */ mashiro_global.variables = new function () { + this.has_hls = false; this.skinSecter = true; } mashiro_global.ini = new function () { @@ -523,25 +524,34 @@ function killCoverVideo() { } } +function loadHls(){ + var video = addComment.I('coverVideo'); + var video_src = $('#coverVideo').attr('data-src'); + if (Hls.isSupported()) { + var hls = new Hls(); + hls.loadSource(video_src); + hls.attachMedia(video); + hls.on(Hls.Events.MANIFEST_PARSED, function () { + video.play(); + }); + } else if (video.canPlayType('application/vnd.apple.mpegurl')) { + video.src = video_src; + video.addEventListener('loadedmetadata', function () { + video.play(); + }); + } +} + function coverVideoIni() { if ($('video').hasClass('hls')) { - $.getScript("https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.3/cdn/js/src/16.hls.js", function(){ - var video = addComment.I('coverVideo'); - var video_src = $('#coverVideo').attr('data-src'); - if (Hls.isSupported()) { - var hls = new Hls(); - hls.loadSource(video_src); - hls.attachMedia(video); - hls.on(Hls.Events.MANIFEST_PARSED, function () { - video.play(); - }); - } else if (video.canPlayType('application/vnd.apple.mpegurl')) { - video.src = video_src; - video.addEventListener('loadedmetadata', function () { - video.play(); - }); - } - }); + if (mashiro_global.variables.has_hls){ + loadHls(); + }else{ + $.getScript("https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.3/cdn/js/src/16.hls.js", function(){ + loadHls(); + mashiro_global.variables.has_hls = true; + }); + } //console.info('ini:coverVideoIni()'); } }