// ==UserScript== // @name 阿里云盘脚本V5.7【修复无法执行】 // @namespace http://bbs.tampermonkey.net.cn/ // @version 66.85 // @description 【bbs.tampermonkey.net.cn】李恒道 // @author 【bbs.tampermonkey.net.cn】李恒道 // @match https://passport.aliyundrive.com/* // @match https://www.aliyundrive.com/drive/* // @match https://www.aliyundrive.com/drive // @match https://aliyundrive.com/drive/* // @match https://aliyundrive.com/drive // @match http://passport.aliyundrive.com/* // @match http://www.aliyundrive.com/drive/* // @match http://www.aliyundrive.com/drive // @match http://aliyundrive.com/drive/* // @match http://aliyundrive.com/drive // @icon https://www.google.com/s2/favicons?domain=aliyundrive.com // @require https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js // @require https://cdn.bootcdn.net/ajax/libs/js-sha1/0.6.0/sha1.js // @grant unsafeWindow // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @connect aliyundrive.com // @connect alicloudccp.com // @run-at document-start // ==/UserScript== let username = '' let password = '' //自动登陆配置项 let NewLink = true; //使用新版链接 let FileList = [] let Searchlist = [] let CreateListner = false; let GenerateFileInShow = false; let parent_file_id = 'root' let listurl = '' let CreateSaveBtn = false; let Totallistnum = 0; let Sublistnum = 0; var ShowFileObj = { name: '文件获取失败', content_hash: 'hash获取失败', size: '公众号:叛逆青年旅舍,来自油猴中文网:bbs.tampermonkey.net.cn', content_type: 'Fucccccck', file_id: '天才少年李恒道', content_type: '系统李恒道吹牛逼理论,QQ4548212' } let accesstoken = '' let filenum = 0; let next_markerlist = [] let totalnum = 0; let Uploadlist = [] let Success = 0; let Faile = 0; let GenerateDialogShow;//对话框1 let GenerateFileinDialogShow;//对话框2 let GenerateShow = false let uploadsize = 1000000 //他妈看不懂了,写的是啥 function GetFileSha1Encr(tempobj) { if (NewLink == true) { let name = tempobj.name.replace('|', '=') if (name === '') { name = 'nameisnull' } return 'aliyunpan://' + name + '|' + tempobj.content_hash.replace('|', '=') + '|' + tempobj.size + '|' + tempobj.content_type.replace('|', '=') } return window.btoa(unescape(encodeURIComponent(JSON.stringify({ name: tempobj.name, content_hash: tempobj.content_hash, size: tempobj.size, content_type: tempobj.content_type, })))) } function CurrentText() { var d = new Date(), str = ''; str += d.getFullYear() + '年'; str += d.getMonth() + 1 + '月'; str += d.getDate() + '日'; str += d.getHours() + '时'; str += d.getMinutes() + '分'; str += d.getSeconds() + '秒'; return str + '序列文件.txt'; } async function CreateTextUpload(name, size, hash) { return new Promise((resolve, reject) => { let useruid = JSON.parse(localStorage.getItem('token')).default_drive_id let uploadtext = '{"drive_id":"' + useruid + '","part_info_list":[{"part_number":1}],"parent_file_id":"' + parent_file_id + '","name":"' + name + '","type":"file","check_name_mode":"auto_rename","size":' + size + ',"content_hash":"' + hash + '","content_hash_name":"sha1"}' GM_xmlhttpRequest({ url: "https://api.aliyundrive.com/v2/file/create", method: "POST", data: uploadtext, headers: { "Content-type": "application/json;charset=utf-8", "Authorization": accesstoken }, onload: function (xhr) { resolve(xhr.responseText); } }); }); } async function UploadTextBin(tageturl, targetdata) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ url: tageturl, method: "PUT", data: targetdata, headers: { "Content-type": " ", "Referer": "https://www.aliyundrive.com/", // "Authorization": accesstoken }, //binary:true, onload: function (xhr) { resolve(xhr.responseText); } }); }); } async function Complete(upload_id, file_id) { return new Promise((resolve, reject) => { let useruid = JSON.parse(localStorage.getItem('token')).default_drive_id let uploadtext = '{"drive_id":"' + useruid + '","upload_id":"' + upload_id + '","file_id":"' + file_id + '"}' GM_xmlhttpRequest({ url: 'https://api.aliyundrive.com/v2/file/complete', method: "POST", data: uploadtext, headers: { "Content-type": "application/json;charset=utf-8", "Authorization": accesstoken }, onload: function (xhr) { resolve(xhr.responseText); } }); }); } async function UploadTextToAliYunpan(text) { var tempblob = new Blob([text]) if (tempblob.size > uploadsize) { alert('文件超出脚本限制大小,无法上传至云盘!请选择导出文件') return; } let create = JSON.parse(await CreateTextUpload(CurrentText(), tempblob.size, sha1(text))) if (create.rapid_upload == true) { alert('网盘内存在该文件!') } let createurl = create.part_info_list[0].upload_url await UploadTextBin(createurl, text) let finishret = await Complete(create.upload_id, create.file_id) if (finishret.indexOf('file_id') == -1) { alert('保存至网盘失败!') } finishret = JSON.parse(finishret) let sharurl = GetFileSha1Encr(finishret) alert('保存至网盘成功!,已设置到剪辑版') GM_setClipboard(sharurl) //file_id JSON.parse console.log('UploadTextToAliYunpan', finishret) } function GetDecrText(text) { debugger; if (text.indexOf('115://') !== -1) { let sizelist = text.replace('115://', '').split('|') if (sizelist.length < 4) { return 'Error' } if (sizelist.length > 4) { var n = parseInt(sizelist[1]); if (!isNaN(n)) { return { content_hash: sizelist[2], content_type: 'null', name: sizelist[0], size: sizelist[1] } } let temp = text let sizelength = text.replace('115://', '').split('|').length - 4 for (let num = 0; num < sizelength; num++) { temp = temp.replace('|', '=') } sizelist = temp.replace('115://', '').split('|') } return { content_hash: sizelist[2], content_type: 'null', name: sizelist[0], size: sizelist[1] } } if (text.indexOf('aliyunpan::') !== -1) { let sizelist = text.replace('aliyunpan::', '').split('|') if (sizelist.length !== 4) { return 'Error' } return { content_hash: sizelist[1], content_type: sizelist[3], name: sizelist[0], size: sizelist[2] } } if (text.indexOf('aliyunpan://') !== -1) { let sizelist = text.replace('aliyunpan://', '').split('|') if (sizelist.length !== 4) { return 'Error' } return { content_hash: sizelist[1], content_type: sizelist[3], name: sizelist[0], size: sizelist[2] } } try { return JSON.parse(decodeURIComponent(escape(window.atob(text)))) } catch (err) { return 'Error' } } function MulReadialogCreate() { if (GenerateShow === true) { GenerateShow = false; GenerateDialogShow.remove() } //导入文件 if (GenerateFileInShow == true) { return; } GenerateFileInShow = true GenerateFileinDialogShow = document.createElement('div') unsafeWindow.ReadFileList = ReadFileList GenerateFileinDialogShow.innerHTML = `
` GenerateFileinDialogShow.onclick = function (event) { //多选关闭删除 if (event.target.outerHTML.indexOf('#PDSClose') != -1) { Uploadlist = [] GenerateFileInShow = false; GenerateFileinDialogShow.remove() return; } if (event.target.outerHTML.indexOf('导入文件') != -1) { document.getElementById("uploadfile").click(); return; } if (event.target.outerHTML.indexOf('开始提取') != -1) { alert('正在开始上传,请勿重复点击!') StartAllFile() return; } } document.querySelector('body').append(GenerateFileinDialogShow) } function MulFileDialogCreate() { if (GenerateFileInShow == true) { Uploadlist = [] GenerateFileInShow = false; GenerateFileinDialogShow.remove() } if (GenerateShow == true) { return; } GenerateShow = true GenerateDialogShow = document.createElement('div') GenerateDialogShow.innerHTML = ` ` GenerateDialogShow.onclick = function (event) { debugger; console.log('去他妈的导出', event.target) //多选关闭删除 if (event.target.outerHTML.indexOf('#PDSClose') != -1) { GenerateShow = false; GenerateDialogShow.remove() return; } if (event.target.innerText == '全部选择') { document.querySelectorAll('.FileListOutShow >div').forEach(item => { SetSelectItem(item, true) }) return; } if (event.target.innerText == '搜索') { SearchFileMulInsert(document.querySelector('[name="SearchMulFile"]').value); return; } if (event.target.innerText == '保存至网盘') { let outtext = '阿里云油猴插件By:油猴中文版\n作者:天才少年李恒道QQ:4548212\n公众号:叛逆青年旅舍\n油猴中文网:bbs.tampermonkey.net.cn\n' document.querySelectorAll('.FileListOutShow >div').forEach(item => { if (item.checkbox == true) { outtext = outtext + item.name + '\n' + item.date + '\n' } }) if (outtext !== '阿里云油猴插件By:油猴中文版\n作者:天才少年李恒道QQ:4548212\n公众号:叛逆青年旅舍\n油猴中文网:bbs.tampermonkey.net.cn\n') { alert('开始进行上传,请勿重复点击!') UploadTextToAliYunpan(outtext) } else { alert('未选择任何文件') } return; } if (event.target.innerText == '导出') { let outtext = '阿里云油猴插件By:油猴中文版\n作者:天才少年李恒道QQ:4548212\n公众号:叛逆青年旅舍\n油猴中文网:bbs.tampermonkey.net.cn\n' document.querySelectorAll('.FileListOutShow >div').forEach(item => { if (item.checkbox == true) { outtext = outtext + item.name + '\n' + item.date + '\n' } }) if (outtext !== '阿里云油猴插件By:油猴中文版\n作者:天才少年李恒道QQ:4548212\n公众号:叛逆青年旅舍\n油猴中文网:bbs.tampermonkey.net.cn\n') { download('导出文件成功By:油猴中文网.txt', outtext) } else { alert('未选择任何文件') } return; } } document.querySelector('body').append(GenerateDialogShow) SearchFileMulInsert('') } function LoadDownloadText(url) { debugger; GM_xmlhttpRequest({ url: url, method: "GET", headers: { //"Content-type": "application/json;charset=utf-8", "Referer": "https://www.aliyundrive.com/", // "Authorization": accesstoken }, onload: function (xhr) { debugger; MulReadialogCreate() AddText(xhr.responseText) alert('解析完成!') console.log('解析文本内容!', xhr.responseText) } }); } function DownloadTextRead(obj) { alert('开始读取文件内容,时长根据网速决定,请勿重复点击'); console.log('获取远程对象开始', obj) let useruid = JSON.parse(localStorage.getItem('token')).default_drive_id let uploadtext = '{"drive_id":"' + useruid + '","file_id":"' + obj.file_id + '"}' GM_xmlhttpRequest({ url: "https://api.aliyundrive.com/v2/file/get_download_url", method: "POST", data: uploadtext, headers: { "Content-type": "application/json;charset=utf-8", "Referer": "https://www.aliyundrive.com/", "Authorization": accesstoken }, onload: function (xhr) { var json = JSON.parse(xhr.responseText); if (json.url === undefined) { alert('获取下载地址失败!') return; } LoadDownloadText(json.url) } }); //MulReadialogCreate() } async function UploadOne(num) { return new Promise((resolve, reject) => { let obj = Uploadlist[num] let text = GetDecrText(obj.date) let useruid = JSON.parse(localStorage.getItem('token')).default_drive_id let uploadtext = '{"drive_id":"' + useruid + '","part_info_list":[{"part_number":1}],"parent_file_id":"' + parent_file_id + '","name":"' + text.name + '","type":"file","check_name_mode":"auto_rename","size":' + text.size + ',"content_hash":"' + text.content_hash + '","content_hash_name":"sha1"}' GM_xmlhttpRequest({ url: "https://api.aliyundrive.com/v2/file/create", method: "POST", data: uploadtext, headers: { "Content-type": "application/json;charset=utf-8", "Authorization": accesstoken }, onload: function (xhr) { var json = JSON.parse(xhr.responseText); if (json.rapid_upload == true) { Success++; SetSelectItem(obj, true, false) resolve('success'); } else { Faile++; SetSelectItem(obj, false, false) resolve('faile'); } } }); }); } async function StartAllFile() { Uploadlist = document.querySelectorAll('.FileListOutShow >div') Success = 0; Faile = 0; for (let index = 0; index < Uploadlist.length; index++) { if (Uploadlist[index].checkbox === false) { await UploadOne(index) } } alert('上传完毕,成功了:' + Success + '个文件,失败了:' + Faile + '文件') unsafeWindow.location.reload(); } function AddText(text) { let list = text.split('\n') for (let index = 0; index < list.length; index++) { let rowtext = list[index] if (rowtext.indexOf('eyJu') != -1 || rowtext.indexOf('aliyunpan://') != -1 || rowtext.indexOf('aliyunpan::') != -1 || rowtext.indexOf('115://') != -1) { let temp = GetDecrText(rowtext) if (temp.content_hash == undefined) { alert('存在文件不正確!已跳過該文件!') } else { let FileItem = document.createElement('div') totalnum += 1 SetTotalnum() FileItem.checkbox = false; FileItem.date = rowtext FileItem.name = temp.name FileItem.innerHTML = '