diff --git a/.github/create_pat.png b/.github/create_pat.png new file mode 100644 index 0000000..1d1646d Binary files /dev/null and b/.github/create_pat.png differ diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..62edfe7 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,29 @@ +# File: .github/workflows/repo-sync.yml +name: 自动同步 +on: + schedule: + - cron: '0 20 * * *' + workflow_dispatch: + watch: + types: started + repository_dispatch: + types: repo-sync +jobs: + repo-sync: + env: + PAT: ${{ github.event.client_payload.PAT || secrets.PAT }} #此处PAT需要申请,教程详见:https://www.jianshu.com/p/bb82b3ad1d11 + runs-on: ubuntu-latest + if: github.event.repository.owner.id == github.event.sender.id + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: 开始自动同步 + uses: repo-sync/github-sync@v2 + if: env.PAT + with: + source_repo: "https://github.com/shanmite/LotteryAutoScript.git" + source_branch: "main" + destination_branch: "main" + github_token: ${{ github.event.client_payload.PAT || secrets.PAT }} \ No newline at end of file diff --git a/README.md b/README.md index e6c19c1..445ab51 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ # AutoScript -![Automatic sweepstakes](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20sweepstakes/badge.svg) -![Automatic clear dynamic&follow](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20clear%20dynamic&follow/badge.svg) + +![Automatic sweepstakes](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20sweepstakes/badge.svg) + + + +![Automatic clear dynamic&follow](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20clear%20dynamic&follow/badge.svg) + + -- [AutoScript](#autoscript) +* [AutoScript](#autoscript) - [动态抽奖](#动态抽奖) - [操作步骤](#操作步骤) - [Fork本仓库](#fork本仓库) @@ -24,6 +30,7 @@ --- ## 动态抽奖 + 通过Github Actions挂载Nodejs脚本 > [Actions官方文档](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions) @@ -37,57 +44,98 @@ ↓↓ ### Fork本仓库 -![fork](.github/fork.png) + +![fork](.github/fork.png) + + ↓↓ ### 填入COOKIE + 进入[B站主页](https://www.bilibili.com/)获取Cookie用于登录 Chrome浏览器: + 1. `F12`打开控制台 2. 进入Application找到Cookies栏中的SESSDATA将HttpOnly选项**取消**勾选 + (此步骤是为了方便后续采用JS获取Cookies) - ![取消httponly](.github/getCookies.png) + + + +![取消httponly](.github/getCookies.png) + + + 3. 在Console中复制以下代码回车 - ```js + + + +``` js { let bilicookie = ''; - document.cookie.split(/\s*;\s*/).forEach(item=>{ + document.cookie.split(/\s*;\s*/).forEach(item => { const _item = item.split('='); - if (['DedeUserID','bili_jct','SESSDATA'].indexOf(_item[0]) !== -1) + if (['DedeUserID', 'bili_jct', 'SESSDATA'].indexOf(_item[0]) !== -1) bilicookie += `${_item[0]}=${_item[1]}; `; }) copy(bilicookie); /* 自动复制到粘贴板 */ console.log(bilicookie) } - ``` +``` + 4. 新建一个COOKIE将获取到的`DedeUserID=***;SESSDATA=***;bili_jct=***`填入 - ![new secret](.github/cookie2.png) - ![new COOKIE](.github/new_secret.png) + + + +![new secret](.github/cookie2.png) + + + + + +![new COOKIE](.github/new_secret.png) + + 也可以采用**其他方式获取**所需的Cookie -只需含有`DedeUserID=...;SESSDATA=...;bili_jct=...`三项即可 +只需含有 `DedeUserID=...;SESSDATA=...;bili_jct=...` 三项即可 (分号分割,顺序随意) ↓↓ ### 微信推送中奖信息(可选) + 如果想使用Server酱提供的**微信推送**服务 + > [Server酱是什么?](http://sc.ftqq.com/3.version) -可在`Repository secrets`中新建一个`SCKEY`并填入相应的值 -![new secret SCKEY](.github/secret2.png) +可在 `Repository secrets` 中新建一个 `SCKEY` 并填入相应的值 + +![new secret SCKEY](.github/secret2.png) + + ↓↓ ### 运行 + 进入Actions启用工作流 -随便改一下此`README.md`文件并提交(Push触发) -![change](.github/start1.png) -![commit](.github/start2.png) +随便改一下此 `README.md` 文件并提交(Push触发) + +![change](.github/start1.png) + + + +![commit](.github/start2.png) + + **或者**通过手动触发 -![commit](.github/byhand.png) + +![commit](.github/byhand.png) + + ***以上步骤是为了检测是否配置成功*** @@ -96,52 +144,85 @@ Chrome浏览器: ↓↓ ### 完成! + 效果 -![效果](.github/success.png) + +![效果](.github/success.png) + + --- ## 清理动态 -只需在`Secret`里添加一个`CLEAR`项并取值为`true` + +只需在 `Secret` 里添加一个 `CLEAR` 项并取值为 `true` + 程序便会每15天清理一次动态和关注 --- - ## 其他细节 + ### 更新 + 如果出现 -![滞后](.github/behind.png) + +![滞后](.github/behind.png) + + 说明此脚本有更新 -通过`Pull Request`更新仓库 -![如何同步更新Github上Fork的项目](.github/update_fork.png) +通过 `Pull Request` 更新仓库 + +![如何同步更新Github上Fork的项目](.github/update_fork.png) + + 或者 使用[GitHub App Pull](https://github.com/apps/pull)自动同步 +### 自动更新(个人推荐) + +1. 点我创建 [`授权令牌`](https://github.com/settings/tokens/new) + +2. 如图,勾选前两项即可: + +![如图,勾选前两项即可:](.github/create_pat.png) + +3. 将 令牌 复制(注意,先复制,一旦关闭网页就不能查看了),再新建`Secrets`,键名 填入 `PAT` + +4. 我默认设置更新时间:每天晚上8点与主仓库自动同步一次! + ### 多账号支持 + 默认支持5个账号 - | cookies | value | - | --------- | ----- | - | `COOKIE` | 值 | - | `COOKIE2` | 值 | - | `COOKIE3` | 值 | - | `COOKIE4` | 值 | - | `COOKIE5` | 值 | - | `COOKIE*` | 值 | + +| cookies | value | +|-----------|-------| +| `COOKIE` | 值 | +| `COOKIE2` | 值 | +| `COOKIE3` | 值 | +| `COOKIE4` | 值 | +| `COOKIE5` | 值 | +| `COOKIE*` | 值 | *添加更多的账号* -可在文件`.github/workflows/node.js.yml`中 +可在文件 `.github/workflows/node.js.yml` 中 ```yaml lottery_*: runs-on: ubuntu-latest steps: - - name: 'Checkout codes' + + + name: 'Checkout codes' + uses: actions/checkout@v2 - - name: 'Use Node.js' + + + name: 'Use Node.js' + uses: actions/setup-node@v1 with: node-version: '12.18.3' - - name: 'Run in Nodejs' + + + name: 'Run in Nodejs' + shell: bash env: NUMBER: * @@ -149,21 +230,28 @@ steps: SCKEY: ${{ secrets.SCKEY }} run: npm start + ``` 将以上星号处改为数字并依次复制粘贴 -此时`Secrets`里就可以添加更多的`COOKIE*`(简单的找规律问题) -若使用自动清理功能,还需再`.github/workflows/clear.yml`中 +此时 `Secrets` 里就可以添加更多的 `COOKIE*` (简单的找规律问题) +若使用自动清理功能, 还需再 `.github/workflows/clear.yml` 中 ```yaml lottery_*: runs-on: ubuntu-latest steps: + - name: 'Checkout codes' + uses: actions/checkout@v2 + - name: 'Use Node.js' + uses: actions/setup-node@v1 with: node-version: '12.18.3' + - name: 'Run in Nodejs' + shell: bash env: NUMBER: * @@ -172,22 +260,34 @@ lottery_*: SCKEY: ${{ secrets.SCKEY }} run: npm run clear + ``` 将以上星号处改为数字并依次复制粘贴以清理更多的账号 ### 如何关闭 -![关闭工作流](.github/close.png) + +![关闭工作流](.github/close.png) + + ### 部分设置说明 - - 定时运行(`UTC`时间) - `.github/workflows/node.js.yml` + + + 定时运行(`UTC`时间) + + `.github/workflows/node.js.yml` + ```yaml schedule: + - cron: '0 */2 * * *' + ``` [如何填写此字段](https://crontab.guru/) - - 模式选择 - `lib/config.js` + + + 模式选择 + + `lib/config.js` + - 字段解释 - `model` - `'00'`关闭自动抽奖 @@ -222,4 +322,3 @@ lottery_*: - 评论内容 --- -