// ==UserScript== // @name 蜜柑计划 快速下载 - Mikan Project Quick Download // @namespace https://github.com/ewigl/mpus // @version 0.4.0 // @description 高亮磁链, 复制磁链(时/后)直接打开, 通过RPC快速创建aria2下载任务. // @author Licht // @license MIT // @homepage https://github.com/ewigl/mpus // @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 GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @downloadURL none // ==/UserScript== ;(function () { 'use strict' const styleCSS = ` .custom-box { border-left: 2px solid; padding-left: 8px; margin-bottom: 16px; } .custom-button { color: white; background-color: slategrey; padding: 4px; margin: 8px 0px; border: none; border-radius: 5px; } .custom-title { color: black; font-size: 16px; font-weight: bold; } #instant_open_input { width: 16px; height: 16px; } .highlight-color-dot { display: inline-block; width: 20px; height: 20px; margin: 2px; border: 1px solid black; border-radius: 50%; cursor: pointer; } .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) // 默认设置 const defaultConfig = { rpcSettings: [ { name: 'rpc_address', value: 'http://localhost:6800/jsonrpc', }, { name: 'rpc_secret', value: '', }, { name: 'rpc_dir', value: '', }, ], colorList: [ '#ff530e', '#fe9b36', '#edcf00', '#32b16c', '#00b8ee', '#546fb4', '#8956a1', '#59b7d0', '#4cb665', '#fff', '#000', '#f00', // ], defaultColor: '#888', } // 默认 message const message = Swal.mixin({ position: 'center-end', toast: true, confirmButtonText: '确定', cancelButtonText: '取消', width: '32rem', timer: 5000, timerProgressBar: true, }) // 工具 const util = { getValue(name) { return GM_getValue(name) }, setValue(name, value) { GM_setValue(name, value) }, initDefaultConfig() { defaultConfig.rpcSettings.forEach((item) => { util.getValue(item.name) === undefined && util.setValue(item.name, item.value) }) // 是否立即打开磁链 util.getValue('magnet_link_instant_open') === undefined && util.setValue('magnet_link_instant_open', false) // 高亮磁链颜色 util.getValue('magnet_highlight_color') === undefined && util.setValue('magnet_highlight_color', defaultConfig.defaultColor) // 添加style以高亮磁链 GM_addStyle(`.magnet-link {color: ${util.getValue('magnet_highlight_color')}}`) }, getDefaultColorButtonsDom() { let dom = '' defaultConfig.colorList.forEach((item) => { dom += `
` }) return dom }, resetToDefaultRPCConfig() { 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: '内部错误', }) }, }) }, } const operation = { onClickSettingsButton: () => { // 主 DOM let mpqdDom = `