aliyun_alist解析
// ==UserScript==
// @name aliyun_alist解析
// @namespace http://tampermonkey.net/
// @version 0.3.1
// @description try to take over the world!
// @author You
// @match https://www.aliyundrive.com/s/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=aliyundrive.com
// @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// ==/UserScript==
(async function() {
'use strict';
//插入窗口
let window_div=insertWindow()
insertTd(window_div)
//获取按钮对象
let button=$('#aliyun_button')[0]
//设置按钮事件
button.onclick=async function(e){
//设置请求网址
let url='127.0.0.1'
let authorization= await alist_login(url)
let refresh_token=await get_refresh_token(url,authorization)
let id=id_get()
let text=document.querySelector('#aliyun_text')
let type=$('#vedio_type')[0].value
console.log(type)
let mount_path='/aliyun/'+type+'/'+text.value
console.log(mount_path)
let add_obj=set_add_obj(mount_path,refresh_token,id.share_id,id.folder_id)
//console.log(add_obj)
add_aliyun_share(url,authorization,add_obj)
}
// Your code here...
})();
function alist_login(url){
return new Promise((resolve,reject)=>{
GM_xmlhttpRequest({
method:"post",
url:"http://"+url+":5244/api/auth/login",
synchronous:true,
headers:{
'Content-Type':'application/json;charset=utf-8'},
data:JSON.stringify({
'username':'用户名',
'password':'密码',
'otp_code':''
}),
onload: function(res){
let authorization=JSON.parse(res.response).data.token
console.log(authorization)
let code=JSON.parse(res.response).message
let result1_div=document.querySelector('#result1_div')
result1_div.innerHTML='登陆状态:'+code
resolve(authorization)
}
})
})
}
function add_aliyun_share(url,authorization,add_obj){
GM_xmlhttpRequest({
method:"post",
url:"http://"+url+":5244/api/admin/storage/create",
synchronous:true,
headers:{
Authorization:authorization,
'Content-Type':'application/json;charset=utf-8'
},
data:add_obj,
onload: function(res){
let code=JSON.parse(res.response).message
let result1_div=document.querySelector('#result2_div')
result1_div.innerHTML='创建状态:'+code
}
})
}
function id_get(){
console.log('开始输出')
let share_url=location.href
let share_id
let folder_id
if(share_url.match(/(?<=\/s\/).*\//)!=null){
share_id=share_url.match(/(?<=\/s\/).*?(?=\/)/)[0]
folder_id=share_url.match(/(?<=\/folder\/).*/)[0]
console.log('share_id:'+share_id+" folder_id:"+folder_id)
}else{
share_id=share_url.match(/(?<=\/s\/).*/)[0]
folder_id='root'
console.log('share_id:'+share_id+" folder_id:无")
}
return {
share_id:share_id,
folder_id:folder_id
}
}
function set_add_obj(mount_path,refresh_token,share_id,root_folder_id){
let add_obj={"mount_path":"","order":0,"remark":"","cache_expiration":30,"web_proxy":false,"webdav_policy":"302_redirect","down_proxy_url":"","extract_folder":"","driver":"AliyundriveShare","addition":"{\"refresh_token\":\"\",\"share_id\":\"\",\"share_pwd\":\"\",\"root_folder_id\":\"\",\"order_by\":\"\",\"order_direction\":\"\"}"}
add_obj.mount_path=mount_path
let addition_obj=JSON.parse(add_obj.addition)
addition_obj.refresh_token=refresh_token
addition_obj.share_id=share_id
addition_obj.root_folder_id=root_folder_id
add_obj.addition=JSON.stringify(addition_obj)
return JSON.stringify(add_obj)
}
function get_refresh_token(url,authorization){
return new Promise((resolve,reject)=>{
GM_xmlhttpRequest({
method:"get",
url:"http://"+url+":5244/api/admin/storage/get?id=2",
synchronous:true,
headers:{
Authorization:authorization
},
onload: function(res){
let refresh_token=JSON.parse(JSON.parse(res.response).data.addition).refresh_token
console.log(refresh_token)
resolve(refresh_token)
}
})
})
}
function insertWindow(){
var window_div=document.createElement('div')
console.log('创建面板')
setBasicStyleWindow(window_div)
setLayoutWindow(window_div)
var body=document.querySelector('body')
body.appendChild(window_div)
return window_div
}
function insertTd(window_div){
$(window_div).append($(
`
<tr id='input'>
<td>
<select name="vedio_type" id="vedio_type">
<option value="动漫">动漫</option>
<option value="剧集">剧集</option>
<option value="电影">电影</option>
<option value="综艺">综艺</option>
</select>
</td>
<td>
<input type="text" id="aliyun_text">
</td>
<td>
<input type="button" value="创建" id="aliyun_button">
</td>
</tr>
`))
let div1=document.createElement('div')
div1.id='result1_div'
let div2=document.createElement('div')
div2.id='result2_div'
window_div.appendChild(div1)
window_div.appendChild(div2)
}
//设置窗口样式
function setBasicStyleWindow(window_div){
//设置背景
window_div.style.backgroundColor='rgba(255,255,3,0.28)'
//设置宽高
window_div.style.height='auto'
window_div.style.width='auto'
//设置边框
window_div.style.border='1px solid skyblue'
window_div.style. borderRadius='1px'
}
function setLayoutWindow (window_div){
//设置元素布局类型
window_div.style.display='block'
//设置重叠显示顺序
window_div.style.zIndex='9999'
//设置定位方式
window_div.style.position='fixed'
//设置坐标
window_div.style.top='0px'
window_div.style.left='50px'
//设置溢出处理方式
//window_div.style.overflowX='scroll'
window_div.style.overflowY='scroll'
}