// ==UserScript== // @name 天翼云盘助手 // @description 天翼云盘跳过客户端直接下载文件,支持文件夹打包下载。 // @version 1.0.9 // @namespace TyCloud_Tools // @icon https://z3.ax1x.com/2021/05/31/2m1BTA.png // @author 邓小明 // @include *//cloud.189.cn/t/* // @include *//cloud.189.cn/main.* // @include *//cloud.189.cn/photo.* // @grant unsafeWindow // @downloadURL none // ==/UserScript== (function() { 'use strict'; addLoadEvent(init); })(); function init() { var append_html = ` `; $('body').append(append_html); var url = unsafeWindow.location.href; if (url.indexOf('cloud.189.cn/main') > 0 || url.indexOf('cloud.189.cn/photo') > 0) { /* 个人云盘 */ if ($('#J_Create').length) { $('#J_Create').after('显示链接'); $('.btn-show-link').on('click', mainShowDownload); } else if ($('.JC_Refresh').length) { $('.JC_Refresh').after('显示链接'); $('.btn-show-link').on('click', photoShowDownload); } else {} } else if (url.indexOf('cloud.189.cn/t') > 0) { /* 分享页 */ $('.breadcrumb').append('
  • 勾选文件显示下载链接
  • '); if ('undefined' != typeof _shareId) { if ($('#J_SaveAs').length) { $('#J_SaveAs').after('显示链接'); $('.btn-show-link').on('click', shareShowDownload); } else if ($('.JC_Refresh').length) { $('.JC_Refresh').after('显示链接'); } else {} } else { /* 恢复单文件下载按钮 */ for (var t = document.getElementsByTagName('a'), e = 0; e < t.length; e++) { 'btn btn-download download-link disable' === t[e].getAttribute('class') && t[e].setAttribute('class', 'btn btn-download download-link'); } } } else {} } function getSelectedFileList() { var mainView = null, fileList = []; if (unsafeWindow.fileId) { fileList = [{ attributes: unsafeWindow }]; } else if (unsafeWindow._shareId) { mainView = unsafeWindow.appRouter.mainView; if (mainView instanceof Object && mainView.fileList) { fileList = mainView.fileList; if (fileList.selected().length) { fileList = fileList.selected(); } } //obj.processFileList(fileList, unsafeWindow._shareId); } else if (unsafeWindow.mainView) { mainView = unsafeWindow.mainView; if (mainView.fileListTabObj && mainView.fileListTabObj[mainView.options.fileId]) { fileList = mainView.fileListTabObj[mainView.options.fileId].fileList.selected(); } else if (mainView.getSelectedModels) { fileList = mainView.getSelectedModels(); } } var selectedFileList = []; fileList.forEach(function(item) { if (item.attributes.fileId > 0) { selectedFileList.push(item); } }); return selectedFileList; } function getMetadata() { var url = unsafeWindow.location.href; var match = url.match(/cloud\.189\.cn\/t\/([0-9a-z]+)/i); var shortCode = match ? match[1] : null; var result; $.ajax({ type: 'get', url: '//cloud.189.cn/v2/listShareDirByShareIdAndFileId.action', data: { shortCode: shortCode, accessCode: getCookie('shareId_' + _shareId), verifyCode: _verifyCode, orderBy: 1, order: 'ASC', pageNum: 1, pageSize: 60 }, dateType: 'json', async: false, success: function(data) { result = data; }, error: function() {} }); return result; } /* 文件夹打包下载链接 */ function buildFolderDownUrl(fileId) { var sessionKey = getCookie('validCodeTimestamp'); var result = 'https://cloud.189.cn/downloadMultiFiles.action?sessionKey=' + sessionKey + '&fileIdS=' + fileId + '&downloadType=3&shareId=' + _shareId; return result; } /* 文件下载链接 */ function getFileDownUrl(fileId, subFileId) { var result = ''; var s_url = unsafeWindow.location.href; var match = s_url.match(/cloud\.189\.cn\/t\/([0-9a-z]+)/i); var shortCode = match ? match[1] : null; $.ajax({ type: 'get', url: '//cloud.189.cn/v2/getFileDownloadUrl.action', data: { shortCode: shortCode, fileId: subFileId, accessCode: getCookie('shareId_' + _shareId), subFileId: fileId, noCache: 1 }, dateType: 'text', async: false, success: function(data) { result = data; }, error: function(data) { console.error(data); } }); return result; } function shareShowDownload() { if(getCookie('COOKIE_LOGIN_USER') == ''){ application.showNotify({type:'error', message:'登录后才能显示'}); return false; } var sels = getSelectedFileList(); showDownloadDialog(); var html = ''; var tmp = getMetadata(); if (tmp.path) { html += '

    压缩包:

    '; html += '

    文件列表:

    '; } html += ''; $('#J_FileModal .modal-body').html(html); $('#J_FileModal').show(); } function mainShowDownload() { if(unsafeWindow.edrive.userId == ''){ application.showNotify({type:'error', message:'登录后才能显示'}); $('#J_FileModal').hide(); return false; } showDownloadDialog(); var file_id = (unsafeWindow.location.hash && unsafeWindow.location.hash != '#home' ? unsafeWindow.location.hash.replace('#home/folder/', '') : '-11'); console.log('file_id', file_id); var file_list = JSON.parse(unsafeWindow.localStorage.getItem('home-' + file_id)); if(file_list == null){ application.showNotify({type:'error', message:'获取失败'}); $('#J_FileModal').hide(); return false; } var html = '

    ' + file_list.path[file_list.path.length-1].fileName + '

    '; html += ''; $('#J_FileModal .modal-body').html(html); $('#J_FileModal .modal-body .folder_btn').off('click').on('click', function(e){ e.preventDefault(); application.showNotify({type:'error', message:'请进入文件夹后再获取'}); setTimeout('window.location.hash = "' + $(this).attr('href') + '"', 1000); $('#J_FileModal').hide(); }); $('#J_FileModal').show(); } function photoShowDownload() { application.showNotify({type:'error', message:'功能待完善'}); } function showDownloadDialog() { var template = ''; if ($('#J_FileModal').length == 0) { $('body').append(template); $('#J_FileModal .close').on('click', function(e) { $('#J_FileModal').hide(); }); } } function addLoadEvent(func) { var old_onload = unsafeWindow.onload; if (typeof unsafeWindow.onload != 'function') { unsafeWindow.onload = func; } else { old_onload(); func(); } } function getCookie(name) { var strcookie = document.cookie; var arrcookie = strcookie.split('; '); for (var i = 0; i < arrcookie.length; i++) { var arr = arrcookie[i].split('='); if (arr[0] == name) { return arr[1]; } } return ''; }