Alist添加存储的时候,每次都要来回切换复制粘贴id,挺费劲的,写了个简易的脚本方便操作,分享一下完整的脚本。
添加脚本的时候,复制下面的代码,把前面四个变量替换成自己的就可以了。(手机上Via浏览器用起来还是很方便的)
// ==UserScript== // @name 快速上传Alist // @namespace http://tampermonkey.net/ // @version 0.1 // @description 简单就完了 // @AuThor 52pojie // @match *://*.aliyundrive.com/* // @Icon https://www.google.com/s2/favicons?sz=64&domain=aliyundrive.com // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_log // @grant GM_getValue // @grant GM_setValue // @connect * // @run-at document-end // ==/UserScript== (function() { 'use strict'; const baseUrl = 'http://xxxxxxxx:5244' const adminUser = '管理员用户名' const adminPwd = '管理员密码' const refresh_token = '自行获取云盘的refresh_token(可以通过mt管理器查看日志)' const headerPost = async (url, data, headers, type) => { return new Promise((resolve, reject) => { let option = { method: "POST", url: url, headers: headers, data: data, responseType: type || 'json', onload: (res) => { if (type === 'blob') { resolve(res) } else { const _re = res.response || res .responseText typeof _re === 'string' ? resolve(JSON.parse(_re)) : resolve(_re) } }, onerror: (err) => { reject(err); }, } try { let req = GM_xmlhttpRequest(option); } catch (error) { console.error(error); } }); }; async function addStorage({mount_path, share_id, share_pwd = "", root_folder_id = "root", order_by = "", order_direction = ""}){ return await headerPost(baseUrl + '/api/admin/storage/create',JSON.stringify({ mount_path: mount_path, order: 0, remark: '', cache_expiration: 30, // 缓存过期时间(分钟) web_proxy: false, // 是否开启web代{过}{滤}理 webdav_policy: "302_redirect", // Webdav策略: 302重定向 down_proxy_url: "", extract_folder: "", driver: "AliyundriveShare", addition: JSON.stringify({ refresh_token: refresh_token, share_id, share_pwd, root_folder_id, order_by, order_direction }) }), { "Authorization": GM_getValue('token'), "Content-Type": "application/json;charset=UTF-8" }) }; async function login() { const res = await headerPost(baseUrl + '/api/auth/login', JSON.stringify({username: adminUser, password: adminPwd, "otp_code":""}), {"Content-Type": "application/json;charset=UTF-8"}) if (res.code === 200) { GM_setValue('token', res.data.token) } else { toast("登录失败") } } function toast(msg) { const t = (() => { if (document.querySelector('#J_single_toast')) { return document.querySelector('#J_single_toast') } else { const _t = document.createElement('div') _t.id = 'J_single_toast' document.body.appendChild(_t) return _t } })() t.innerText = msg t.classList.toggle('show') setTimeout(() => {t.classList.toggle('show')}, 1500) } function createCustomDom() { let mount_path = `/xx云盘分享_${+new Date}` const cBtn = document.createElement('div') cBtn.innerText = "创建Alist存储" cBtn.className = "cBtn" document.body.appendChild(cBtn) const dialog = document.createElement('div') dialog.className = "mount-path-dialog" dialog.innerHTML = ` <div class="mask"></div> <div class="input-wrap"> <div class="input-item"> <p>请输入Alist挂载路径:</p> <input name="mount_path" value=${mount_path}> </div> <div class="input-item"> <p>请输入分享密码:</p> <input name="share_pwd"> </div> <div class="btn-group"> <div class="cancel btn">取消</div> <div class="confirm btn">确认</div> </div> </div>` document.body.appendChild(dialog) cBtn.addEventListener('click', () => { dialog.style.display = 'block'; dialog.querySelector('[name="mount_path"]').focus(); dialog.querySelector('[name="mount_path"]').setSelectionRange(1, 999); }) dialog.addEventListener('click', function(e){ if (Array.from(dialog.querySelectorAll('.mask, .cancel')).includes(e.target)) { closeDialog() } if (e.target === dialog.querySelector('.confirm')) { const arr = window.location.pathname.split('/') addStorage({ mount_path: dialog.querySelector('[name="mount_path"]').value, share_pwd: dialog.querySelector('[name="share_pwd"]').value, share_id: arr[2], root_folder_id: arr[4] }).then(res => { if (res.code === 200) { dialog.style.display = 'none' toast('创建成功') } else { toast(res.message) } }) } }) function closeDialog() { dialog.style.display = 'none' } } async function init() { GM_addStyle(` #J_single_toast { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 1001; display: none; background: rgba(0,0,0,0.8); color: var(--basic_white); padding: 10px; max-width: 300px; border-radius: 4px; } #J_single_toast.show { display: block; } .cBtn { position: fixed; left: 50%; transform: translateX(-50%); bottom: 80px; z-index: 999; bottom: calc(constant(safe-area-inset-bottom) + 80px); bottom: calc(env(safe-area-inset-bottom) + 80px); display: inline-flex; align-items: center; justify-content: center; color: var(--basic_white); background: var(--theme_primary); height: 44px; padding: 0 16px; font-size: 16px; border-radius: 22px; } .mount-path-dialog { position: fixed; top: 0; left: 0; bottom: 0; right: 0; z-index: 1000; display: none; margin: auto; } .mount-path-dialog .mask { position: absolute; width: 100%; height: 100%; top: 0; left: 0; background: rgba(0,0,0,0.6) } .mount-path-dialog .input-wrap { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; justify-content: center; width: 300px; height: 280px; background: #fff; border-radius: 10px; box-sizing: boder-box; } .mount-path-dialog .input-wrap .input-item { margin-bottom: 8px; } .mount-path-dialog .input-wrap p { font-size: 14px; margin-bottom: 5px; } .mount-path-dialog .input-wrap input{ display: block; width: 240px; height: 40px; margin: 0 auto 15px; font-size: 12px; border: 1px solid #ccc; padding-left: 8px; border-radius: 4px; } .mount-path-dialog .input-wrap .btn-group { display: flex; align-items: center; justify-content: space-between; width: 260px; margin: 0 auto; } .mount-path-dialog .input-wrap .btn-group .btn { display: inline-flex; align-items: center; justify-content: center; flex: 1; margin: 0 10px; height: 40px; background: var(--theme_primary); color: var(--basic_white); font-size: 16px; border-radius: 4px; } .mount-path-dialog .input-wrap .btn-group .cancel { background: #fff; color: #333; border: 1px solid #ccc; } `) await login() createCustomDom() } window.addEventListener ("load", init); })();