// ==UserScript== // @name 百度网盘不限速下载-KDown🔥🔥🔥 // @namespace https://kdown.moiu.net // @description 一款百度云加速程序,加速永无止境,无视黑号 // @version 1.2.7 // @author KDown // @license MIT // @icon https://upload.moiu.net/MoTeam-CDN-img/logo.png // @resource https://cdn.staticfile.org/limonte-sweetalert2/11.7.1/sweetalert2.min.css // @require https://cdn.staticfile.org/limonte-sweetalert2/11.7.1/sweetalert2.all.min.js // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_setClipboard // @match *://pan.baidu.com/* // @match *://yun.baidu.com/* // @match *://pan.baidu.com/disk/home* // @match *://yun.baidu.com/disk/home* // @match *://pan.baidu.com/disk/main* // @match *://yun.baidu.com/disk/main* // @match *://pan.baidu.com/s/* // @match *://yun.baidu.com/s/* // @match *://pan.baidu.com/share/* // @match *://yun.baidu.com/share/* // @connect moiu.net // @connect staticfile.org // @connect baidu.com // ==/UserScript== (() => { // 在页面加载时立即调用GetNotify函数 GetNotify(); if (window.location.pathname === "/disk/home") { window.location.replace("./main"); } AddElement(); function GetNotify() { GM_xmlhttpRequest({ method: "GET", url: "https://apiv.moiu.net/api/MF/isok", onload: function(response) { try { const jsondata = JSON.parse(response.responseText); // 假设返回的jsondata格式和您示例中的相同 const { code, message, open, gg } = jsondata; // 确保公告是打开状态 if (open === 1 && code === 200) { Swal.fire({ icon: "info", title: gg, // 使用公告标题 text: message, // 使用公告信息 confirmButtonText: "关闭", }); } } catch (e) { console.error("Error fetching announcement:", e); } }, }); } function AddElement() { // 检查按钮是否已经存在,如果存在,则不再尝试添加 if (document.getElementById("KDown") === null) { const toolbar = document.querySelector("div.wp-s-agile-tool-bar__header"); if (toolbar) { // 创建按钮并添加到工具栏 const newButton = document.createElement("button"); newButton.id = "KDown"; newButton.className = "u-button nd-file-list-toolbar-action-item u-button--primary"; newButton.style.marginRight = "8px"; newButton.innerText = "KDown"; toolbar.prepend(newButton); const statusButton = document.createElement("button"); statusButton.id = "KDownStatus"; statusButton.className = "u-button nd-file-list-toolbar-action-item u-button--primary"; statusButton.style.marginRight = "8px"; statusButton.innerText = "KDown Status"; toolbar.prepend(statusButton); newButton.addEventListener("click", handleKDownClick); statusButton.addEventListener("click", handleKDownStatusClick); // 一旦按钮添加成功,停止重试逻辑 } else { // 如果工具栏不存在,100毫秒后再次尝试 setTimeout(AddElement, 100); } } else { // 如果按钮已经存在,则不再进行任何操作 console.log("KDown button already added."); } } async function getBdsToken() { var htmlString = $("html").html(); var regex = /"bdstoken":"(\w+)"/; var match = regex.exec(htmlString); return match ? match[1] : null; } async function shareFiles(bdstoken, selectedIds, bdpassword) { return $.post("https://pan.baidu.com/share/set?channel=chunlei&bdstoken=" + bdstoken, { period: 1, pwd: bdpassword, eflag_disable: true, channel_list: "[]", schannel: 4, fid_list: JSON.stringify(selectedIds) }).then(response => response); } function getDownloadLinkFromApi(link, password) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: "GET", url: `https://apiv.moiu.net/api/MF/get_link?url=${encodeURIComponent(link)}&dir=/&password=${encodeURIComponent(password)}`, onload: function(response) { if (response.status >= 200 && response.status < 300) { const data = JSON.parse(response.responseText); resolve(data); } else { reject({ status: response.status, statusText: response.statusText }); } }, onerror: function(response) { reject({ status: response.status, statusText: "Network error" }); } }); }); } async function handleKDownClick() { let selectedElements = document.querySelectorAll(".wp-s-pan-table__body-row.mouse-choose-item.selected, .wp-s-file-grid-list__item.text-center.cursor-p.mouse-choose-item.is-checked, .wp-s-file-contain-list__item.text-center.cursor-p.mouse-choose-item.is-checked"); let selectedIds = Array.from(selectedElements).map(item => item.getAttribute("data-id")); if (selectedIds.length === 0) { Swal.fire({ showConfirmButton: true, title: '系统提示', text: '请选择需要下载的文件', icon: 'error' }); return; } if (selectedIds.length > 1) { Swal.fire({ showConfirmButton: true, title: '系统提示', text: '暂时只能下载一个文件', icon: 'error' }); return; } let selectedItems = Array.from(selectedElements); if (selectedItems.some(item => item.dataset.isdir === "true") || $('tr.selected img[src*="ceH8M5EZYnGhnBKRceGqmaZXPPw2xbO+1x"]').length > 0) { Swal.fire({ title: '系统提示', text: '请不要选择文件夹解析,因为还没学会.', icon: 'error' }); return; } const { value: password } = await Swal.fire({ title: '输入密码', input: 'password', inputLabel: '输入在QQ群中公告密码,群在脚本简介可以看到', inputPlaceholder: '输入以KDown_开头的密码,防止刷流量狗', inputAttributes: { maxlength: 30, autocapitalize: 'off', autocorrect: 'off' } }); if (!password) { Swal.fire("提示", "需要密码来继续", "info"); return; } Swal.fire({ title: "正在获取下载链接...", onBeforeOpen: () => { Swal.showLoading(); } }); const bdstoken = await getBdsToken(); if (!bdstoken) { Swal.fire("错误", "无法获取bdstoken", "error"); return; } const bdpassword = "zzzz"; // 这个是分享密码,云端设的就是这个,不要乱改了 const shareResponse = await shareFiles(bdstoken, selectedIds, bdpassword); const apiResponse = await getDownloadLinkFromApi(shareResponse.link, password); if (apiResponse && apiResponse.error && Object.keys(apiResponse).length === 1) { // 只有error组存在 Swal.update({ icon: 'error', title: '错误', text: apiResponse.error }); } else if (apiResponse && apiResponse.dlink && apiResponse.server_filename) { // 正常情况 const dlink = apiResponse.dlink; Swal.fire({ icon: 'success', title: '下载链接获取成功', html: ` 文件名: ${apiResponse.server_filename}
链接:
用户代理(UA): `, didOpen: () => { const copyButton = document.getElementById("copyButton"); copyButton.addEventListener("click", async () => { const downloadLinkInput = document.getElementById("downloadLink"); try { await navigator.clipboard.writeText(downloadLinkInput.value); Swal.fire("已复制", "下载链接已复制到剪贴板", "success"); } catch (err) { console.error("Failed to copy: ", err); Swal.fire("复制失败", "无法将链接复制到剪贴板", "error"); } }); }, preConfirm: () => { return { dlink: apiResponse.dlink }; } }); } } async function handleKDownStatusClick() { // 处理状态按钮点击事件 Swal.fire("检查中...", "正在检查服务器状态,请稍候...", "info"); // 发送请求获取服务器状态 GM_xmlhttpRequest({ method: "GET", url: "https://apiv.moiu.net/api/status", onload: function(response) { try { const data = JSON.parse(response.responseText); // 假设服务器返回的数据中有code和message字段 const { code, message } = data; if (code === 200) { Swal.fire({ icon: "success", title: "服务器状态", text: message, }); } else if (code === 201) { Swal.fire({ icon: "error", title: "服务器状态", text: message, }); } else { Swal.fire({ icon: "warning", title: "服务器状态", text: "未知状态", }); } } catch (error) { Swal.fire("错误", "处理服务器响应时发生错误", "error"); console.error("Error handling server response:", error); } }, onerror: function(error) { Swal.fire("错误", "无法连接到服务器", "error"); console.error("Error connecting to server:", error); }, }); } })();