Site updated: 2022-11-07 17:29:09

This commit is contained in:
llbzow
2022-11-07 17:29:09 +00:00
parent 393ae22047
commit 267e5f619e
40 changed files with 1891 additions and 20 deletions

116
live2d-widget/README.html Normal file
View File

@@ -0,0 +1,116 @@
<h1 id="Live2D-Widget"><a href="#Live2D-Widget" class="headerlink" title="Live2D Widget"></a>Live2D Widget</h1><p><img src="https://forthebadge.com/images/badges/built-with-love.svg"><br><img src="https://forthebadge.com/images/badges/uses-html.svg"><br><img src="https://forthebadge.com/images/badges/made-with-javascript.svg"><br><img src="https://forthebadge.com/images/badges/contains-cat-gifs.svg"><br><img src="https://forthebadge.com/images/badges/powered-by-electricity.svg"><br><img src="https://forthebadge.com/images/badges/makes-people-smile.svg"></p>
<h2 id="特性-Feature"><a href="#特性-Feature" class="headerlink" title="特性 Feature"></a>特性 Feature</h2><p>在网页中添加 Live2D 看板娘。兼容 PJAX支持无刷新加载。<br>Add Live2D widget to web page. Compatible with PJAX.</p>
<p><img src="assets/screenshot-2.png" width="280"><img src="assets/screenshot-3.png" width="280"><img src="assets/screenshot-1.png" width="270"></p>
<p>(注:以上人物模型仅供展示之用,本仓库并不包含任何模型。)</p>
<p>你也可以查看示例网页:</p>
<ul>
<li><a href="https://zhangshuqiao.org/">米米的博客</a> 的左下角可查看效果</li>
<li><a href="https://mi.js.org/live2d-widget/demo/demo.html">demo.html</a>,展现基础功能</li>
<li><a href="https://mi.js.org/live2d-widget/demo/login.html">login.html</a>,仿 NPM 的登陆界面</li>
</ul>
<h2 id="使用-Usage"><a href="#使用-Usage" class="headerlink" title="使用 Usage"></a>使用 Usage</h2><p>如果你是小白,或者只需要最基础的功能,那么只用将这一行代码加入 html 页面的 <code>head</code><code>body</code> 中,即可加载看板娘:</p>
<pre><code class="xml">&lt;script src=&quot;https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js&quot;&gt;&lt;/script&gt;
</code></pre>
<p>添加代码的位置取决于你的网站的构建方式。例如,如果你使用的是 <a href="https://hexo.io/">Hexo</a>,那么需要在主题的模版文件中添加以上代码。对于用各种模版引擎生成的页面,修改方法类似。<br>如果网站启用了 PJAX由于看板娘不必每页刷新需要注意将该脚本放到 PJAX 刷新区域之外。</p>
<p><strong>但是!我们强烈推荐自己进行配置,让看板娘更加适合你的网站!</strong><br>如果你有兴趣自己折腾的话,请看下面的详细说明。</p>
<h2 id="配置-Configuration"><a href="#配置-Configuration" class="headerlink" title="配置 Configuration"></a>配置 Configuration</h2><p>你可以对照 <code>autoload.js</code> 的源码查看可选的配置项目。<code>autoload.js</code> 会自动加载三个文件:<code>waifu.css</code><code>live2d.min.js</code><code>waifu-tips.js</code><code>waifu-tips.js</code> 会创建 <code>initWidget</code> 函数,这就是加载看板娘的主函数。<code>initWidget</code> 函数接收一个 Object 类型的参数,作为看板娘的配置。以下是配置选项:</p>
<table>
<thead>
<tr>
<th>选项</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><code>waifuPath</code></td>
<td><code>string</code></td>
<td><code>https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/waifu-tips.json</code></td>
<td>看板娘资源路径,可自行修改</td>
</tr>
<tr>
<td><code>apiPath</code></td>
<td><code>string</code></td>
<td><code>https://live2d.fghrsh.net/api/</code></td>
<td>API 路径,可选参数</td>
</tr>
<tr>
<td><code>cdnPath</code></td>
<td><code>string</code></td>
<td><code>https://fastly.jsdelivr.net/gh/fghrsh/live2d_api/</code></td>
<td>CDN 路径,可选参数</td>
</tr>
<tr>
<td><code>tools</code></td>
<td><code>string[]</code></td>
<td><code>autoload.js</code></td>
<td>加载的小工具按钮,可选参数</td>
</tr>
</tbody></table>
<p>其中,<code>apiPath</code><code>cdnPath</code> 两个参数设置其中一项即可。<code>apiPath</code> 是后端 API 的 URL可以自行搭建并增加模型需要修改的内容比较多此处不再赘述可以参考 <a href="https://github.com/fghrsh/live2d_api">live2d_api</a>。而 <code>cdnPath</code> 则是通过 jsDelivr 这样的 CDN 服务加载资源,更加稳定。</p>
<h2 id="自定义-Customization"><a href="#自定义-Customization" class="headerlink" title="自定义 Customization"></a>自定义 Customization</h2><p>如果以上「配置」部分提供的选项还不足以满足你的需求,那么你可以自己进行修改。本仓库的目录结构如下:</p>
<ul>
<li><code>src/waifu-tips.js</code> 包含了按钮和对话框的逻辑;</li>
<li><code>waifu-tips.js</code> 是由 <code>src/waifu-tips.js</code> 自动打包生成的,不建议直接修改;</li>
<li><code>waifu-tips.json</code> 中定义了触发条件(<code>selector</code>CSS 选择器)和触发时显示的文字(<code>text</code></li>
<li><code>waifu.css</code> 是看板娘的样式表。</li>
</ul>
<p><code>waifu-tips.json</code> 中默认的 CSS 选择器规则是对 Hexo 的 <a href="http://github.com/next-theme/hexo-theme-next">NexT 主题</a> 有效的,为了适用于你自己的网页,可能需要自行修改,或增加新内容。<br><strong>警告:<code>waifu-tips.json</code> 中的内容可能不适合所有年龄段,或不宜在工作期间访问。在使用时,请自行确保它们是合适的。</strong></p>
<p>要在本地部署本项目的开发测试环境,你需要安装 Node.js 和 npm然后执行以下命令</p>
<pre><code class="bash">git clone https://github.com/stevenjoezhang/live2d-widget.git
npm install
npm run build
</code></pre>
<p>如果有任何疑问,欢迎提 Issue。如果有任何修改建议欢迎提 Pull Request。</p>
<h2 id="部署-Deploy"><a href="#部署-Deploy" class="headerlink" title="部署 Deploy"></a>部署 Deploy</h2><p>在本地完成了修改后,你可以将修改后的项目部署在服务器上,或者通过 CDN 加载,以便在网页中使用。</p>
<h3 id="Using-CDN"><a href="#Using-CDN" class="headerlink" title="Using CDN"></a>Using CDN</h3><p>要自定义有关内容,可以把这个仓库 Fork 一份,然后把修改后的内容通过 git push 到你的仓库中。这时,使用方法对应地变为</p>
<pre><code class="xml">&lt;script src=&quot;https://fastly.jsdelivr.net/gh/username/live2d-widget@latest/autoload.js&quot;&gt;&lt;/script&gt;
</code></pre>
<p>将此处的 <code>username</code> 替换为你的 GitHub 用户名。为了使 CDN 的内容正常刷新,需要创建新的 git tag 并推送至 GitHub 仓库中,否则此处的 <code>@latest</code> 仍然指向更新前的文件。此外 CDN 本身存在缓存,因此改动可能需要一定的时间生效。相关文档:</p>
<ul>
<li><a href="https://git-scm.com/book/en/v2/Git-Basics-Tagging">Git Basics - Tagging</a></li>
<li><a href="https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository">Managing releases in a repository</a></li>
</ul>
<h3 id="Self-host"><a href="#Self-host" class="headerlink" title="Self-host"></a>Self-host</h3><p>你也可以直接把这些文件放到服务器上,而不是通过 CDN 加载。</p>
<ul>
<li>如果你能够通过 <code>ssh</code> 连接你的主机,请把 Fork 并修改后的代码仓库克隆到服务器上。</li>
<li>如果你的主机无法用 <code>ssh</code> 连接(例如一般的虚拟主机),请在本地修改好代码后,通过 <code>ftp</code> 等方式将文件上传到主机的网站的目录下。</li>
<li>如果你是通过 Hexo 等工具部署的静态博客,请把本项目的代码放在博客源文件目录下(例如 <code>source</code> 目录)。重新部署博客时,相关文件就会自动上传到对应的路径下。为了避免这些文件被 Hexo 插件错误地修改,可能需要设置 <code>skip_render</code></li>
</ul>
<p>这样,整个项目就可以通过你的域名访问了。不妨试试能否正常地通过浏览器打开 <code>autoload.js</code><code>live2d.min.js</code> 等文件,并确认这些文件的内容是完整和正确的。<br>一切正常的话,接下来修改 <code>autoload.js</code> 中的常量 <code>live2d_path</code><code>live2d-widget</code> 这一目录的 URL 即可。比如说,如果你能够通过</p>
<pre><code>https://example.com/path/to/live2d-widget/live2d.min.js
</code></pre>
<p>访问到 <code>live2d.min.js</code>,那么就把 <code>live2d_path</code> 的值修改为</p>
<pre><code>https://example.com/path/to/live2d-widget/
</code></pre>
<p>路径末尾的 <code>/</code> 一定要加上。<br>完成后,在你要添加看板娘的界面加入</p>
<pre><code class="xml">&lt;script src=&quot;https://example.com/path/to/live2d-widget/autoload.js&quot;&gt;&lt;/script&gt;
</code></pre>
<p>就可以加载了。</p>
<h2 id="鸣谢-Thanks"><a href="#鸣谢-Thanks" class="headerlink" title="鸣谢 Thanks"></a>鸣谢 Thanks</h2><p><a href="https://www.browserstack.com/"><img height="80" src="https://live.browserstack.com/images/opensource/browserstack-logo.svg" alt="BrowserStack Logo"></a></p>
<blockquote>
<p>感谢 BrowserStack 容许我们在真实的浏览器中测试此项目。<br>Thanks to <a href="https://www.browserstack.com/">BrowserStack</a> for providing the infrastructure that allows us to test in real browsers!</p>
</blockquote>
<p><a href="https://www.jsdelivr.com"><img height="80" src="https://raw.githubusercontent.com/jsdelivr/jsdelivr-media/master/default/svg/jsdelivr-logo-horizontal.svg"></a></p>
<blockquote>
<p>感谢 jsDelivr 提供的 CDN 服务。<br>Thanks jsDelivr for providing public CDN service.</p>
</blockquote>
<p>代码自这篇博文魔改而来:<br><a href="https://www.fghrsh.net/post/123.html">https://www.fghrsh.net/post/123.html</a></p>
<p>感谢 <a href="https://hitokoto.cn/">一言</a> 提供的语句接口。</p>
<p>点击看板娘的纸飞机按钮时,会出现一个彩蛋,这来自于 <a href="http://www.websiteasteroids.com/">WebsiteAsteroids</a></p>
<h2 id="更多-More"><a href="#更多-More" class="headerlink" title="更多 More"></a>更多 More</h2><p>更多内容可以参考:<br><a href="https://nocilol.me/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02">https://nocilol.me/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02</a><br><a href="https://github.com/xiazeyu/live2d-widget.js">https://github.com/xiazeyu/live2d-widget.js</a><br><a href="https://github.com/summerscar/live2dDemo">https://github.com/summerscar/live2dDemo</a></p>
<p>关于后端 API 模型:<br><a href="https://github.com/xiazeyu/live2d-widget-models">https://github.com/xiazeyu/live2d-widget-models</a><br><a href="https://github.com/xiaoski/live2d_models_collection">https://github.com/xiaoski/live2d_models_collection</a></p>
<p>除此之外,还有桌面版本:<br><a href="https://github.com/amorist/platelet">https://github.com/amorist/platelet</a><br><a href="https://github.com/akiroz/Live2D-Widget">https://github.com/akiroz/Live2D-Widget</a><br><a href="https://github.com/zenghongtu/PPet">https://github.com/zenghongtu/PPet</a><br><a href="https://github.com/LikeNeko/L2dPetForMac">https://github.com/LikeNeko/L2dPetForMac</a></p>
<p>以及 Wallpaper Engine<br><a href="https://github.com/guansss/nep-live2d">https://github.com/guansss/nep-live2d</a></p>
<h2 id="许可证-License"><a href="#许可证-License" class="headerlink" title="许可证 License"></a>许可证 License</h2><p>Released under the GNU General Public License v3<br><a href="http://www.gnu.org/licenses/gpl-3.0.html">http://www.gnu.org/licenses/gpl-3.0.html</a></p>
<p>本仓库并不包含任何模型,用作展示的所有 Live2D 模型、图片、动作数据等版权均属于其原作者,仅供研究学习,不得用于商业用途。</p>
<p>Live2D 官方网站:<br><a href="https://www.live2d.com/en/">https://www.live2d.com/en/</a><br><a href="https://live2d.github.io/">https://live2d.github.io</a></p>
<p>Live2D Cubism Core は Live2D Proprietary Software License で提供しています。<br><a href="https://www.live2d.com/eula/live2d-proprietary-software-license-agreement_en.html">https://www.live2d.com/eula/live2d-proprietary-software-license-agreement_en.html</a><br>Live2D Cubism Components は Live2D Open Software License で提供しています。<br><a href="http://www.live2d.com/eula/live2d-open-software-license-agreement_en.html">http://www.live2d.com/eula/live2d-open-software-license-agreement_en.html</a></p>
<blockquote>
<p>The terms and conditions do prohibit modification, but obfuscating in <code>live2d.min.js</code> would not be considered illegal modification.</p>
</blockquote>
<p><a href="https://community.live2d.com/discussion/140/webgl-developer-licence-and-javascript-question">https://community.live2d.com/discussion/140/webgl-developer-licence-and-javascript-question</a></p>
<h2 id="更新-Update"><a href="#更新-Update" class="headerlink" title="更新 Update"></a>更新 Update</h2><p>2018年10月31日由 fghrsh 提供的原 API 停用,请更新至新地址。参考文章:<br><a href="https://www.fghrsh.net/post/170.html">https://www.fghrsh.net/post/170.html</a></p>
<p>2020年1月1日起本项目不再依赖于 jQuery。</p>
<p>2022年11月1日起本项目不再需要用户单独加载 Font Awesome。</p>