// ==UserScript==
// @name 阿里云盘助手
// @namespace http://tampermonkey.net/
// @version 1.1.6
// @description 支持生成文件下载链接、修改文件后缀,支持第三方播放器DPlayer(突破视频2分钟限制,长按倍速,选集,历史播放)
// @author 罗根大人
// @match https://www.aliyundrive.com/*
// @connect *
// @icon https://img.alicdn.com/imgextra/i1/O1CN01JDQCi21Dc8EfbRwvF_!!6000000000236-73-tps-64-64.ico
// @require https://cdn.bootcdn.net/ajax/libs/localforage/1.10.0/localforage.min.js
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.min.js
// @require https://cdn.bootcdn.net/ajax/libs/dplayer/1.27.0/DPlayer.min.js
// @require https://cdn.bootcdn.net/ajax/libs/hls.js/1.3.0/hls.min.js
// @run-at document-body
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @license MIT
// @downloadURL none
// ==/UserScript==
(function() {
'use strict'
var showAria2SetHtml = '
'
let name = item.name;
let fileId = item.fileId;
let compilationId = ""
let path = '/drive/'
if(item.share){
path = item.compilationId;
}else if (item.compilationId) {
let i = item.compilationId.indexOf('_');
compilationId = item.compilationId.substring(i + 1, item.compilationId.length);
path += 'folder/' + compilationId;
item.share=false;
}
let progressPercentage = item.progressPercentage;
let fromSourceDescription = item.fromSourceDescription;
html += `
已观看${progressPercentage}%
`
html += '
'
}
let videoList = resp.recentUsed.items.filter(function (item, index) {
return item.category === 'video'
})
setItem("historyCloudVideo", videoList);
let list = getItem("historyVideo");
let videoLength = videoList.length;
if (list) {
videoLength += list.length
} else {
list = []
}
let html = ''
if (list.length > 0) {
html += '
'
html += '
本地历史
清空本地历史
'
list.forEach(handler)
html += '
'
html += '
'
}
html += '
云端历史
'
videoList.forEach(handler)
html += '
'
dp.showDiv(title, html);
dp.hideTip()
$('.history_video').on('click', function (e) {
let id = $(e.currentTarget).attr('fileId');
let compilationId = $(e.currentTarget).attr('compilationId');
dp.playInfoToHistory(id, compilationId)
$('.ant-modal-Link').remove();
});
$('.clearHistory').on('click', function () {
setItem('historyVideo', []);
$('#localHistoryList').remove();
})
})
}
dp.session = function (callback){
let token = getToken() || {}
let deviceId= token.user_id.split('').reverse().join("").substring(0,20);
let userId = token.user_id;
unsafeWindow.luoGenSession(function (p,s,nd){
deviceId = nd;
console.log('你好,罗根!')
createSession(function(signature,d){
dp.user["x-device-id"] = deviceId;
dp.user["x-signature"]= signature;
localStorage.setItem('x-device-id',deviceId)
localStorage.setItem('x-signature',signature)
callback && callback(p,s);
},p,s,deviceId)
},window.atob('NWRkZTRlMWJkZjllNDk2NmIzODdiYTU4ZjRiM2ZkYzM='),deviceId,userId)
}
dp.playInfoToHistory = function (id, compilationId) {
let $ = getJquery();
let historyCloudVideo = getItem("historyCloudVideo");
let historyVideo = getItem("historyVideo");
if (!historyCloudVideo) {
historyCloudVideo = []
}
if (!historyVideo) {
historyVideo = []
}
let listVideo = historyVideo.concat(historyCloudVideo)
listVideo = listVideo.filter(function (item, index) {
return item.fileId === id
})
if (listVideo.length <= 0) {
showError('该文件不在历史播放列表中')
return
}
let videoInfo = listVideo[0];
if(videoInfo.share){
window.open(videoInfo.compilationId)
return
}
dp.videoPage.name = videoInfo.name;
dp.videoPage.folderName = videoInfo.fromSourceDescription;
dp.videoPage.compilationId = compilationId;
let name = videoInfo.name;
let href = '/drive/'
if (compilationId) {
href += 'folder/' + compilationId;
}
if(videoInfo.share){
dp.videoPage.share = true;
href = compilationId;
}else {
dp.videoPage.share = false;
}
let html = `'
if (element.length) {
element.append(elementhtml)
} else {
jq(document.body).append('
')
}
var hide = hideShow
setTimeout(function () {
hide()
}, timeout || 3000)
}
let showError = function (msg, timeout) {
let jq = getJquery()
hideShow()
var element = jq('.aDrive div')
var elementhtml = '
'
if (element.length) {
element.append(elementhtml)
} else {
jq(document.body).append('
')
}
var hide = hideShow
setTimeout(function () {
hide()
}, timeout || 3000)
}
let isUrlExpires = function (url) {
var time = url.length > 1 && 6000
, ex = url.match(/&x-oss-expires=(\d+)&/);
return ex && ex[1] && + "".concat(ex[1], "000") - time < Date.now();
};
let refresh_token = function (callback) {
let token = getToken()
if (token != null) {
return callback && callback(token)
}
if (!(token && token.refresh_token)) {
return callback && callback('')
}
getJquery().ajax({
type: 'post',
url: 'https://api.aliyundrive.com/token/refresh',
data: JSON.stringify({
refresh_token: token.refresh_token
}),
headers: {
'Content-type': 'application/json;charset=utf-8',
'x-signature': dp.user["x-signature"],
'x-device-id': dp.user["x-device-id"]
},
success: function (response) {
if (response instanceof Object && response.access_token) {
delete response.user_data
localStorage.setItem('token', response instanceof Object ? JSON.stringify(response) : response)
callback && callback(response)
} else {
callback && callback('')
}
},
error: function () {
callback && callback('')
}
})
}
function loadScript(src) {
if (!window.instances) {
window.instances = {};
}
if (!window.instances[src]) {
window.instances[src] = new Promise((resolve, reject) => {
const script = document.createElement("script")
script.src = src;
script.type = "text/javascript";
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
return window.instances[src];
}
let getTime = function (time) {
let h = parseInt(time / 60 / 60 % 24)
h = h < 10 ? '0' + h : h
let m = parseInt(time / 60 % 60)
m = m < 10 ? '0' + m : m
let s = parseInt(time % 60)
s = s < 10 ? '0' + s : s
return `${h}:${m}:${s}`
}
let getJquery = function () {
return $
}
let getLocalforage = function () {
return localStorage
}
let initPre = function () {
if (!dp.createDPlayer()) {
setTimeout(initPre, 500)
}
}
let refSession = function(){
let now = new Date().getTime();
let time = localStorage.getItem('LG_session') || 0;
let token = getToken() || {}
// 大于3分钟
if(now - time > 180000 && token.user_id){
localStorage.setItem('LG_session',now)
}else {
console.log("未到刷新时间或者时机")
return;
}
dp.session(function(a,b){});
}
setInterval(function(){
if(!getToken() && localStorage.length!=0){
localStorage.clear();
}
}, 1000)
window.addEventListener("storage", function (e) {
if(e.key==='x-device-id'){
dp.user["x-device-id"] = e.newValue;
console.log("deviceid 已刷新")
}
if(e.key==='x-signature'){
dp.user["x-signature"] = e.newValue;
console.log("signature 已刷新")
}
})
loadScript("https://cdn.jsdelivr.net/gh/wyndem/aliEccJs@1.0.7/js/main.js")
.then((val) => {
}
)
let loadFunc = function(){
if (!unsafeWindow.luoGenSession) {
setTimeout(loadFunc, 500)
}else {
dp.user['ref_time'] = new Date().getTime()
setInterval(refSession,300000);
refSession()
dp.initStatus=true;
dp.user["x-device-id"] =getItem("x-device-id");
dp.user["x-signature"] =getItem("x-signature");
}
}
loadFunc()
initXMLHttpRequest()
})()