// ==UserScript== // @name 蜜柑计划 Arai2 RPC 下载 - Mikan Project Aria2 RPC Download // @namespace http://tampermonkey.net/ // @version 0.1 // @description 复制磁力链接时 可以通过 RPC 快速创建 aria2 下载任务 // @author Licht // @license MIT // @homepage https://github.com/ewigl/mpard // @match http*://mikanani.me/* // @icon https://mikanani.me/images/favicon.ico?v=2 // @require https://unpkg.com/jquery@3.7.1/dist/jquery.min.js // @require https://unpkg.com/sweetalert2@11.10.1/dist/sweetalert2.all.min.js // @connect localhost // @connect * // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @downloadURL none // ==/UserScript== ;(function () { 'use strict' let styleCSS = ` #magnet-link-box { display: none; border-left: 1px solid; padding-left: 8px; } #rpc-setting-box { display: none; border-left: 1px solid; padding-left: 8px; } .custom-button { color: white; background-color: slategrey; padding: 4px; margin: 8px 0px; border: none; border-radius: 5px; } .rpc-settings-label { display: flex; align-items: center; } .rpc-settings-label div { width: 20%; } .rpc-settings-input { display: inline-block; flex: 1; height: 32px; padding: 5px; border: 1px solid; border-radius: 5px; } ` GM_addStyle(styleCSS) // 默认设置 let defaultConfig = { rpcSettings: [ { name: 'rpc_address', value: 'http://localhost:6800/jsonrpc', }, { name: 'rpc_secret', value: '', }, { name: 'rpc_dir', value: '', }, ], } // 默认 message let message = Swal.mixin({ position: 'center-end', toast: true, confirmButtonText: '确定', cancelButtonText: '取消', width: '32rem', timer: 5000, timerProgressBar: true, }) // 工具 let util = { getValue(name) { return GM_getValue(name) }, setValue(name, value) { GM_setValue(name, value) }, initDefaultConfig() { defaultConfig.rpcSettings.forEach((value) => { util.getValue(value.name) === undefined && util.setValue(value.name, value.value) }) }, resetDefaultConfig() { defaultConfig.rpcSettings.forEach((value) => { util.setValue(value.name, value.value) }) }, sendToRPC: async (magnetLink) => { let rpc = { address: util.getValue('rpc_address'), secret: util.getValue('rpc_secret'), dir: util.getValue('rpc_dir').trim() === '' ? undefined : util.getValue('rpc_dir'), } let rpcData = { id: new Date().getTime(), jsonrpc: '2.0', method: 'aria2.addUri', params: [ `token:${rpc.secret}`, [magnetLink], { dir: rpc.dir, }, ], } GM_xmlhttpRequest({ method: 'POST', url: rpc.address, data: JSON.stringify(rpcData), onload: (response) => { let resJson = JSON.parse(response.responseText) if (resJson.result) { message.fire({ icon: 'success', title: 'RPC请求发送成功, 请前往控制台查看', }) } else { message.fire({ icon: 'error', title: 'RPC请求发送失败, 请检查RPC设置是否正确', text: `${resJson.error.code} / ${resJson.error.message}`, }) } }, onerror: (error) => { message.fire({ icon: 'error', title: 'RPC请求发送失败, 请检查RPC设置是否正确', text: JSON.stringify(error), }) }, onabort: () => { message.fire({ icon: 'error', title: '内部错误', }) }, }) }, } let operation = { onCopyMagnet: (event) => { let target = event.target let magnetLink = $(target).attr('data-clipboard-text') // 主 DOM let mpardDom = `