From 58e079989327e26fc7b7db27fb94fbc5dec436cd Mon Sep 17 00:00:00 2001 From: HCLonely Date: Sat, 4 Jul 2020 18:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=95=AA=E5=89=A7=E5=B0=81?= =?UTF-8?q?=E9=9D=A2=E6=A0=BC=E5=BC=8F=E9=85=8D=E7=BD=AE(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ lib/templates/bangumi.ejs | 3 +-- package.json | 2 +- src/index.js | 20 ++++++++++---------- src/lib/templates/webpSupport.js | 4 ---- 5 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 src/lib/templates/webpSupport.js diff --git a/README.md b/README.md index 9df9ba4..d1af055 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ bangumi: loading: metaColor: color: + webp: ``` - **enable**: 是否启用 @@ -42,6 +43,7 @@ bangumi: - **loading**: 图片加载完成前的loading图片 - **metaColor**: meta部分(简介上方)字体颜色 - **color**: 简介字体颜色 +- **webp**: 番剧封面使用`webp`格式(此格式在`safari`浏览器下不显示,但是图片大小可以缩小100倍左右), 默认`true` ## 使用 diff --git a/lib/templates/bangumi.ejs b/lib/templates/bangumi.ejs index 0a9855f..2bacfec 100644 --- a/lib/templates/bangumi.ejs +++ b/lib/templates/bangumi.ejs @@ -41,5 +41,4 @@ <% include index.js %> tabs[<%- show %>].click(); <% include pagination.js %> - <% include webpSupport.js %> - \ No newline at end of file + diff --git a/package.json b/package.json index c89b57a..de226b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-bilibili-bangumi", - "version": "1.3.2", + "version": "1.3.3", "description": "hexo bilibili番剧页", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 6ec11b5..10c2bec 100644 --- a/src/index.js +++ b/src/index.js @@ -40,7 +40,7 @@ hexo.extend.console.register('bangumi', 'Generate pages of bilibili bangumis for log.info("Please add vmid to _config.yml"); return; } - saveBangumiData(this.config.bangumi.vmid); + saveBangumiData(this.config.bangumi.vmid, this.config.bangumi.webp); } else { log.info("Unknown command, please use \"hexo bangumi -h\" to see the available commands") } @@ -58,7 +58,7 @@ async function getBangumiPage(vmid, status) { return { success: false, data: response }; } } -async function getBangumi(vmid, status, pn) { +async function getBangumi(vmid, status, webp, pn) { let response = await axios.get(`https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=${status}&vmid=${vmid}&ps=50&pn=${pn}`) let $data = []; if (response?.data?.code === 0) { @@ -69,7 +69,7 @@ async function getBangumi(vmid, status, pn) { if (cover){ let href = new URL(cover) href.protocol = 'https' - href.pathname += '@220w_280h.webp' + if(webp) href.pathname += '@220w_280h.webp' cover = href.href } $data.push({ @@ -96,12 +96,12 @@ function count(e) { function total(e) { return e ? (e === -1 ? `未完结` : `全${e}话`) : '-'; } -async function biliBangumi(vmid, status) { - let page = await getBangumiPage(vmid, status); +async function biliBangumi(vmid, status, webp) { + let page = await getBangumiPage(vmid, status, webp); if(page?.success){ let list = []; for (let i = 1; i < page.data; i++) { - let data = await getBangumi(vmid, status, i); + let data = await getBangumi(vmid, status, webp, i); list.push(...data); } return list; @@ -110,12 +110,12 @@ async function biliBangumi(vmid, status) { return []; } } -async function saveBangumiData(vmid) { +async function saveBangumiData(vmid, webp = true) { log.info("Getting bilibili bangumis, please wait..."); let startTime = new Date().getTime(); - let wantWatch = await biliBangumi(vmid, 1); - let watching = await biliBangumi(vmid, 2); - let watched = await biliBangumi(vmid, 3); + let wantWatch = await biliBangumi(vmid, 1, webp); + let watching = await biliBangumi(vmid, 2, webp); + let watched = await biliBangumi(vmid, 3, webp); let endTime = new Date().getTime(); log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded in ' + (endTime - startTime) + " ms"); let bangumis = { wantWatch, watching, watched }; diff --git a/src/lib/templates/webpSupport.js b/src/lib/templates/webpSupport.js deleted file mode 100644 index 23df949..0000000 --- a/src/lib/templates/webpSupport.js +++ /dev/null @@ -1,4 +0,0 @@ -(function(){var WebP=new Image();WebP.onload=WebP.onerror=function(){ -if(WebP.height!=2){var sc=document.createElement('script');sc.type='text/javascript';sc.async=true; -var s=document.getElementsByTagName('script')[0];sc.src='//cdn.jsdelivr.net/npm/webpjs@0.0.2/webpjs.min.js';s.parentNode.insertBefore(sc,s);}}; -WebP.src='data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';})(); \ No newline at end of file