perf: optimize code logic

Optimize code logic, fix a tiny bug
issue #209
This commit is contained in:
Spirit 2020-04-01 19:23:37 +08:00
parent 5c58c054c5
commit f265fe83c6

View File

@ -453,10 +453,15 @@ function get_bgm_items($page = 1){
} }
$lists = $bgm["list"]; $lists = $bgm["list"];
foreach ((array)$lists as $list) { foreach ((array)$lists as $list) {
if(preg_match('/已看完/m',$list["new_ep"]['index_show'], $matches_finish)){
$percent = 100;
}else{
preg_match('/第(\d+)话/m',$list['progress'], $matches_progress); preg_match('/第(\d+)话/m',$list['progress'], $matches_progress);
preg_match('/第(\d+)话/m',$list["new_ep"]['index_show'], $matches_new); preg_match('/第(\d+)话/m',$list["new_ep"]['index_show'], $matches_new);
$progress = is_numeric($matches_progress[1]) ? $matches_progress[1] : 0; $progress = is_numeric($matches_progress[1]) ? $matches_progress[1] : 0;
$total = is_numeric($matches_new[1]) ? $matches_new[1] : $list['total_count']; $total = is_numeric($matches_new[1]) ? $matches_new[1] : $list['total_count'];
$percent = $progress / $total * 100;
}
$html .= '<div class="column"> $html .= '<div class="column">
<a class="bangumi-item" href="https://bangumi.bilibili.com/anime/' . $list['season_id'] . '/" target="_blank" rel="nofollow"> <a class="bangumi-item" href="https://bangumi.bilibili.com/anime/' . $list['season_id'] . '/" target="_blank" rel="nofollow">
<img class="bangumi-image" src="' . str_replace('http://', 'https://', $list['cover']) . '"/> <img class="bangumi-image" src="' . str_replace('http://', 'https://', $list['cover']) . '"/>
@ -464,7 +469,7 @@ function get_bgm_items($page = 1){
<h3 class="bangumi-title" title="' . $list['title'] . '">' . $list['title'] . '</h2> <h3 class="bangumi-title" title="' . $list['title'] . '">' . $list['title'] . '</h2>
<div class="bangumi-summary"> '. $list['evaluate'] .' </div> <div class="bangumi-summary"> '. $list['evaluate'] .' </div>
<div class="bangumi-status"> <div class="bangumi-status">
<div class="bangumi-status-bar" style="width: '. $progress / $total * 100 .'%"></div> <div class="bangumi-status-bar" style="width: '. $percent .'%"></div>
<p>' . $list['new_ep']['index_show'] . '</p> <p>' . $list['new_ep']['index_show'] . '</p>
</div> </div>
</div> </div>