live2d-widget/README.md

190 lines
10 KiB
Markdown
Raw Normal View History

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