开启辅助访问     
收藏本站

站内搜索

搜索

Minecraft(我的世界)苦力怕论坛

[展示] 油猴脚本展示——Ringeal007的《我的世界》基岩版专用服务器下载按钮

 发表于 2023-4-26 14:11:32|显示全部楼层|阅读模式 IP:河北省
本帖最后由 Ringeal007 于 2024-1-1 05:25 编辑
我创作了一个简单的油猴脚本。其中部分代码由ChatGPT生成或修改。

脚本对中文Minecraft Wiki镜像站的基岩版专用服务器页面中的表格作出修改。每个版本对应的行的最右侧都增加一个单元格,包含两个下载按钮,第一个默认采用第一接口,第二个默认采用第二接口。如果该版本为测试版或未发布Linux版,则将按钮设置为不可点击。按钮名称分别为“下载(Windows)”和“下载(Ubuntu(Linux))”。



脚本作用网页:
基岩版专用服务器 - Minecraft Wiki_BWIKI_哔哩哔哩 (biligame.com)

油猴脚本文件下载:
下载链接1:
 Ringeal007's Minecraft BDS Download Button.user.js(3.21 KB, 下载次数: 15)
下载链接2:
98850 - huang1111网盘



代码片段:
  1. // ==UserScript==
  2. // @name         Ringeal007's Minecraft BDS Download Button
  3. // @namespace    ringeal007
  4. // @version      alpha-0.1.0
  5. // @description  对中文Minecraft Wiki镜像站的基岩版专用服务器页面中的表格作出修改。每个版本对应的行的最右侧都增加一个单元格,包含两个下载按钮,第一个默认采用第一接口,第二个默认采用第二接口。如果该版本为测试版或未发布Linux版,则将按钮设置为不可点击。按钮名称分别为“下载(Windows)”和“下载(Ubuntu(Linux))”。
  6. // @author       Ringeal007
  7. // @match        *://wiki.biligame.com/mc/%E5%9F%BA%E5%B2%A9%E7%89%88%E4%B8%93%E7%94%A8%E6%9C%8D%E5%8A%A1%E5%99%A8*
  8. // @grant        none
  9. // ==/UserScript==

  10. //本脚本部分代码由ChatGPT生成

  11. (function() {
  12.     'use strict';

  13.     // 定义四个不同接口的下载链接
  14.     const apiUrls = [
  15.         "https://minecraft.azureedge.net/bin-win/bedrock-server-%version%.zip",
  16.         "https://minecraft.azureedge.net/bin-linux/bedrock-server-%version%.zip",
  17.         "https://minecraft.azureedge.net/bin-win-preview/bedrock-server-%version%.zip",
  18.         "https://minecraft.azureedge.net/bin-linux-preview/bedrock-server-%version%.zip"
  19.     ];

  20.     // 找到包含版本信息的表格,获取tbody元素
  21.     const tbody = document.evaluate('/html/body/div[2]/div[2]/div[4]/div[5]/div/table/tbody', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

  22.     // 遍历表格中的每个版本行
  23.     for (let i = 0; i < tbody.rows.length; i++) {
  24.         const row = tbody.rows[i];

  25.         // 在该版本行最后增加一个单元格
  26.         const cell = row.insertCell(-1);

  27.         // 如果该版本介绍中含有 "测试版服务器软件升级至",采用第三和第四接口
  28.         const isPreview = row.cells[1].innerText.includes("测试版服务器软件升级至");

  29.         // 如果该版本介绍中含有 "未发布Linux版",则将按钮变色并设置为不可点击
  30.         const isLinuxUnavailable = row.cells[1].innerText.includes("未发布Linux版");

  31.         // 获取版本号
  32.         const version = row.cells[0].innerText;

  33.         // 给该单元格添加两个下载按钮
  34.         const downloadBtnWin = document.createElement("a");
  35.         downloadBtnWin.textContent = "下载(Windows)";
  36.         downloadBtnWin.href = apiUrls[isPreview ? 2 : 0].replace("%version%", version);
  37.         downloadBtnWin.style.marginRight = "10px";
  38.         if (isLinuxUnavailable) {
  39.             downloadBtnWin.style.color = "gray";
  40.             downloadBtnWin.style.pointerEvents = "none";
  41.         }
  42.         cell.appendChild(downloadBtnWin);

  43.         const downloadBtnLinux = document.createElement("a");
  44.         downloadBtnLinux.textContent = "下载(Ubuntu(Linux))";
  45.         downloadBtnLinux.href = apiUrls[isPreview ? 3 : 1].replace("%version%", version);
  46.         if (isLinuxUnavailable) {
  47.             downloadBtnLinux.style.color = "gray";
  48.             downloadBtnLinux.style.pointerEvents = "none";
  49.         }
  50.         cell.appendChild(downloadBtnLinux);

  51.         // 设置该单元格的样式
  52.         cell.style.whiteSpace = "nowrap";
  53.         cell.style.textAlign = "right";
  54.         cell.style.verticalAlign = "middle";
  55.     }
  56. })();
复制代码






苦力怕论坛,感谢有您~
 楼主|  发表于 2024-1-1 05:26:12|显示全部楼层 IP:河北省
此油猴脚本应当作废,因为我的世界有了新的维基网站,并且新的维基网站添加了快捷下载按钮。
来自 4# 2024-1-1 05:26:12回复收起回复
苦力怕论坛,感谢有您~
回复支持

使用道具举报

 发表于 2023-5-1 14:09:54|显示全部楼层 IP:湖南省
这插件有什么用?
3#2023-5-1 14:09:54回复收起回复
苦力怕论坛,感谢有您~
 发表于 2023-4-29 17:19:46|显示全部楼层 IP:河南省
我来围观一下
2#2023-4-29 17:19:46回复收起回复
苦力怕论坛,感谢有您~

本版积分规则

本站
关于我们
联系我们
坛史纲要
官方
哔哩哔哩
技术博客
下载
网易版
安卓版
JAVA
反馈
意见建议
教程中心
更多
捐助本站
QQ群
QQ群

QQ群

访问手机版

访问手机版

手机版|小黑屋|系统状态|klpbbs.com

粤公网安备 44200002445329号 | 由 木韩网络 提供云服务 | GMT+8, 2024-9-1 13:08

声明:本站与Mojang以及微软公司没有从属关系

Powered by Discuz! X3.4 粤ICP备2023071842号