Ringeal007 发表于 2023-4-26 14:11:32

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

本帖最后由 Ringeal007 于 2024-1-1 05:25 编辑

我创作了一个简单的油猴脚本。其中部分代码由ChatGPT生成或修改。

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

static/image/hrline/line4.png

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

油猴脚本文件下载:
下载链接1:

下载链接2:
98850 - huang1111网盘

static/image/hrline/line4.png

代码片段:
// ==UserScript==
// @name         Ringeal007's Minecraft BDS Download Button
// @namespace    ringeal007
// @version      alpha-0.1.0
// @description对中文Minecraft Wiki镜像站的基岩版专用服务器页面中的表格作出修改。每个版本对应的行的最右侧都增加一个单元格,包含两个下载按钮,第一个默认采用第一接口,第二个默认采用第二接口。如果该版本为测试版或未发布Linux版,则将按钮设置为不可点击。按钮名称分别为“下载(Windows)”和“下载(Ubuntu(Linux))”。
// @author       Ringeal007
// @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*
// @grant      none
// ==/UserScript==

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

(function() {
    'use strict';

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

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

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

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

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

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

      // 获取版本号
      const version = row.cells.innerText;

      // 给该单元格添加两个下载按钮
      const downloadBtnWin = document.createElement("a");
      downloadBtnWin.textContent = "下载(Windows)";
      downloadBtnWin.href = apiUrls.replace("%version%", version);
      downloadBtnWin.style.marginRight = "10px";
      if (isLinuxUnavailable) {
            downloadBtnWin.style.color = "gray";
            downloadBtnWin.style.pointerEvents = "none";
      }
      cell.appendChild(downloadBtnWin);

      const downloadBtnLinux = document.createElement("a");
      downloadBtnLinux.textContent = "下载(Ubuntu(Linux))";
      downloadBtnLinux.href = apiUrls.replace("%version%", version);
      if (isLinuxUnavailable) {
            downloadBtnLinux.style.color = "gray";
            downloadBtnLinux.style.pointerEvents = "none";
      }
      cell.appendChild(downloadBtnLinux);

      // 设置该单元格的样式
      cell.style.whiteSpace = "nowrap";
      cell.style.textAlign = "right";
      cell.style.verticalAlign = "middle";
    }
})();






Ringeal007 发表于 2024-1-1 05:26:12

此油猴脚本应当作废,因为我的世界有了新的维基网站,并且新的维基网站添加了快捷下载按钮。

microsoft.com 发表于 2023-5-1 14:09:54

这插件有什么用?

Social 发表于 2023-4-29 17:19:46

我来围观一下
页: [1]
查看完整版本: 油猴脚本展示——Ringeal007的《我的世界》基岩版专用服务器下载按钮