您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
支持生成文件下载链接、修改文件后缀,支持第三方播放器DPlayer(突破视频2分钟限制,长按倍速,选集,历史播放)
当前为
// ==UserScript== // @name 阿里云盘助手 // @namespace http://tampermonkey.net/ // @version 1.0.9 // @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 // ==/UserScript== (function() { 'use strict' var showAria2SetHtml = '<div class="ant-modal-root"id="aria2-set-box"><div class="ant-modal-mask"></div><div tabindex="-1"class="ant-modal-wrap"role="dialog"><div role="document"class="ant-modal modal-wrapper--2yJKO"style="width: 340px;transform-origin: -14px 195px;"><div class="ant-modal-content"><div class="ant-modal-header"><div class="ant-modal-title">Aria2设置</div></div><div class="ant-modal-body"><div class="icon-wrapper--3dbbo"id="aria2-set-icon"><span data-role="icon"data-render-as="svg"data-icon-type="PDSClose"class="close-icon--33bP0 icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSClose"></use></svg></span></div><div>推送链接:</div><div class="content-wrapper--1_WJv"><input id="aria2-link"class="ant-input ant-input-borderless input--3oFR6"type="text"></div><div>推送路径:</div><div class="content-wrapper--1_WJv"><input id="aria2-path"class="ant-input ant-input-borderless input--3oFR6"type="text"></div><div>RPC密钥:</div><div class="content-wrapper--1_WJv"><input id="aria2-token"class="ant-input ant-input-borderless input--3oFR6"type="text"></div></div><div class="ant-modal-footer"><div class="footer--3Q0je"><button id="aria2-set-save"class="button--2Aa4u primary--3AJe5 small---B8mi">确定</button></div></div></div></div></div></div>'; let dp = { dPlayerNode: null, player: null, user:{ 'x-signature':'', 'x-device-id':'' }, // 当前页信息 page: { id: null, order: null, order_by: null, item: [] }, videoPage: { id: '', video: {}, player: null } } let transcoding = { UHD: '4K 超清', QHD: '2K 超清', FHD: '1080 全高清', HD: '720 高清', SD: '540 标清', LD: '360 流畅' } // 创建播放器 dp.createDPlayer = function () { let jquery = getJquery() let videoNode = jquery('video') if (videoNode.length <= 0) { return false } if (!dp.dPlayerNode || jquery('#dplayer').length === 0) { dp.dPlayerNode = jquery('<div id=\'dplayer\' style=\'width: 100%; height: 100%;\'></div>')[0] videoNode[0].parentNode.parentNode.replaceWith(dp.dPlayerNode) }else if(dp.videoPage.player){ dp.videoPage.player.destroy(); } let video = dp.videoPage.video //视频信息 let play_info = video.video_preview_play_info //清晰度 let task_list = play_info.live_transcoding_task_list dp.videoPage.id = video.file_id let quality = [], defaultQuality = task_list.length - 1, locQuality = getItem("quality") task_list.forEach(function (item, index) { let name = transcoding[item.template_id] if (!name) { return } if (locQuality === item.template_id) { defaultQuality = index; } quality.push({ templateId: item.template_id, name: name, url: item.url || item.preview_url, type: 'hls' }) }) if (defaultQuality < 0) { defaultQuality = 0 } let fileList = dp.page.item; let fileIndex = fileList.findIndex(function (item, index) { return item.file_id === dp.videoPage.id }) let pic = '' if (fileIndex !== -1) { pic = fileList[fileIndex].thumbnail } let video_json = { quality: quality, defaultQuality: defaultQuality, pic: pic, customType: { hls: function (video, player) { const hls = new Hls() hls.loadSource(video.src) hls.attachMedia(video) } } }; let options = { container: dp.dPlayerNode, video: video_json, autoplay: true, screenshot: true, hotkey: false, airplay: true, volume: 1.0, contextmenu: [] } try { let player = dp.videoPage.player = new DPlayer(options) player.on("quality_end", function () { setItem("quality", player.quality.templateId); }); player.on('error', function (e) { console.log(e) }) dp.dPlayerEvent(); } catch (error) { console.error('播放器创建失败', error) } return true } // 历史视频播放 dp.historyVideo = function () { let $ = getJquery(); let title = '<div style="display:flex; justify-content:center; align-items:center;"><span style="margin-right:2px" data-role="icon"data-render-as="svg"data-icon-type="PDSAddS"class="icon--d-ejA "><svg t="1676171168881" class="icon" viewBox="0 0 1060 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1457" width="16" height="16"><path d="M515.762599 958.870845c246.966761 0 447.17029-200.203529 447.17029-447.170289 0-246.966761-200.203529-447.17029-447.17029-447.17029-246.966761 0-447.17029 200.203529-447.170289 447.17029 0 246.966761 200.203529 447.17029 447.170289 447.170289z m0 63.88147c-282.251292 0-511.051759-228.800468-511.051759-511.051759 0-282.251292 228.800468-511.051759 511.051759-511.05176 282.238815 0 511.051759 228.800468 511.05176 511.05176 0 282.251292-228.800468 511.051759-511.05176 511.051759z m0 0" fill="#515151" p-id="1458"></path><path d="M547.703334 192.293206c0-17.642265-14.29847-31.940735-31.940735-31.940735s-31.940735 14.29847-31.940735 31.940735v343.362901c0 9.195438 3.955161 17.954187 10.85486 24.017935l191.644409 167.688859c13.262891 11.640901 33.462911 10.318355 45.103812-2.93206 11.640901-13.262891 10.318355-33.462911-2.93206-45.103811L547.703334 521.158008V192.293206z m0 0" fill="#515151" p-id="1459"></path></svg></span>最近在看</div>' dp.showTip("加载中") videoHistoryList(function (resp) { if (!resp || !resp.recentUsed) { let cloudList = getItem("historyCloudVideo"); resp['recentUsed'] = {} if (cloudList) { resp['recentUsed']['items'] = cloudList; } else { resp['recentUsed']['items'] = []; } } function handler(item, index) { html += '<div style="width: 100%;">' let name = item.name; let fileId = item.fileId; let compilationId = "" let path = '/drive/' if (item.compilationId) { let i = item.compilationId.indexOf('_'); compilationId = item.compilationId.substring(i + 1, item.compilationId.length); path += 'folder/' + compilationId; } let progressPercentage = item.progressPercentage; let fromSourceDescription = item.fromSourceDescription; html += `<div style="height: 52px; width: 100%;"><div data-index="0"class="tr-wrapper--3qYK2"style=" height: 52px; width: 100%;"><div class="padding-element-horizontal--39l8Q"style="width: 32px;"></div><div class="drop-wrapper--1I5zO"data-drop-target="false"><div data-is-dragging="false"class="drag-wrapper--2Z_J-"draggable="true"><div class="tr--5N-1q tr--3Ypim"data-is-selected="false"data-clickable="true"data-has-checkbox="true"style="cursor: pointer;"><div class="checkbox--3xYhn checkbox-container--TNndw"role="checkbox"aria-checked="false"data-checked="false"data-partial="false"data-disabled="false"data-no-padding="false"><span data-role="icon"data-render-as="svg"data-icon-type="PDSMore"class="ant-dropdown-trigger icon--d-ejA "><svg t="1676180557921"class="icon"viewBox="0 0 1024 1024"version="1.1"xmlns="http://www.w3.org/2000/svg"p-id="3478"width="16"height="16"><path d="M374.6 636.5c4.4 0 8.5-1.2 12.1-3.3l171.7-100c8-3.6 13.6-11.9 13.6-21.5 0-8.8-4.8-16.6-11.9-20.7l-167.8-97.8c-4.3-5-10.7-8.1-17.7-8.1-13.1 0-23.6 10.7-23.6 23.8v1.3l-0.3 0.2 0.4 199.8c-0.1 0.8-0.1 1.6-0.1 2.5 0 13.2 10.6 23.8 23.6 23.8z"fill="#4D4D4D"p-id="3479"></path><path d="M64.7 586.3a32.2 32.1 0 1 0 64.4 0 32.2 32.1 0 1 0-64.4 0Z"fill="#4D4D4D"p-id="3480"></path><path d="M960 398.3c0.1-1.6 0.2-3.2 0.2-4.8 0-35-28.5-63.3-63.6-63.3-11.7 0-22.7 3.2-32.2 8.7l-0.5-0.3-31.5 18.2v-64.7c-0.1-73.1-59.9-133-133.1-133H197.4c-73.1 0-133 59.8-133 133v165.8h0.2c0 17.7 14.4 32.1 32.2 32.1s32.2-14.4 32.2-32.1h0.2V287c0-35.2 28.8-64 64-64h510.2c35.2 0 64 28.8 64 64v448.9c0 35.2-28.8 64-64 64H193.3c-35.2 0-64-28.8-64-64v-21.4c0-17.7-14.4-32.1-32.2-32.1-17.8 0-32.2 14.4-32.2 32.1h-0.4v15.3c0 73.2 59.9 133 133 133h501.9c73.2 0 133-59.8 133-133v-64.1l33.1 19.1 0.1-0.1c9.2 5.1 19.8 8 31 8 35.1 0 63.6-28.4 63.6-63.3 0-1.6-0.1-3.2-0.2-4.8V398.3z m-63.6 205.1c-0.3 7.8-6.9 14.1-15 14.1-2.7 0-5.3-0.7-7.5-2l-41.5-23.7V430.1l40.9-23.2c2.3-1.5 5.1-2.3 8.1-2.3 8.3 0 15 6.6 15 14.6v184.2z"fill="#4D4D4D"p-id="3481"></path></svg></span></div><div class="td--GiK_C td--3QAAr history_video"compilationId="${compilationId}"fileId="${fileId}"data-col-key="name"style="flex: 1 1 0%; min-width: 160px;"><div class="cover--2UinW file-cover--37ssA"data-size="XXS"data-thumbnail="normal"><div class="is-loaded--31jGX thumbnail-wrapper--3fR8n"><div class="thumbnail--2LF21 fill-mode-cover--OFezO size-xxs--2rm_b"><img alt="video"class="fileicon--2Klqk fileicon--vNn4M "draggable="false"src="https://img.alicdn.com/imgextra/i2/O1CN01H7FCkb1P6mPJxDEFa_!!6000000001792-2-tps-80-80.png"/></div></div></div><p class="text-primary--3DHOJ"title="${name}">${name}</p></div><div compilationId="${compilationId}" fileId="${fileId}" class="history_video td--GiK_C td--3QAAr"data-col-key="updated_at"style="width: 200px; flex: 0 0 auto;"><p class="text-secondary--38-Of" >已观看${progressPercentage}%</p></div><div class="td--GiK_C td--3QAAr"data-col-key="size"style="width: 160px; flex: 0 0 auto;"><p class="text-secondary--38-Of"><a href="${path}">${fromSourceDescription}</a></p></div></div></div></div><div class="padding-element-horizontal--39l8Q"style="width: 32px;"></div></div></div>` html += '</div>' } 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 = '<p style="padding-bottom:10px"> 最近观看了 ' + videoLength + '个视频</p>' html += '<div style="height: 410px; overflow-y: auto;">' if (list.length > 0) { html += '<div id="localHistoryList">' html += '<h1 style="padding-bottom:13px">本地历史</h1><p class="text-secondary--38-Of clearHistory" style="padding-bottom:13px"><a>清空本地历史</a></p>' list.forEach(handler) html += '<hr align=center width="100%" color="#1890ff" size=1/>' html += '</div>' } html += '<h1 style="padding-bottom:10px">云端历史</h1>' videoList.forEach(handler) html += '</div>' 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.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]; 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; } let html = `<div class="modal--2-twY"><div class="web--X2m_s container--1KDdZ"><div class="content--2h39N"><div class="header--2Vw8Y"data-layout-sider-open="true"><div class="header-right--15o8Y"><div class="nav-actions--3xj7P"><span class="nav-action--3wGIv nav-next--2clOM"><span data-role="icon"data-render-as="svg"data-icon-type="PDSRightNormal"class="nav-icon--3M-2m icon--d-ejA "style="color:#1890ff"><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSRightNormal"></use></svg></span><span class="nav-text--2o_Eh"><a href="${href}">进入到当前目录</a></span></span></div><div class="separator--2A8C0"></div></div><div class="header-center--3bFO1"><div class="filename--zkxdz"><span class="text--2KGvI">${name}</span></div></div><div style="padding:10px" id="header-close"><span data-role="icon"data-render-as="svg"data-icon-type="PDSClose"class="icon--2RYr- icon--d-ejA "><svg viewBox="0 0 1024 1024"data-spm-anchor-id="0.0.0.i4.54a06c75hUkxKw"><use xlink:href="#PDSClose"></use></svg></span></div></div><div class="previewer--3q5IV"><div class="video-previewer--1vo5c"><div class="video-previewer-container--3N0eI"tabindex="-1"data-fullscreen="false"><div class="video-stage--3LCB4 cursor--w3p8T"><video class="video--26SLZ"preload="metadata"src=""></video></div></div></div></div></div></div></div>` $('#root').append(html) $("#header-close").on('click', function (e) { dp.saveVideoLookTime(function(){ if(dp.videoPage.player){ dp.videoPage.player.destroy() } dp.videoPage ={ id: '', video: {}, player: null }; }); $('.modal--2-twY').remove() }) // 获取文件信息 dp.videoPage.id = id dp.getVideoPreviewPlayInfo(function (response) { dp.playInfo({ response: response }); }) } dp.showTip = function (msg, timeout) { let $ = getJquery(); dp.hideTip(); let element = $(".aDrive div"); let html = '<div class="aDrive-notice"><div class="aDrive-notice-content"><div class="aDrive-custom-content aDrive-loading"><div></div><span><div class="content-wrapper--B7mAG" data-desc="false" style="margin-left: 20px; padding-right: 20px;"><div class="title-wrapper--3bQQ2">' + msg + '<div class="desc-wrapper--218x0"></div></div></div></span></div></div></div>' if (element.length) { element.append(html); } else { $(document.body).append('<div><div class="aDrive"><div>' + html + '</div></div></div>'); } setTimeout(function () { dp.hideTip() }, timeout || 5000); }; dp.hideTip = function () { let $ = getJquery(); var notice = $(".aDrive-notice"); if (notice.length && "function" == typeof notice.remove) { notice.remove() } else if ("function" == typeof notice.removeNode) { notice.removeNode(!0) } }; var initCloesClick = false; // 播放器事件绑定 dp.dPlayerEvent = function () { var rightCount = 0; var rightInterval = null; var logKey = false; var playbackRate = null; if(!initCloesClick){ getJquery()(".header-left--3QcN-").on('click', function () { dp.saveVideoLookTime(function(){ if(dp.videoPage.player){ dp.videoPage.player.destroy() initCloesClick =false; } dp.videoPage ={ id: '', video: {}, player: null }; if(dp.videoPage.session){ clearTimeout(dp.videoPage.session) } }); }) dp.videoPage.session = setTimeout(function(){ renew_session() },300000) initCloesClick =true; } dp.selectEpisode() dp.getVideoLookTime() document.onkeydown = function (event) { let player = dp.videoPage.player //右 if (event.code === 'ArrowRight') { rightCount += 1; if (!playbackRate) { playbackRate = player.video.playbackRate } if (!rightInterval) { rightInterval = setInterval(function () { if (rightCount > 100) { rightCount = 2; } if (rightCount > 1 && !logKey) { dp.doubleSpeed() logKey = true; } }, 100) } } else if (event.code === 'ArrowLeft') { //左 player.seek(player.video.currentTime - 5); } else if (event.code === 'ArrowUp') { //上 player.volume(player.volume() + .01); } else if (event.code === 'ArrowDown') { //下 player.volume(player.volume() - .01); } else if (event.code === 'Space') { //空格 player.toggle(); } else if (event.code === 'Enter') { //回车 player.fullScreen.toggle(); } } document.onkeyup = function (event) { let player = dp.videoPage.player if (event.code === 'ArrowRight') { if (rightCount === 1) { player.seek(player.video.currentTime + 5); } logKey = false; if (rightInterval) { window.clearInterval(rightInterval) } rightInterval = null; rightCount = 0; if (playbackRate) { player.speed(playbackRate) player.notice('恢复正常') playbackRate = null } } } } // 长按双倍速 dp.doubleSpeed = function () { let player = dp.videoPage.player player.notice('倍速播放 x2') player.speed(2) } //获取上次观看时长 dp.getVideoLookTime = function () { let id = dp.videoPage.id; if (id) { getVideoFile(function (response) { if (response && response.user_meta) { let player = dp.videoPage.player let userMeta = JSON.parse(response.user_meta) player.seek(userMeta.play_cursor); player.play(); } }) } } // 更新保存的时长 dp.saveVideoLookTime = function (callback) { if (dp.videoPage.id) { let videoPage = dp.videoPage; let player = videoPage.player; let progress = parseInt((player.video.currentTime / player.video.duration) * 100) let vId = videoPage.id; updateVideoTime(function () { console.log("保存成功") let videoInfo = { "category": "video", "name": videoPage.name, "progressPercentage": progress, "fileId": vId, "fromSourceDescription": videoPage.folderName, "compilationId": "_" + videoPage.compilationId, } let list = getItem("historyVideo"); if (list == null) { list = [] } let newList = [videoInfo]; list.forEach(function (item, index) { if (item.fileId !== vId && newList.length <= 3) { newList.push(item); } }) setItem("historyVideo", newList); callback && callback() }); } } // 选集 dp.selectEpisode = function () { let jq = getJquery() if (jq('.dplayer-icons-right #btn-select-episode').length) return // if (document.querySelectorAll('.dplayer-menu-item').length < 4) return let fileList = dp.page.item , videoList = fileList.filter(function (item, index) { return item.category === 'video' }) , fileIndex = videoList.findIndex(function (item, index) { return item.file_id === dp.videoPage.id }) if (!(fileIndex > -1 && videoList.length > 1)) return var elevideo = '<section class="scroll-container--Ho4ra""><div class="scroll-wrapper--zw1q2"><ul class="drawer-list--JYzyI">' videoList.forEach(function (item, index) { let t; let created = item.created_at.split("T")[0]; if (fileIndex === index) { t = getTime(dp.videoPage.video.video_preview_play_info.meta.duration); elevideo += `<li class="drawer-item--2cNtQ "data-is-current="true"><div class="thumbnail--1bhNX"style="background-image: linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.3) 100%), url("${item.thumbnail}");"></div><div class="meta--3-qtu"><p class="title--2vewu"title="${item.name}"><span data-role="icon"data-render-as="svg"data-icon-type="PDSPlayCircle"class="icon--2AFV7 icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSPlayCircle"></use></svg></span><span class="filename--3hcxw">${item.name}</span></p><p class="duration--3hbgi">${t}</p><p class="time--2_PJ8">${created}</p></div></li>` } else { let d = item.video_media_metadata.duration; if (d) { t = getTime(d); } else { t = '时长无法获取' } elevideo += `<li class="drawer-item--2cNtQ "data-is-current="false"><div class="thumbnail--1bhNX"style="background-image: linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.3) 100%), url("${item.thumbnail}");"></div><div class="meta--3-qtu"><p class="title--2vewu"title="${item.name}"><span class="filename--3hcxw">${item.name}</span></p><p class="duration--3hbgi">${t}</p><p class="time--2_PJ8">${created}</p></div></li>` } }) elevideo += '</ul></div></section>'; let svg = '<svg t="1674881901474" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8038" width="200" height="200"><path d="M765.952 124.928l0 81.92 0 129.024 0 156.672 0 159.744q0 76.8 0.512 141.312t0.512 100.352q0 24.576-11.776 40.96t-29.696 22.016-39.424 0-39.936-24.064q-37.888-38.912-81.92-81.408t-90.624-85.504-94.208-86.016-91.648-82.944q-19.456-17.408-29.184-43.008t-8.704-53.248 11.776-54.272 32.256-45.056q39.936-34.816 79.36-70.144t80.896-72.704 87.04-78.336 96.768-87.04q22.528-20.48 45.568-27.136t41.472-2.048 29.696 20.48 11.264 40.448z" p-id="8039"></path></svg>' let disable = '<svg t="1674882113958" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14669" width="200" height="200"><path d="M512.631648 1023.999376a511.992507 511.992507 0 1 1 511.368127-511.368127 511.992507 511.992507 0 0 1-511.368127 511.368127zM512.631648 63.076853a449.554397 449.554397 0 1 0 448.930016 449.554396A450.178778 450.178778 0 0 0 512.631648 63.076853z" fill="#0F3567" p-id="14670"></path><path d="M138.877118 830.19148L818.328638 150.677522l44.143744 44.143744L183.020862 874.335224z" fill="#0F3567" p-id="14671"></path></svg>'; let html = ''; if (videoList[0] !== videoList[fileIndex]) { html += `<button class="dplayer-icon dplayer-play-icon prev-icon" title="${videoList[fileIndex - 1].name}">` + svg + '</button>' } else { html += '<button class="dplayer-icon dplayer-play-icon prev-icon" title="没上集了">' + disable + '</button>' } html += '<button id="btn-select-episode" class="dplayer-icon dplayer-quality-icon" title="选集">选集</button> <div class="playlist-content" style="max-height: 330px;width: 100%;height: auto;box-sizing: border-box;overflow: hidden;position: absolute;left: 0;transition: all .38s ease-in-out;bottom: 52px;overflow-y: auto;transform: scale(0);z-index: 2;"><div class="list" style="background-color: rgba(0, 0, 0, 0.85);height: 100%;">' + elevideo + '</div></div>' if (videoList[videoList.length - 1] !== videoList[fileIndex]) { html += `<button class="dplayer-icon dplayer-play-icon next-icon" style="transform: rotate(-180deg)" title="${videoList[fileIndex + 1].name}">` + svg + '</button>' } else { html += '<button class="dplayer-icon dplayer-play-icon next-icon" title="没下集了">' + disable + '</button>' } jq('.dplayer-icons-right').prepend(html) jq('#btn-select-episode').on('click', function () { var eleEpisode = jq('.playlist-content') if (eleEpisode.css('transform').match(/\d+/) > 0) { eleEpisode.css('transform', 'scale(0)') } else { eleEpisode.css('transform', 'scale(1)') jq('.dplayer-mask').addClass('dplayer-mask-show') jq('.dplayer-icons-right .playlist-content').scrollTop((fileIndex + 1) * jq('.dplayer-icons-right li')[0].offsetHeight - jq('.dplayer-icons-right .playlist-content').height() / 2) } }) jq('.dplayer-mask').on('click', function () { var eleEpisode = jq('.playlist-content') if (eleEpisode.css('transform').match(/\d+/) > 0) { eleEpisode.css('transform', 'scale(0)') jq(this).removeClass('dplayer-mask-show') } }) jq('.playlist-content li').on('click', function () { var $this = jq(this) if ($this.attr('data-is-current') === 'true') { return } jq('.dplayer-mask').removeClass('dplayer-mask-show') let file = videoList[$this.index()] dp.playByFile(file) }) jq('.prev-icon').on('click', function () { var file = videoList[fileIndex - 1] file ? dp.playByFile(file) : showError('没有上一集了') }) jq('.next-icon').on('click', function () { var file = videoList[fileIndex + 1] file ? dp.playByFile(file) : showError('没有下一集了') }) } // 通过视频文件来播放该视频 dp.playByFile = function (file) { dp.saveVideoLookTime(function(){ let player = dp.videoPage.player try { player.pause() document.removeEventListener('click', player.docClickFun, true) player.container.removeEventListener('click', player.containerClickFun, true) player.fullScreen && player.fullScreen.destroy && player.fullScreen.destroy() player.hotkey && player.hotkey.destroy && player.hotkey.destroy() player.contextmenu && player.contextmenu.destroy && player.contextmenu.destroy() player.controller && player.controller.destroy && player.controller.destroy() player.timer && player.timer.destroy && player.timer.destroy() } catch (error) { console.error(error) } dp.videoPage.id = file.file_id dp.videoPage.name = file.name; //文件名 dp.videoPage.folderName = dp.page.folderName; // 文件夹Id dp.videoPage.compilationId = file.parent_file_id; dp.getVideoPreviewPlayInfo(function (response) { dp.playInfo({ response: response }); getJquery()('.header-file-name--CN_fq, .text--2KGvI').text(file.name) }) }); } dp.getVideoPreviewPlayInfo = function (callback) { refresh_token(function (result) { if (result) { if (location.href.indexOf('aliyundrive.com/drive') > 0) { videoPreviewPlayInfo(callback) } else { share_token(function (result) { if (result) { shareLinkVideoPlayInfo(callback) } else { callback && callback('') } }) } } else { callback && callback('') } }) } dp.playerReady = function (callback) { let player = dp.videoPage.player if (player.video.duration > 0 || player.video.readyState > 2) { player.isReady = true callback && callback() } else if (player.isReady) { callback && callback() } else { player.video.ondurationchange = function () { player.video.ondurationchange = null player.isReady = true callback && callback() } } } // 播放器 dp.playInfo = function (res) { let list = res.response.video_preview_play_info.live_transcoding_task_list dp.videoPage.id = res.response.file_id let info = dp.findByFileId(dp.videoPage.id); if (info) { dp.videoPage.name = info.name; //文件名 dp.videoPage.folderName = dp.page.folderName; // 文件夹Id dp.videoPage.compilationId = info.parent_file_id; } if (list[0].hasOwnProperty("preview_url")) { dp.getVideoPreviewPlayInfo(function (response) { if (response === '') { showError("播放信息获取失败,请刷新重试", 10000); return; } dp.videoPage.video = response; initPre() }) } else { dp.videoPage.video = res.response; initPre() } } // 通过id来查找 已加载的文件信息 dp.findByFileId = function (id) { let fileIndex = dp.page.item.findIndex(function (item, index) { return item.file_id === id }) if (!fileIndex) { return null; } return dp.page.item[fileIndex]; } dp.fileGet = function (response) { console.log(response) } //当文件较多时,需要合并 dp.fileList = function (res) { let data = res.data let response = res.response // 数据量过大,进行数组合并 if (dp.page.id === data.parent_file_id && dp.page.order === data.order_direction && dp.page.order_by === data.order_by) { dp.page.item = dp.page.item.concat(response.items) } else { dp.page.id = data.parent_file_id dp.page.order = data.order_direction dp.page.order_by = data.order_by dp.page.item = response.items } let folderName = getJquery()('.breadcrumb-item-link--M-p4b:last').text(); dp.page.folderName = folderName; showSuccess(`已加载${dp.page.item.length}个文件`) if (dp.isHome()) { dp.initMenuButton() } else { dp.initShareButton() } } dp.getPlayNode = function (e) { let fileList = dp.page.item , parent_file_id = fileList[0].parent_file_id , videoMemory = getItem('video_memory') if (videoMemory && videoMemory[parent_file_id]) { return videoMemory[parent_file_id][e] } return '' } dp.isHome = function () { return location.href.indexOf('com/drive') > 0 } dp.isExpires = function (item) { let time = Date.parse(item.expire_time) - Date.now() return time > 0 && time < 1000 * Number(item.expires_in) } dp.setExpires = function (item, time) { item.expire_time = new Date(Date.now() + time).toISOString() item.expires_in = void 0 === time ? 600 : time return item } dp.showDiv = function (title, _html) { function format(s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }); } let html = '<div class="ant-modal-root ant-modal-Link"><div class="ant-modal-mask"></div><div tabindex="-1" class="ant-modal-wrap" role="dialog"><div role="document" class="ant-modal modal-wrapper--2yJKO" style="width: 666px;"><div class="ant-modal-content"><div class="ant-modal-header"><div class="ant-modal-title" id="rcDialogTitle1">{title}</div></div><div class="ant-modal-body"><div class="icon-wrapper--3dbbo"><span data-role="icon" data-render-as="svg" data-icon-type="PDSClose" class="close-icon--33bP0 icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSClose"></use></svg></span></div>' html = format(html, { title: title }) html += _html; html += '</div></div></div></div></div></div>' getJquery()('body').append(html) getJquery()('.ant-modal-Link .icon-wrapper--3dbbo').one('click', function () { getJquery()('.ant-modal-Link').remove() }) getJquery()('.ant-modal-Link .ant-modal-wrap').on('click', function (event) { if (getJquery()(event.target).closest('.ant-modal-content').length === 0) { getJquery()('.ant-modal-Link').remove() } }) } dp.showBox = function (fileList) { if (!fileList) { fileList = dp.selectedFileList() if (fileList.length === 0) { return } } let rowStyle = 'margin:10px 0px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;' let html = '<div class="ant-modal-root ant-modal-Link"><div class="ant-modal-mask"></div><div tabindex="-1" class="ant-modal-wrap" role="dialog"><div role="document" class="ant-modal modal-wrapper--2yJKO" style="width: 666px;"><div class="ant-modal-content"><div class="ant-modal-header"><div class="ant-modal-title" id="rcDialogTitle1">文件下载</div></div><div class="ant-modal-body"><div class="icon-wrapper--3dbbo"><span data-role="icon" data-render-as="svg" data-icon-type="PDSClose" class="close-icon--33bP0 icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSClose"></use></svg></span></div>' html += '<p> 共加载了 ' + fileList.length + '个文件</p>' html += '<div class="item-list" style="padding: 20px; height: 410px; overflow-y: auto;">' fileList.forEach(function (item, index) { html += '<p>' + (++index) + ':' + item.name + '</p>' if (item.type === 'file') { html += '<p style="' + rowStyle + '"><a title="' + item.download_url + '" href="' + item.download_url + '" style="color: blue;">' + item.download_url + '</a></p>' } else if (item.type === 'folder') { html += '<p style="' + rowStyle + '"><font color="green">  请进入文件夹下载</font></p>' } }) html += '</div></div><div class="ant-modal-footer"><div class="footer--1r-ur"><div class="buttons--nBPeo">' html += '<button class="button--2Aa4u primary--3AJe5 small---B8mi appreciation">👍 点个赞</button>' html += '<button class="button--2Aa4u primary--3AJe5 small---B8mi aria2-download">Aria2 推送</button>'; html += '<button class="button--2Aa4u primary--3AJe5 aria2-set" style="margin-left: 0;width: auto;border: 0 solid transparent;">⚙️</button>'; html += '</div></div></div></div></div></div></div>' getJquery()('body').append(html) getJquery()('.ant-modal-Link .icon-wrapper--3dbbo').one('click', function () { getJquery()('.ant-modal-Link').remove() }) getJquery()('.ant-modal-Link .ant-modal-wrap').on('click', function (event) { if (getJquery()(event.target).closest('.ant-modal-content').length === 0) { getJquery()('.ant-modal-Link').remove() } }) getJquery()('.ant-modal-Link .appreciation').on('click', function () { window.open('http://greasyfork.icu/zh-CN/scripts/458626', '_blank') }) getJquery()('.ant-modal-Link .aria2-set').on('click', function () { dp.showAria2Set(); }) getJquery()('.ant-modal-Link .aria2-download').on('click', function () { let fileAria2List = fileList.filter(function (item) { return item.type === "file"; }); if (fileAria2List.length === 0) { showError('当前未检索到文件(非文件夹)') return } dp.aria2Push(getJquery()(this), fileAria2List); }) } dp.aria2Push = function (btn, fileAria2List) { let $ = getJquery(); let link = getItem("aria2-link"); let path = getItem("aria2-path"); let token = getItem("aria2-token") || ""; if (!link || !path) { showError('请点击右边齿轮按钮,设置好Aria2再来推送吧') return; } let dir = $(".breadcrumb--2FqFQ[data-calc=true] > .breadcrumb-item--tV9dn > .breadcrumb-item-link--M-p4b"); let folderName = "\/阿里云盘"; for (let i = 0; i < dir.length; i++) { folderName += "\/" + dir[i].innerText } let sendDownLoad = []; fileAria2List.forEach(function (item, index) { sendDownLoad.push({ id: "", jsonrpc: "2.0", method: "aria2.addUri", params: [ "token:" + token, [item.download_url], { out: item.name, dir: path + folderName, referer: "https://www.aliyundrive.com/", "user-agent": navigator.userAgent } ] }); }); let text = btn.text(); btn.text("正在推送"); $.ajax({ type: "POST", url: link, data: JSON.stringify(sendDownLoad), crossDomain: true, processData: false, contentType: "application/json", success: function (result) { showSuccess("Aria2推送成功") btn.text(text); }, error: function (error) { showError("Aria2 推送失败,请检查配置,或刷新后重试") btn.text(text); } }); } dp.showAria2Set = function () { let $ = getJquery(); $('body').append(showAria2SetHtml); let close = function () { $("#aria2-set-box").remove(); } let link = $("#aria2-link"); let path = $("#aria2-path"); let token = $("#aria2-token"); link.val(getItem("aria2-link") || ""); path.val(getItem("aria2-path") || ""); token.val(getItem("aria2-token") || ""); $("#aria2-set-icon").one("click", close); $("#aria2-set-save").one("click", function () { setItem('aria2-link', link.val()) setItem('aria2-path', path.val().replace(/\/$/, "")) setItem('aria2-token', token.val()) close(); }); } dp.showDownloadHomePage = function () { let max = dp.page.item.length dp.page.item.forEach(function (item, index) { if (item.download_url && !dp.isExpires(item)) { item.download_url = '' } if (item.download_url || item.type === 'folder') { max-- if (max === 0) { dp.showBox() } } else { getDownloadUrl(item.file_id, item.drive_id, function (download_url) { max-- if (download_url) { dp.setExpires(item, 1600) item.download_url = download_url } if (max === 0) { dp.showBox() } }) } }) } // 初始化菜单 dp.initMenuButton = function () { let jq = getJquery() if (jq('.button-download-aliyun').length !== 0) { return } if (jq('#root header').length !== 0) { var html = '' html += '<div style="margin:1px 8px;"></div><button class="button--2Aa4u primary--3AJe5 small---B8mi history-video"><span style="margin-right:2px" data-role="icon"data-render-as="svg"data-icon-type="PDSAddS"class="icon--d-ejA "><svg t="1676170067530"class="icon"viewBox="0 0 1024 1024"version="1.1"xmlns="http://www.w3.org/2000/svg"p-id="2764"width="200"height="200"><path d="M512 1024C229.248 1024 0 794.752 0 512S229.248 0 512 0s512 229.248 512 512-229.248 512-512 512z m42.666667-486.869333V298.538667C554.666667 275.328 535.552 256 512 256c-23.722667 0-42.666667 19.029333-42.666667 42.538667v256.256a41.984 41.984 0 0 0 12.202667 29.866666l121.258667 121.258667a42.368 42.368 0 0 0 60.032-0.298667 42.666667 42.666667 0 0 0 0.298666-60.032L554.666667 537.130667z"fill="#ffffff"p-id="2765"></path></svg></span>最近在看</button>' html += '<div style="margin:1px 8px;"></div><button class="button--2Aa4u primary--3AJe5 small---B8mi button-download-aliyun">显示链接</button>' jq('#root header:eq(0)').append(html) jq('.button-download-aliyun').on('click', dp.showDownloadHomePage) $('.history-video').on('click', dp.historyVideo) } else { setTimeout(dp.initMenuButton, 1000) } } dp.selectedFileList = function () { let jq = getJquery() let selectedFileList = [], fileList = dp.page.item if (fileList.length === 0) { console.error('获取文件列表失败') return [] } let node = '' if (jq('.tbody--3Y4Fn .tr--5N-1q.tr--3Ypim').length) { node = jq('.tbody--3Y4Fn .tr--5N-1q.tr--3Ypim') } else if (jq('.outer-wrapper--25yYA').length) { node = jq('.outer-wrapper--25yYA') } node.each(function (index) { var $this = jq(this) if ($this.attr('data-is-selected') === 'true') { let data_index = $this.closest('[data-index]').attr('data-index') data_index && selectedFileList.push(fileList[data_index]) } }) return selectedFileList.length ? selectedFileList : fileList } // 分享按钮显示 dp.initShareButton = function () { let jq = getJquery() if (jq('.button-download-aliyun').length !== 0) { return } if (jq('#root [class^=banner] [class^=right]').length !== 0) { var html = '' html += '<div style="margin:1px 7px;"></div><button class="button--2Aa4u primary--3AJe5 small---B8mi button-download-aliyun">显示链接</button>' jq('#root [class^=banner] [class^=right]').prepend(html) jq('.button-download-aliyun').on('click', dp.showDownloadSharePage) } else { setTimeout(dp.initShareButton, 500) } } dp.showDownloadSharePage = function () { if (document.querySelector('[class^=login]')) { document.querySelector('[class^=login]').click() return } let fileList = dp.selectedFileList() if (fileList.length === 0) { return } dp.getShareLinkDownloadUrlAll(fileList, function (fileList) { dp.showBox(fileList) }) } dp.shareLinkDownloadUrl = function (file_id, share_id, callback) { var token = getToken() getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/file/get_share_link_download_url', data: JSON.stringify({ //expire_sec: 600, file_id: file_id, share_id: share_id }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=utf-8', 'x-share-token': getItem('shareToken').share_token }, async: true, success: function (response) { if (response.download_url) { callback && callback(response.download_url) } else { callback && callback('') } }, error: function (error) { let errorCode = error.responseJSON ? error.responseJSON.code : '' if ('InvalidParameterNotMatch.ShareId' === errorCode) { showError('错误:参数不匹配,请刷新', 10000) } callback && callback('') } }) } dp.getShareLinkDownloadUrlAll = function (fileList, callback) { let max = fileList.length fileList.forEach(function (item, index) { if (item.download_url && !dp.isExpires(item)) { item.download_url = '' } if (item.download_url || item.type === 'folder') { max-- if (max === 0) { callback && callback(fileList) } } else { dp.getShareLinkDownloadUrl(item.file_id, item.share_id, function (download_url) { if (download_url) { dp.setExpires(item, 1600) item.download_url = download_url } max-- if (max === 0) { callback && callback(fileList) } }) } }) } dp.getShareLinkDownloadUrl = function (file_id, share_id, callback) { refresh_token(function (result) { if (result) { share_token(function (result) { if (result) { dp.shareLinkDownloadUrl(file_id, share_id, callback) } else { callback && callback('') } }) } else { callback && callback('') } }) } // --------- - ------------ end -------------------------- // --------------- start ----------------------------------- class XMLHttp { request = function (param) { } response = function (param) { } } let http = new XMLHttp() http.request = function (req) { if(!req.url.endsWith('users/device/renew_session')){ if(req.headers['x-signature']){ dp.user["x-signature"]=req.headers['x-signature'] } if(req.headers['x-device-id']){ dp.user["x-device-id"]=req.headers['x-device-id'] } } // 后缀修改 if (req.url.endsWith('file/update')) { let reqbody = JSON.parse(req.data[0]); let name = reqbody.name; //原本的后缀 let i = name.lastIndexOf('.'); if (i === -1) { return; } let newName = name.substring(0, i); if (newName.lastIndexOf('.') !== -1) { reqbody.name = newName; req.data[0] = JSON.stringify(reqbody) } } } let $mediaNum = 0; http.response = function (res) { let config = res.config isUrlExpires(config.url) if (config.status === 404 && config.url.indexOf('/file/get_video_preview_play_info') > 0) { return; } else if (config.status === 403 && isUrlExpires(config.url)) { var mediaNum = (config.url.match(/media-(\d+)\.ts/) || [])[1] || 0; // 避免死循环 if (mediaNum > 0 && $mediaNum != mediaNum) { $mediaNum = mediaNum; dp.getVideoPreviewPlayInfo(); } return } else if (config.status !== 200) { return } if (getJquery()('.ant-modal-mask').length > 0) { return } let response = res.response, url = config.url try { config.data = JSON.parse(config.data) } catch (error) { config.data = {} } response = { response: response, data: config.data } if (url.endsWith('/file/get')) { dp.fileGet(response) } else if (url.indexOf('/file/list') > 0 || url.indexOf('/file/search') > 0) { dp.fileList(response) } else if (url.indexOf('/file/get_video_preview_play_info') > 0) { dp.playInfo(response) } } // 初始化 拦截XMLHttpRequest function initXMLHttpRequest() { let open = XMLHttpRequest.prototype.open XMLHttpRequest.prototype.open = function (...args) { let send = this.send let _this = this let post_data = [] this.send = function (...data) { post_data = data let dataBody = { url: args[1], method: args[0], headers:{}, data: data } if(_this._header_){ dataBody.headers=_this._header_ } // 请求前拦截 http.request(dataBody) return send.apply(_this, data) } this.addEventListener('readystatechange', function () { if (this.readyState === 4) { let config = { url: args[1], status: this.status, method: args[0], data: post_data } // 请求后拦截 let res = this.response if (typeof res == 'string') { try { res = JSON.parse(this.response) } catch (e) { console.log("解析出问题了, ", e) } } http.response({ config, response: res }) } }, false) return open.apply(this, args) } } let getDownloadUrl = function (file_id, drive_id, callback) { let token = getToken() var that = getDownloadUrl getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/file/get_download_url', data: JSON.stringify({ expire_sec: 14400, drive_id: drive_id, file_id: file_id }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=utf-8', 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { if (response.url) { callback && callback(response.url, response) } else { console.error('获取下载链接失败', response) callback && callback('') } }, error: function (error) { let errorCode = error.responseJSON ? error.responseJSON.code : '' if (errorCode === 'TooManyRequests') { setTimeout(function () { that(file_id, drive_id, callback) }, 500) } else { console.error('获取下载链接 错误', error) callback && callback('') } } }) } let getHomeDownloadUrl = function (fileId, driveId, callback) { let token = getToken() if (token == null) { refresh_token(function (res) { getHomeDownloadUrl() }) } else { getDownloadUrl(fileId, driveId, callback) } } let getToken = function () { let token = getLocalforage().getItem(`token`) if (token != null) { token = JSON.parse(token) if (dp.isExpires(token)) { return token } return null } return token } let getItem = function (n) { let item = getLocalforage().getItem(n) if (!item) { return null } try { return JSON.parse(item) } catch (e) { return item; } } let setItem = function (k, v) { localStorage.setItem(k, v instanceof Object ? JSON.stringify(v) : v) } let videoPreviewPlayInfo = function (callback) { let token = getToken() || {}, file_id = dp.videoPage.id getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/file/get_video_preview_play_info', data: JSON.stringify({ category: 'live_transcoding', drive_id: token.default_drive_id, file_id: file_id, template_id: '', get_subtitle_info: !0 }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=UTF-8', 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { callback && callback(response) }, error: function (error) { callback && callback('') } }) } let shareLinkVideoPlayInfo = function (callback) { var token = getToken() || {}, share_id = shareId(), file_id = dp.videoPage.id getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info', data: JSON.stringify({ category: 'live_transcoding', file_id: file_id, get_preview_url: true, share_id: share_id, template_id: '', get_subtitle_info: !0 }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=UTF-8', 'x-share-token': getItem('shareToken').share_token, 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { callback && callback(response) }, error: function (error) { callback && callback('') } }) } let getVideoFile = function (callback) { let token = getToken() || {} getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/file/get', data: JSON.stringify({ drive_id: token.default_drive_id, file_id: dp.videoPage.id }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=UTF-8', 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { callback && callback(response) }, error: function (error) { callback && callback('') } }) } let updateVideoTime = function (callback) { let token = getToken() || {} let player = dp.videoPage.player; getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/adrive/v2/video/update', data: JSON.stringify({ drive_id: token.default_drive_id, duration: player.video.duration, file_id: dp.videoPage.id, play_cursor: player.video.currentTime }), headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=UTF-8', 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { callback && callback(response) }, error: function (error) { callback && callback('') } }) } let videoHistoryList = function (callback) { let token = getToken() || {} getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/apps/v1/users/home/widgets', data: '{"context":{"recentUsed":{"limit":20},"recentSaved":{"limit":1}}}', headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), 'content-type': 'application/json;charset=UTF-8', 'x-signature': dp.user["x-signature"], 'x-device-id': dp.user["x-device-id"] }, async: true, success: function (response) { callback && callback(response) }, error: function (error) { callback && callback('') } }) } let shareId = function () { var url = location.href var match = url.match(/aliyundrive\.com\/s\/([a-zA-Z\d]+)/) return match ? match[1] : null } let renew_session= function(callback){ let token = getToken() || {} getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/users/v1/users/device/renew_session', data: '{}', headers: { 'authorization': ''.concat(token.token_type || '', ' ').concat(token.access_token || ''), '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.result) { callback && callback(response) } else { callback && callback('') } }, error: function () { callback && callback('') } }) } let share_token = function (callback) { var shareToken = getItem('shareToken') var share = shareId if (!shareToken) { showError('请登陆后刷新此页面重试!', 1e4) return callback && callback('') } if (dp.isExpires(shareToken)) { return callback && callback(shareToken) } getJquery().ajax({ type: 'post', url: 'https://api.aliyundrive.com/v2/share_link/get_share_token', data: JSON.stringify({ share_id: share(), share_pwd: '' }), 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.share_token) { localStorage.setItem('shareToken', response instanceof Object ? JSON.stringify(response) : response) callback && callback(response) } else { callback && callback('') } }, error: function (error) { if (error.responseJSON.code === 'InvalidResource.SharePwd') { showError('请刷新并重新填写提取码', 1e4) } callback && callback('') } }) } let hideShow = function () { let t = getJquery()('.aDrive-notice') t.length && 'function' == typeof t.remove ? t.remove() : 'function' == typeof t.removeNode && t.removeNode(true) } let showSuccess = function (msg, timeout) { let jq = getJquery() hideShow() let element = jq('.aDrive div') let elementhtml = '<div class="aDrive-notice"><div class="aDrive-notice-content"><div class="aDrive-custom-content aDrive-success"><span data-role="icon" data-render-as="svg" data-icon-type="PDSCheckmarkCircleFill" class="success-icon--2Zvcy icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSCheckmarkCircleFill"></use></svg></span><span><div class="content-wrapper--B7mAG" data-desc="false" style="margin-left: 44px; padding-right: 20px;"><div class="title-wrapper--3bQQ2">' + msg + '<div class="desc-wrapper--218x0"></div></div></div></span></div></div>' if (element.length) { element.append(elementhtml) } else { jq(document.body).append('<div><div class="aDrive"><div>' + elementhtml + '</div></div></div>') } var hide = hideShow setTimeout(function () { hide() }, timeout || 3000) } let showError = function (msg, timeout) { let jq = getJquery() hideShow() var element = jq('.aDrive div') var elementhtml = '<div class="aDrive-notice"><div class="aDrive-notice-content"><div class="aDrive-custom-content aDrive-error"><span data-role="icon" data-render-as="svg" data-icon-type="PDSCloseCircleFill" class="error-icon--1Ov4I icon--d-ejA "><svg viewBox="0 0 1024 1024"><use xlink:href="#PDSCloseCircleFill"></use></svg></span><span><div class="content-wrapper--B7mAG" data-desc="false" style="margin-left: 44px; padding-right: 20px;"><div class="title-wrapper--3bQQ2">' + msg + '<div class="desc-wrapper--218x0"></div></div></div></span></div></div></div>' if (element.length) { element.append(elementhtml) } else { jq(document.body).append('<div><div class="aDrive"><div>' + elementhtml + '</div></div></div>') } 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('') } }) } 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) } } initXMLHttpRequest() console.log('你好,罗根') })()