├── chrome ├── .gitignore ├── images │ ├── icon.jpg │ ├── logo16.png │ ├── logo32.png │ ├── logo48.png │ ├── logo64.png │ ├── logo128.png │ └── BaiduExplorerIcon.svg ├── .web-extension-id ├── _locales │ ├── zh_CN │ │ └── messages.json │ └── en │ │ └── messages.json ├── webpack.config.js ├── src │ ├── inject.js │ ├── album.js │ ├── baidu.js │ ├── fuck_baidu.js │ ├── home.js │ ├── convert.js │ ├── share.js │ └── core.js ├── manifest.json ├── js │ ├── inject.js │ ├── album.js │ ├── fuck_baidu.js │ ├── connect.js │ ├── baidu.js │ ├── core.js │ ├── convert.js │ └── home.js ├── background.js └── css │ └── setting.css ├── aria2c ├── start.bat ├── HideRun.vbs ├── README.md └── aria2.conf ├── chrome.crx ├── firefox.xpi ├── .github ├── CONTRIBUTING.md └── issue_template.md ├── .eslintrc.json └── README.md /chrome/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /aria2c/start.bat: -------------------------------------------------------------------------------- 1 | aria2c.exe --conf=aria2.conf -------------------------------------------------------------------------------- /chrome.crx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome.crx -------------------------------------------------------------------------------- /firefox.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/firefox.xpi -------------------------------------------------------------------------------- /aria2c/HideRun.vbs: -------------------------------------------------------------------------------- 1 | CreateObject("WScript.Shell").Run "aria2c.exe --conf-path=aria2.conf",0 -------------------------------------------------------------------------------- /chrome/images/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/icon.jpg -------------------------------------------------------------------------------- /chrome/images/logo16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/logo16.png -------------------------------------------------------------------------------- /chrome/images/logo32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/logo32.png -------------------------------------------------------------------------------- /chrome/images/logo48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/logo48.png -------------------------------------------------------------------------------- /chrome/images/logo64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/logo64.png -------------------------------------------------------------------------------- /chrome/images/logo128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mrs4s/BaiduExporter/HEAD/chrome/images/logo128.png -------------------------------------------------------------------------------- /chrome/.web-extension-id: -------------------------------------------------------------------------------- 1 | # This file was created by https://github.com/mozilla/web-ext 2 | # Your auto-generated extension ID for addons.mozilla.org is: 3 | {9eb45374-1aad-4d38-b1ba-9df392f6bf54} -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | TROUBLESHOOTING: 2 | 3 | 1. 尝试安装最新版本插件 4 | 2. 尝试清空浏览器缓存 5 | 3. 尝试卸载插件后重新安装 6 | 7 | 发起 Issue 时,请最好提供: 8 | 9 | 1. 您下载的内容地址 10 | 2. 插件版本号,浏览器版本号,系统版本号 11 | 3. 列举出现问题的详细步骤 12 | 4. 描述能否复现问题 13 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 请确保以下几点: 2 | 3 | 1. 已经阅读过README 4 | 2. 尝试安装最新版本插件 5 | 3. 尝试清空浏览器缓存 6 | 4. 尝试卸载插件后重新安装 7 | 8 | 发起 Issue 时,请提供: 9 | 10 | 1. 您下载的内容地址 11 | 2. 插件版本号,浏览器版本号,系统版本号 12 | 3. 列举出现问题的详细步骤 13 | 4. 描述能否复现问题 14 | 15 | ---------- 16 | 17 | **不符合上述条件的Issue将被无理由关闭** 18 | -------------------------------------------------------------------------------- /chrome/_locales/zh_CN/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "appName": { 3 | "message": "网盘助手" 4 | }, 5 | "description": { 6 | "message": "可以方便的把网盘的下载地址导出到aria2/aria2-rpc,支持YAAW。" 7 | }, 8 | "openContextMenuTitle": { 9 | "message": "导出到aria2-rpc" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chrome/_locales/en/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "appName": { 3 | "message": "Exporter" 4 | }, 5 | "description": { 6 | "message": "Assistant to export download links to aria2/aria2-rpc" 7 | }, 8 | "openContextMenuTitle": { 9 | "message": "Export to aria2-rpc" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chrome/webpack.config.js: -------------------------------------------------------------------------------- 1 | var webpack = require('webpack'); 2 | var path = require('path'); 3 | var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); 4 | module.exports = { 5 | context: __dirname + '/src', 6 | entry: { 7 | home: './home.js', 8 | share: './share.js', 9 | album: './album.js', 10 | baidu:'./baidu.js', 11 | inject:'./inject.js' 12 | }, 13 | output: { 14 | path: __dirname + '/js', 15 | filename: '[name].js' // 为上面entry的key值 16 | }, 17 | plugins: [ 18 | // new webpack.optimize.UglifyJsPlugin(), 19 | ], 20 | }; -------------------------------------------------------------------------------- /aria2c/README.md: -------------------------------------------------------------------------------- 1 | # Aria2 for windows 2 | 3 | 关于aria2在Windows下的配置大家一直很有疑问,所以我还是写点东西方便大家使用比较好 4 | 5 | ## Download 6 | - 目前下载已经转移到Github上进行版本发布了,大家可以在[Release](https://github.com/tatsuhiro-t/aria2/releases/)下下载自己电脑对应的版本. 7 | 8 | ## Usage 9 | - 直接运行exe只会闪现一个黑框消失,无法正常使用的,必须使用脚本进行启动. 10 | - 拷贝这个目录下的配置文件和脚本文件,和下载解压缩的aria2c.exe放在同一个目录下. 11 | - 点击 `start.bat`可以直接运行,但是会有一个命令行窗口,不能关闭,关闭也就意味着程序的退出 12 | - 点击 `HideRun.vbs`也会直接运行,但是没有任何反应,因为隐藏窗口了,可以在任务管理器的进程窗口里看到程序的运行 13 | 14 | 15 | ##配置 16 | 17 | - 默认配置已经够用了,不过方便大家,还是讲解下常用的几个参数吧. 18 | - 配置文件里面的 `#`符号代表注释,如果使用这个符号那么那一行的设置就不会生效,想启用设置必须先把前面的`#`号删除 19 | - 一般情况下要根据自己的需求设置下载路径也就是`dir`这个参数,注意这里一定得写绝对路径 20 | - 首先是 `rpc-user`和`rpc-passwd`很明显这个需要一起使用,这是旧的加密方式.如果启用的话RPC路径就变成 `http://username:passwd@hostname:port/jsonrpc` 这种格式了(不推荐使用这个格式) 21 | - 其次是`rpc-secret`,使用这个设置加密路径的话,RPC格式就是`http://token:secret@hostname:port/jsonrpc`这样 22 | - 如果只是在自己电脑上使用的话,没必要启用任何加密方式,默认的就行.这样RPC路径就是`http://localhost:6800/jsonrpc` -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "jquery": true, 6 | "amd": true, 7 | "webextensions": true 8 | }, 9 | "extends": "eslint:recommended", 10 | "globals": { 11 | "CORE": true, 12 | "CONNECT": true, 13 | "Utilities": true, 14 | "SetMessage": true, 15 | "disk": true, 16 | "yunData": true 17 | }, 18 | "parserOptions": { 19 | "sourceType": "module" 20 | }, 21 | "rules": { 22 | "no-unused-vars": [ 23 | 0 24 | ], 25 | "no-console": [ 26 | 0 27 | ], 28 | "indent": [ 29 | 2, 30 | 4 31 | ], 32 | "linebreak-style": [ 33 | 2, 34 | "unix" 35 | ], 36 | "quotes": [ 37 | 2, 38 | "double", 39 | "avoid-escape" 40 | ], 41 | "semi": [ 42 | 2, 43 | "always" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /chrome/src/inject.js: -------------------------------------------------------------------------------- 1 | if (typeof browser != "undefined") 2 | chrome = browser; 3 | 4 | function requestAddScript(name) { 5 | chrome.runtime.sendMessage({ 6 | method: "add_script", 7 | data: "js/" + name + ".js" 8 | }); 9 | } 10 | 11 | $(function() { 12 | window.addEventListener("message", function(event) { 13 | if (event.source != window) 14 | return; 15 | 16 | if (event.data.type == "yunData") { 17 | // console.log(event.data.data); 18 | window.yunData = JSON.parse(event.data.data); 19 | 20 | if (window.location.href.includes("/disk/home")) 21 | requestAddScript("home"); 22 | else if (window.location.href.includes("/pcloud/album/")) 23 | requestAddScript("album"); 24 | else 25 | requestAddScript("share"); 26 | } 27 | }); 28 | 29 | function addBaiduJS() { 30 | var s = document.createElement("script"); 31 | s.src = chrome.runtime.getURL("js/baidu.js"); 32 | document.body.appendChild(s); 33 | } 34 | if (document.readyState === "complete") { 35 | addBaiduJS(); 36 | } else { 37 | window.addEventListener('load', addBaiduJS); 38 | } 39 | }); -------------------------------------------------------------------------------- /aria2c/aria2.conf: -------------------------------------------------------------------------------- 1 | #用户名 2 | #rpc-user=user 3 | #密码 4 | #rpc-passwd=passwd 5 | #设置加密的密钥 6 | #rpc-secret=secret 7 | #允许rpc 8 | enable-rpc=true 9 | #允许所有来源, web界面跨域权限需要 10 | rpc-allow-origin-all=true 11 | #是否启用https加密,启用之后要设置公钥,私钥的文件路径 12 | #rpc-secure=true 13 | #启用加密设置公钥 14 | #rpc-certificate=/home/name/.config/aria2/example.crt 15 | #启用加密设置私钥 16 | #rpc-private-key=/home/name/.config/aria2/example.key 17 | #允许外部访问,false的话只监听本地端口 18 | rpc-listen-all=true 19 | #RPC端口, 仅当默认端口被占用时修改 20 | #rpc-listen-port=6800 21 | #最大同时下载数(任务数), 路由建议值: 3 22 | max-concurrent-downloads=5 23 | #断点续传 24 | continue=true 25 | #同服务器连接数 26 | max-connection-per-server=5 27 | #最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要 28 | min-split-size=10M 29 | #单文件最大线程数, 路由建议值: 5 30 | split=10 31 | #下载速度限制 32 | max-overall-download-limit=0 33 | #单文件速度限制 34 | max-download-limit=0 35 | #上传速度限制 36 | max-overall-upload-limit=0 37 | #单文件速度限制 38 | max-upload-limit=0 39 | #断开速度过慢的连接 40 | #lowest-speed-limit=0 41 | #验证用,需要1.16.1之后的release版本 42 | #referer=* 43 | #文件保存路径, 默认为当前启动位置 44 | dir=D:\Downloads 45 | #文件缓存, 使用内置的文件缓存, 如果你不相信Linux内核文件缓存和磁盘内置缓存时使用, 需要1.16及以上版本 46 | #disk-cache=0 47 | #另一种Linux文件缓存方式, 使用前确保您使用的内核支持此选项, 需要1.15及以上版本(?) 48 | #enable-mmap=true 49 | #文件预分配, 能有效降低文件碎片, 提高磁盘性能. 缺点是预分配时间较长 50 | #所需时间 none < falloc ? trunc << prealloc, falloc和trunc需要文件系统和内核支持 51 | file-allocation=prealloc 52 | #不进行证书校验 53 | check-certificate=false -------------------------------------------------------------------------------- /chrome/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "background": { 3 | "scripts": [ "background.js" ], 4 | "persistent": false 5 | }, 6 | "content_scripts": [ 7 | { 8 | "js": ["js/jquery-2.2.3.min.js", "js/inject.js" ], 9 | "css": [ "css/setting.css" ], 10 | "matches": [ "*://pan.baidu.com/s/*", "*://yun.baidu.com/s/*", "*://pan.baidu.com/disk/home*", "*://yun.baidu.com/share/link*", "*://pan.baidu.com/share/link*", "*://yun.baidu.com/disk/home*", "*://pan.baidu.com/pcloud/album/*", "*://yun.baidu.com/pcloud/album/*" ], 11 | "run_at": "document_idle" 12 | }, 13 | { 14 | "js": [ "js/fuck_baidu.js" ], 15 | "matches": [ "*://pan.baidu.com/s/*", "*://yun.baidu.com/s/*", "*://pan.baidu.com/disk/home*", "*://yun.baidu.com/share/link*", "*://pan.baidu.com/share/link*", "*://yun.baidu.com/disk/home*", "*://pan.baidu.com/pcloud/album/*", "*://yun.baidu.com/pcloud/album/*" ], 16 | "run_at": "document_start" 17 | } 18 | ], 19 | "default_locale": "en", 20 | "description": "__MSG_description__", 21 | "icons": { 22 | "32": "images/logo32.png", 23 | "16": "images/logo16.png", 24 | "48": "images/logo48.png", 25 | "128": "images/logo128.png" 26 | }, 27 | "web_accessible_resources": [ "js/baidu.js", "js/convert.js" ], 28 | "manifest_version": 2, 29 | "permissions": [ "cookies", "notifications", "*://pan.baidu.com/", "*://yun.baidu.com/", "*://pcs.baidu.com/", "activeTab", "contextMenus", "storage" ], 30 | "name": "__MSG_appName__", 31 | "author": "acgotaku", 32 | "version": "0.8.8" 33 | } 34 | -------------------------------------------------------------------------------- /chrome/src/album.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | //网盘专辑页面导出 3 | /* 4 | 基本步骤是首先设定导出模式,文本模式的话 5 | 只需要初始化文本框即可,RPC模式要设置好 RPC地址 6 | 然后开始分析选中的文件 获取当前文件夹的所以文件id 7 | 然后进行比较,如果是文件 直接进行下载 如果是文件夹则递归查找 8 | 遇到文件就下载 遇到文件夹继续获取文件夹里面的内容 9 | 10 | */ 11 | //两种导出模式 RPC模式 和 TXT模式 12 | var MODE = "RPC"; 13 | var RPC_PATH = "http://localhost:6800/jsonrpc"; 14 | var isSingleShare = window.location.pathname.includes("file"); 15 | 16 | // 获得选中的文件 17 | function getShareFile() { 18 | var file_list = []; 19 | if (isSingleShare) { 20 | file_list.push({ name: yunData.server_filename, link: yunData.dlink }); 21 | } 22 | else { 23 | var selected = $("#fileItems .on"); 24 | if (selected.length == 0) { 25 | showToast("请选择一下你要保存的文件哦", "MODE_CAUTION"); 26 | return; 27 | } 28 | 29 | for (var i=0;i` if you are using aria2 1.18.4(or higher) with 'JSON-RPC PATH' like http://token:secret@hostname:port/jsonrpc 12 | - Set `--rpc-user= --rpc-passwd=` if you are using aria2 1.15.2(or higher) with 'JSON-RPC PATH' like http://username:passwd@hostname:port/jsonrpc 13 | - Use `http://localhost:6800/jsonrpc#max-connection-per-server=5&split=10` set download options for specific file. 14 | - 已上传 Aria2 配置文件方便大家使用:[aria2.conf](https://raw.githubusercontent.com/acgotaku/BaiduExporter/master/aria2c/aria2.conf) 15 | - Aria2 配置参考我的博客:[使用 Aria2 下载百度网盘和 115 的资源](https://blog.icehoney.me/posts/2015-01-31-Aria2-download)。 16 | 17 | ## Install 18 | 19 | 全面支持 Chrome, Firefox, Edge 和 Safari: 20 | 21 | * Chrome : Click **Settings** -> **Extensions** -> Check **Developer mode**-> **Load unpacked extension**, navigate to the `chrome` folder, click OK. 22 | * Firefox : Open **about:debugging** in Firefox, click "Load Temporary Add-on" and navigate to the `chrome` folder, click OK. 23 | * Safari : Install Chrome or Firefox on Mac. 24 | * Edge: You need at least Windows 10 build 14342 25 | 1. Open [about:flags](about:flags), Check `Enable extension developer features`, Restart. 26 | 2. Clone repo to a local read-write folder. 27 | 3. Click **More(...)** -> **Extensions** -> **Load extension**, navigate to the `chrome` folder, click OK. 28 | 29 | ## Issue 须知 30 | 31 | 请先阅读[这里](https://github.com/acgotaku/BaiduExporter/issues/128) 32 | 33 | ## Thanks 34 | 35 | - Icon by [Losses Don](https://github.com/Losses) 36 | 37 | ## Tips 38 | 39 | 不想每次开启Chrome都提示禁用请看这个帖子:[Guide on Packaging and Import Baidu Exporter to Chrome](https://hencolle.com/2016/10/16/baidu_exporter/) 40 | 41 | ## License 42 | 43 | ![GPLv3](https://www.gnu.org/graphics/gplv3-127x51.png) 44 | 45 | BaiduExporter is licensed under [GNU General Public License](https://www.gnu.org/licenses/gpl.html) Version 3 or later. 46 | 47 | BaiduExporter is free software: you can redistribute it and/or modify 48 | it under the terms of the GNU General Public License as published by 49 | the Free Software Foundation, either version 3 of the License, or 50 | (at your option) any later version. 51 | 52 | BaiduExporter is distributed in the hope that it will be useful, 53 | but WITHOUT ANY WARRANTY; without even the implied warranty of 54 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 55 | GNU General Public License for more details. 56 | 57 | You should have received a copy of the GNU General Public License 58 | along with BaiduExporter. If not, see . 59 | -------------------------------------------------------------------------------- /chrome/js/inject.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) 10 | /******/ return installedModules[moduleId].exports; 11 | 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ exports: {}, 15 | /******/ id: moduleId, 16 | /******/ loaded: false 17 | /******/ }; 18 | 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | 22 | /******/ // Flag the module as loaded 23 | /******/ module.loaded = true; 24 | 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | 29 | 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | 36 | /******/ // __webpack_public_path__ 37 | /******/ __webpack_require__.p = ""; 38 | 39 | /******/ // Load entry module and return exports 40 | /******/ return __webpack_require__(0); 41 | /******/ }) 42 | /************************************************************************/ 43 | /******/ ([ 44 | /* 0 */ 45 | /***/ function(module, exports) { 46 | 47 | if (typeof browser != "undefined") 48 | chrome = browser; 49 | 50 | function requestAddScript(name) { 51 | chrome.runtime.sendMessage({ 52 | method: "add_script", 53 | data: "js/" + name + ".js" 54 | }); 55 | } 56 | 57 | $(function() { 58 | window.addEventListener("message", function(event) { 59 | if (event.source != window) 60 | return; 61 | 62 | if (event.data.type == "yunData") { 63 | // console.log(event.data.data); 64 | window.yunData = JSON.parse(event.data.data); 65 | 66 | if (window.location.href.includes("/disk/home")) 67 | requestAddScript("home"); 68 | else if (window.location.href.includes("/pcloud/album/")) 69 | requestAddScript("album"); 70 | else 71 | requestAddScript("share"); 72 | } 73 | }); 74 | 75 | function addBaiduJS() { 76 | var s = document.createElement("script"); 77 | s.src = chrome.runtime.getURL("js/baidu.js"); 78 | document.body.appendChild(s); 79 | } 80 | if (document.readyState === "complete") { 81 | addBaiduJS(); 82 | } else { 83 | window.addEventListener('load', addBaiduJS); 84 | } 85 | }); 86 | 87 | /***/ } 88 | /******/ ]); -------------------------------------------------------------------------------- /chrome/src/baidu.js: -------------------------------------------------------------------------------- 1 | var showToast; 2 | 3 | (function () { 4 | // 封装的百度的Toast提示消息 5 | // Type类型有 6 | // caution 警告 failure 失败 loading 加载 success 成功 7 | // MODE_CAUTION 警告 MODE_FAILURE 失败 MODE_LOADING 加载 MODE_SUCCESS 成功 8 | 9 | if (typeof window.require == "undefined") { 10 | showToast = function (message, type) { 11 | Utilities.useToast({ 12 | toastMode: disk.ui.Toast[type], 13 | msg: message, 14 | sticky: false 15 | }) 16 | }; 17 | } else if (typeof manifest == "object") { 18 | // New version 19 | var Context = window.require("system-core:context/context.js").instanceForSystem; 20 | Context.log.send=function(e){}; 21 | showToast = function (message, type) { 22 | if (type.startsWith("MODE")) { 23 | type = type.split("_")[1].toLowerCase(); 24 | } 25 | Context.ui.tip({ 26 | mode: type, 27 | msg: message 28 | }); 29 | }; 30 | 31 | window.addEventListener("message", function (event) { 32 | if (event.source != window) 33 | return; 34 | 35 | if (event.data.type == "get_selected") { 36 | window.postMessage({ type: "selected", data: Context.list.getSelected() }, "*"); 37 | } 38 | }); 39 | } else { 40 | var Toast = window.require("common:widget/toast/toast.js"); 41 | showToast = function (message, type) { 42 | Toast.obtain.useToast({ 43 | toastMode: Toast.obtain[type], 44 | msg: message, 45 | sticky: false 46 | }); 47 | }; 48 | } 49 | 50 | window.addEventListener("message", function (event) { 51 | if (event.source != window) 52 | return; 53 | 54 | if (event.data.type == "show_toast") { 55 | var request = event.data.data; 56 | showToast(request.message, request.type); 57 | 58 | var button = $("#export_menu"); 59 | if (button.length != 0) { 60 | try { 61 | button.parent()[0].removeChild = function () { 62 | console.log("Remove me? Naive!"); 63 | }; 64 | Object.defineProperty(button.parent()[0], "removeChild", { writable: false} ); 65 | } catch (e) { 66 | console.log("Unable to hook removeChild"); 67 | } 68 | } 69 | } 70 | }); 71 | 72 | if (window.yunData) { 73 | if (window.yunData.sign2) { 74 | var yunData = window.require('disk-system:widget/data/yunData.js').get(); 75 | window.postMessage({ type: "yunData", data: JSON.stringify(yunData) }, "*"); 76 | } 77 | else { 78 | window.postMessage({ type: "yunData", data: JSON.stringify(window.yunData) }, "*"); 79 | } 80 | } 81 | else if (window.disk.ui.album) { 82 | var real = window.disk.ui.album.prototype.buildListView; 83 | window.disk.ui.album.prototype.buildListView = function (list) { 84 | window.postMessage({ type: "yunData", data: JSON.stringify(list) }, "*"); 85 | real.call(this, list); 86 | } 87 | } 88 | else if (disk.util.ViewShareUtils) { 89 | window.postMessage({ type: "yunData", data: disk.util.ViewShareUtils.viewShareData }, "*"); 90 | } 91 | })(); -------------------------------------------------------------------------------- /chrome/js/album.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) 10 | /******/ return installedModules[moduleId].exports; 11 | 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ exports: {}, 15 | /******/ id: moduleId, 16 | /******/ loaded: false 17 | /******/ }; 18 | 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | 22 | /******/ // Flag the module as loaded 23 | /******/ module.loaded = true; 24 | 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | 29 | 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | 36 | /******/ // __webpack_public_path__ 37 | /******/ __webpack_require__.p = ""; 38 | 39 | /******/ // Load entry module and return exports 40 | /******/ return __webpack_require__(0); 41 | /******/ }) 42 | /************************************************************************/ 43 | /******/ ([ 44 | /* 0 */ 45 | /***/ function(module, exports) { 46 | 47 | (function () { 48 | //网盘专辑页面导出 49 | /* 50 | 基本步骤是首先设定导出模式,文本模式的话 51 | 只需要初始化文本框即可,RPC模式要设置好 RPC地址 52 | 然后开始分析选中的文件 获取当前文件夹的所以文件id 53 | 然后进行比较,如果是文件 直接进行下载 如果是文件夹则递归查找 54 | 遇到文件就下载 遇到文件夹继续获取文件夹里面的内容 55 | 56 | */ 57 | //两种导出模式 RPC模式 和 TXT模式 58 | var MODE = "RPC"; 59 | var RPC_PATH = "http://localhost:6800/jsonrpc"; 60 | var isSingleShare = window.location.pathname.includes("file"); 61 | 62 | // 获得选中的文件 63 | function getShareFile() { 64 | var file_list = []; 65 | if (isSingleShare) { 66 | file_list.push({ name: yunData.server_filename, link: yunData.dlink }); 67 | } 68 | else { 69 | var selected = $("#fileItems .on"); 70 | if (selected.length == 0) { 71 | showToast("请选择一下你要保存的文件哦", "MODE_CAUTION"); 72 | return; 73 | } 74 | 75 | for (var i=0;i=r&&(a.push(t({type:"childList",target:c,addedNodes:[f],removedNodes:[f],nextSibling:f.nextSibling,previousSibling:f.previousSibling})),y--),d.a&&k.a&&A(a,f,k.a,d.d),d.c&&3===f.nodeType&&f.nodeValue!==k.c&&a.push(t({type:"characterData",target:f})),d.e&&n(f,k)}function n(b,c){for(var x=b.childNodes,p=c.b,y=x.length,w=p?p.length:0,f,k,e,l,u,z=0,v=0,q=0;v=r&&(a.push(t({type:"childList",target:c,addedNodes:[f],removedNodes:[f],nextSibling:f.nextSibling,previousSibling:f.previousSibling})),y--),d.a&&k.a&&A(a,f,k.a,d.d),d.c&&3===f.nodeType&&f.nodeValue!==k.c&&a.push(t({type:"characterData",target:f})),d.e&&n(f,k)}function n(b,c){for(var x=b.childNodes,p=c.b,y=x.length,w=p?p.length:0,f,k,e,l,u,z=0,v=0,q=0;v 2 | 3 | 4 | 5 | 20 | 22 | 41 | 43 | 44 | 46 | image/svg+xml 47 | 49 | 50 | 51 | 52 | 53 | 59 | 65 | 74 | 80 | 86 | 92 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /chrome/background.js: -------------------------------------------------------------------------------- 1 | if (typeof browser != "undefined") 2 | chrome = browser; 3 | 4 | var HttpSendRead = function (info) { 5 | Promise.prototype.done = Promise.prototype.then; 6 | Promise.prototype.fail = Promise.prototype.catch; 7 | return new Promise(function (resolve, reject) { 8 | var http = new XMLHttpRequest(); 9 | var contentType = "\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u0078\u002d\u0077\u0077\u0077\u002d\u0066\u006f\u0072\u006d\u002d\u0075\u0072\u006c\u0065\u006e\u0063\u006f\u0064\u0065\u0064\u003b\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003d\u0055\u0054\u0046\u002d\u0038"; 10 | var timeout = 3000; 11 | if (info.contentType != null) { 12 | contentType = info.contentType; 13 | } 14 | if (info.timeout != null) { 15 | timeout = info.timeout; 16 | } 17 | var timeId = setTimeout(httpclose, timeout); 18 | function httpclose() { 19 | http.abort(); 20 | } 21 | http.onreadystatechange = function () { 22 | if (http.readyState == 4) { 23 | if ((http.status == 200 && http.status < 300) || http.status == 304) { 24 | clearTimeout(timeId); 25 | if (info.dataType == "json") { 26 | resolve(JSON.parse(http.responseText), http.status, http); 27 | } 28 | else if (info.dataType == "SCRIPT") { 29 | // eval(http.responseText); 30 | resolve(http.responseText, http.status, http); 31 | } 32 | } 33 | else { 34 | clearTimeout(timeId); 35 | reject(http, http.statusText, http.status); 36 | } 37 | } 38 | }; 39 | http.open(info.type, info.url, true); 40 | http.setRequestHeader("Content-type", contentType); 41 | var h; 42 | for (h in info.headers) { 43 | if (info.headers[h]) { 44 | http.setRequestHeader(h, info.headers[h]); 45 | } 46 | } 47 | if (info.type == "POST") { 48 | http.send(info.data); 49 | } 50 | else { 51 | http.send(); 52 | } 53 | }); 54 | }; 55 | 56 | chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { 57 | console.log(request.method); 58 | console.log(request.data); 59 | switch (request.method) { 60 | case "add_script": 61 | chrome.tabs.executeScript(sender.tab.id, { file: request.data }); 62 | break; 63 | case "rpc_data": 64 | HttpSendRead(request.data) 65 | .done(function (json, textStatus, jqXHR) { 66 | sendResponse(true); 67 | }) 68 | .fail(function (jqXHR, textStatus, errorThrown) { 69 | sendResponse(false); 70 | }); 71 | return true; 72 | case "config_data": 73 | for (var key in request.data) { 74 | localStorage.setItem(key, request.data[key]); 75 | } 76 | break; 77 | case "rpc_version": 78 | HttpSendRead(request.data) 79 | .done(function (json, textStatus, jqXHR) { 80 | sendResponse(json); 81 | }) 82 | .fail(function (jqXHR, textStatus, errorThrown) { 83 | sendResponse(null); 84 | }); 85 | return true; 86 | case "get_cookies": 87 | getCookies(request.data).then(value => sendResponse(value)); 88 | return true; 89 | } 90 | }); 91 | 92 | // Promise style `chrome.cookies.get()` 93 | function getCookie(detail) { 94 | return new Promise(function (resolve) { 95 | chrome.cookies.get(detail, resolve); 96 | }); 97 | }; 98 | 99 | //async function getCookies(details) 100 | //{ 101 | // var obj = {}; 102 | // for (var item of await Promise.all(details.map(item => getCookie(item)))) 103 | // obj[item.name] = item.value; 104 | // return obj; 105 | //} 106 | 107 | function getCookies(details) { 108 | return new Promise(function (resolve) { 109 | var list = details.map(item => getCookie(item)); 110 | Promise.all(list).then(function (cookies) { 111 | var obj = {}; 112 | for (var item of cookies) 113 | if (item != null) 114 | obj[item.name] = item.value; 115 | resolve(obj); 116 | }); 117 | }); 118 | } 119 | 120 | //弹出chrome通知 121 | function showNotification(id, opt) { 122 | if (!chrome.notifications) 123 | return; 124 | 125 | chrome.notifications.create(id, opt, function () { }); 126 | setTimeout(function () { 127 | chrome.notifications.clear(id, function () { }); 128 | }, 5000); 129 | } 130 | 131 | //软件版本更新提示 132 | var manifest = chrome.runtime.getManifest(); 133 | var previousVersion = localStorage.getItem("version"); 134 | if (previousVersion == "" || previousVersion != manifest.version) { 135 | var opt = { 136 | type: "basic", 137 | title: "更新", 138 | message: "百度网盘助手更新到" + manifest.version + "版本啦~\n此次更新解决下载文件路径的问题~", 139 | iconUrl: "images/icon.jpg" 140 | }; 141 | var id = new Date().getTime().toString(); 142 | showNotification(id, opt); 143 | localStorage.setItem("version", manifest.version); 144 | } 145 | -------------------------------------------------------------------------------- /chrome/css/setting.css: -------------------------------------------------------------------------------- 1 | #setting_div, 2 | #download_ui { 3 | border: 3px solid #999; 4 | background: #FFF; 5 | width: 600px; 6 | box-shadow: 0 0 9px #999; 7 | position: absolute; 8 | z-index: 998; 9 | } 10 | 11 | .g-button-menu { 12 | cursor: pointer; 13 | } 14 | 15 | .save-button { 16 | cursor: pointer; 17 | font-size: 12px; 18 | height: 34px; 19 | line-height: 34px; 20 | padding-left: 35px; 21 | position: relative; 22 | margin-right: 10px; 23 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMUAAAAiCAYAAADveR3KAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wwLBCo75CTjigAAAT5JREFUeNrt2Ttug0AUheEzPAqn4tGwEPbAmtkDO0AyqRCNoYsLGMZNjBUEkVJF1vxfSYN0NVfn3hkzL4uz86yv+114T/M8K47jt//Hf/u4XBTGsaLPrlPTNMqzjNMFr93GUWVZKmqaRlVVKU1TqgKvTdOkuq4VSVKSJHLOURV4LUkSSVJAKYCfaApgJ5LE6ARIMsaQFMBpUqwkBbAlBEkBsGgDx54TE00BHO0Ubl2pBLxngoCkAM6TgtsnQIZFGzhGUwDfnrt1tP8AeDs+hSFJAZyOT6QE8LpwIimAnW2nsKQFfG8GHu+AX5LCrqtWkgIgKYDTpiAlgNctLEkBMD4BNAXwJ9s7BXsFfGfZKYCTpMizTMMwqCgKqgGv9X2vPMtk2rZ13fWq2zhSFXivLEsZa61bloVqwHvGGJkg0APD/WsWsNiZMwAAAABJRU5ErkJggg==') no-repeat 0 0; 24 | display: inline-block; 25 | } 26 | 27 | .save-button em { 28 | position: absolute; 29 | left: 10px; 30 | top: 8px; 31 | } 32 | 33 | .save-button b { 34 | color: #666; 35 | padding-right: 10px; 36 | height: 34px; 37 | line-height: 34px; 38 | text-decoration: none; 39 | display: block; 40 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMUAAAAiCAYAAADveR3KAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wwLBCo75CTjigAAAT5JREFUeNrt2Ttug0AUheEzPAqn4tGwEPbAmtkDO0AyqRCNoYsLGMZNjBUEkVJF1vxfSYN0NVfn3hkzL4uz86yv+114T/M8K47jt//Hf/u4XBTGsaLPrlPTNMqzjNMFr93GUWVZKmqaRlVVKU1TqgKvTdOkuq4VSVKSJHLOURV4LUkSSVJAKYCfaApgJ5LE6ARIMsaQFMBpUqwkBbAlBEkBsGgDx54TE00BHO0Ubl2pBLxngoCkAM6TgtsnQIZFGzhGUwDfnrt1tP8AeDs+hSFJAZyOT6QE8LpwIimAnW2nsKQFfG8GHu+AX5LCrqtWkgIgKYDTpiAlgNctLEkBMD4BNAXwJ9s7BXsFfGfZKYCTpMizTMMwqCgKqgGv9X2vPMtk2rZ13fWq2zhSFXivLEsZa61bloVqwHvGGJkg0APD/WsWsNiZMwAAAABJRU5ErkJggg==') no-repeat right 0; 41 | } 42 | 43 | .top .close { 44 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wwLAhwxiWDnUwAAAP9JREFUOMvtkE1uwjAQhd9UkSxl4RvAIr5VOABVfIDS8lP6J2DZRSJygHKNchFnEW4wi0hZTVdYSVpIu6sQb+c39ud5D7jq34m6hojINs9RlgcMhwOM4hhaa3+PmeVjt/Pz2/EYROTnwbcfiIiZZbXeYP+5R1kewMyitfZ+4RwiYzCK4xbsxw2bmzQfW5sgTTN/ns+mCMOQeiN34z9MZyic815kDO4nd60amro5WzARWZsgMsbDrE1OwnqBzCzHmABQOIc0zcDM8mdgt8P3LEdkDArnsFpvTkKD38COndV1Lcun5xa0Gz/ogy0fF1BKEQAopaiqKnl5fTsLverS9QXS7puw76aeiwAAAABJRU5ErkJggg==') no-repeat scroll 0 0 transparent; 45 | cursor: pointer; 46 | height: 20px; 47 | right: 10px; 48 | top: 10px; 49 | width: 20px; 50 | position: absolute; 51 | } 52 | 53 | .top h3, 54 | .close { 55 | height: 42px; 56 | line-height: 40px; 57 | } 58 | 59 | .top h3 { 60 | text-indent: 1em; 61 | color: #333; 62 | font-size: 14px; 63 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAABgCAIAAAC19kRlAAAAkUlEQVQ4y81SMQ6AIAwshoQ3OLr4S3+Jv2AgTiRC6iRtiZiGRbtd7q5cWwwiwl22lFLBBKyUwPJu33v+LPvEI4ARp/feExNjJMY5R0zO+bnBSIKh1Ou2U7ZlngkAnwf5qgCQy/gSRxj5Dnbv00sgGd6tkak82PO8xGmGQ01qpUyXoGFUV5Ce42Q/MYRAIKVUwQVuRHZj5tt3GgAAAABJRU5ErkJggg==') repeat-x 0 0 #EEE; 64 | font-weight: 700; 65 | } 66 | 67 | .global-icon-download { 68 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wwLAxApN3taPgAAAJBJREFUOMtjYBjsgJGQgtylD//D2JOj5QmqZyLF9v////+nqoHEgGFiIA8HG+WxjBy7yAZ++fELb2wzEXIZzLAvP34RFduMhNIgunfbgiQgGhkZGclK2JVrn/8n1jCiQeXa5/9hgGgNyC4hJZeg62UiNmsR8iZMLwuyYNW6FwyEXEr3nMJISklC0DBKY58uAADhV0qO0TJN9gAAAABJRU5ErkJggg==') no-repeat; 69 | height: 20px; 70 | width: 20px; 71 | } 72 | 73 | #setting_div_table input { 74 | text-indent: 10px; 75 | border: 1px solid #C6C6C6; 76 | box-shadow: 0 0 3px #C6C6C6; 77 | -webkit-box-shadow: 0 0 3px #C6C6C6; 78 | } 79 | tr>td:first-child{ 80 | width: 110px; 81 | } 82 | .input-large { 83 | width: 80%; 84 | } 85 | 86 | .input-medium { 87 | width: 81%; 88 | } 89 | 90 | .input-small { 91 | width: 150px; 92 | } 93 | 94 | #setting_div_table input[disabled] { 95 | cursor: not-allowed; 96 | background-color: #eee; 97 | } 98 | 99 | #send_test { 100 | display: inline-block; 101 | border: 1px solid #D1D1D1; 102 | background-color: #F7F7F7; 103 | text-align: center; 104 | text-decoration: none; 105 | color: #1B83EB; 106 | } 107 | 108 | #add_rpc { 109 | display: inline-block; 110 | border: 1px solid #D1D1D1; 111 | background-color: #F7F7F7; 112 | text-align: center; 113 | text-decoration: none; 114 | color: #1B83EB; 115 | margin-left: 5px; 116 | } 117 | 118 | #copyright { 119 | display: inline-block; 120 | } 121 | 122 | #setting_aria2_headers { 123 | overflow: auto; 124 | resize: none; 125 | width: 90%; 126 | height: 80px; 127 | border: 1px solid #C6C6C6; 128 | box-shadow: 0 0 3px #C6C6C6; 129 | -webkit-box-shadow: 0 0 3px #C6C6C6; 130 | } 131 | 132 | .button { 133 | background: #eeeeef; 134 | margin: 0 10px; 135 | text-decoration: none; 136 | font-size: 14px; 137 | padding: 0 50px; 138 | height: 37px; 139 | line-height: 37px; 140 | color: #333; 141 | border: 1px solid rgb(198, 198, 198); 142 | border-radius: 2px; 143 | display: inline-block; 144 | } 145 | 146 | .button:hover, 147 | .button:visited, 148 | .button:active { 149 | background: #fafafa; 150 | color: #333; 151 | text-decoration: none; 152 | } 153 | 154 | .save-button .menu { 155 | position: absolute; 156 | width: 98%; 157 | left: 0; 158 | top: 32px; 159 | background: #fff; 160 | text-align: center; 161 | border: 1px solid #aaa; 162 | display: none; 163 | z-index: 100; 164 | } 165 | 166 | .save-button .menu a { 167 | height: 24px; 168 | line-height: 24px; 169 | display: block; 170 | color: #666; 171 | } 172 | 173 | .save-button .menu a:hover { 174 | background: #e4eefe; 175 | cursor: pointer; 176 | text-decoration: none; 177 | } 178 | 179 | #download_ui > .content { 180 | padding: 10px 20px; 181 | height: auto; 182 | overflow: hidden; 183 | } 184 | 185 | #setting_div_table { 186 | width: 100%; 187 | border: 0; 188 | border-collapse: separate; 189 | border-spacing: 10px; 190 | display: table; 191 | background-color: rgb(250, 250, 250); 192 | } 193 | #aria2_list{ 194 | z-index: 9999; 195 | } -------------------------------------------------------------------------------- /chrome/src/home.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | //网盘主页导出 3 | /* 4 | 基本步骤是首先设定导出模式,文本模式的话 5 | 只需要初始化文本框即可,RPC模式要设置好 RPC地址 6 | 然后开始分析选中的文件 获取当前文件夹的所以文件id 7 | 然后进行比较,如果是文件 直接进行下载 如果是文件夹则递归查找 8 | 遇到文件就下载 遇到文件夹继续获取文件夹里面的内容 9 | 10 | */ 11 | //两种导出模式 RPC模式 和 TXT模式 12 | var MODE = "RPC"; 13 | var RPC_PATH = "http://localhost:6800/jsonrpc"; 14 | 15 | function getHashParameter(name) { 16 | var hash = window.location.hash; 17 | hash = hash.substr(1).split("&"); 18 | for (var i = 0; i < hash.length; i++) { 19 | var pair = hash[i]; 20 | var arr = pair.split("="); 21 | if (arr[0] == name) 22 | return decodeURIComponent(decodeURIComponent(arr[1])); 23 | } 24 | } 25 | 26 | var Downloader = (function() { 27 | var delay; 28 | 29 | var currentTaskId = 0; 30 | // Paths of folders to be processed. 31 | var folders = []; 32 | // { id: path } of files to be processed. 33 | var files = {}; 34 | var completedCount = 0; 35 | 36 | function getNextFile(taskId) { 37 | if (taskId != currentTaskId) 38 | return; 39 | 40 | if (folders.length != 0) { 41 | completedCount++; 42 | CORE.showToast("正在获取文件列表... " + completedCount + "/" + (completedCount + folders.length - 1), "MODE_SUCCESS"); 43 | 44 | var path = folders.pop(); 45 | $.getJSON("/api/list", { 46 | "dir": path, 47 | "bdstoken": yunData.MYBDSTOKEN, 48 | "channel": "chunlei", 49 | "clienttype": 0, 50 | "web": 1 51 | }).done(function(json) { 52 | setTimeout(function() { getNextFile(taskId) }, delay); 53 | 54 | if (json.errno != 0) { 55 | CORE.showToast("未知错误", "MODE_FAILURE"); 56 | console.log(json); 57 | return; 58 | } 59 | 60 | for (var i = 0; i < json.list.length; i++) { 61 | var item = json.list[i]; 62 | if (item.isdir) 63 | folders.push(item.path); 64 | else 65 | files[item.fs_id] = item.path; 66 | } 67 | }).fail(function(xhr) { 68 | CORE.showToast("网络请求失败", "MODE_FAILURE"); 69 | console.log(xhr); 70 | 71 | setTimeout(function() { getNextFile(taskId) }, delay); 72 | }); 73 | } else if (files.length != 0) { 74 | CORE.showToast("正在获取下载地址... ", "MODE_SUCCESS"); 75 | 76 | setFileData(files); 77 | downloader.reset(); 78 | } else { 79 | CORE.showToast("一个文件都没有哦", "MODE_CAUTION"); 80 | downloader.reset(); 81 | } 82 | } 83 | 84 | var downloader = {}; 85 | 86 | downloader.addFolder = function(path) { 87 | folders.push(path); 88 | }; 89 | 90 | downloader.addFile = function(id, path) { 91 | files[id] = path; 92 | }; 93 | 94 | downloader.start = function() { 95 | delay = parseInt(localStorage.getItem("rpc_delay")) || 300; 96 | currentTaskId = new Date().getTime(); 97 | getNextFile(currentTaskId); 98 | } 99 | 100 | downloader.reset = function() { 101 | currentTaskId = 0; 102 | folders = []; 103 | files = {}; 104 | completedCount = 0; 105 | }; 106 | 107 | return downloader; 108 | })(); 109 | 110 | var sign = btoa(new Function("return " + yunData.sign2)()(yunData.sign3, yunData.sign1)); 111 | 112 | function setFileData(files) { 113 | $.get("/api/download", { 114 | "type": "dlink", 115 | "fidlist": JSON.stringify(Object.keys(files)), 116 | "timestamp": yunData.timestamp, 117 | "sign": sign, 118 | "bdstoken": yunData.MYBDSTOKEN, 119 | "channel": "chunlei", 120 | "clienttype": 0, 121 | "web": 1, 122 | "app_id": 250528 123 | }, null, "json").done(function(json) { 124 | if (json.errno != 0) { 125 | CORE.showToast("未知错误", "MODE_FAILURE"); 126 | console.log(json); 127 | return; 128 | } 129 | 130 | var file_list = []; 131 | for (var i = 0; i < json.dlink.length; i++) { 132 | var item = json.dlink[i]; 133 | var path = files[item.fs_id]; 134 | file_list.push({ name: path.substr(pathPrefixLength), link: item.dlink }); 135 | } 136 | 137 | if (MODE == "TXT") { 138 | CORE.dataBox.show(); 139 | CORE.dataBox.fillData(file_list); 140 | } else { 141 | var paths = CORE.parseAuth(RPC_PATH); 142 | var rpc_list = CORE.aria2Data(file_list, paths[0], paths[2]); 143 | generateParameter(rpc_list); 144 | } 145 | }).fail(function(xhr) { 146 | CORE.showToast("网络请求失败", "MODE_FAILURE"); 147 | console.log(xhr); 148 | }); 149 | } 150 | 151 | window.addEventListener("message", function(event) { 152 | if (event.source != window) 153 | return; 154 | 155 | if (event.data.type == "selected") { 156 | Downloader.reset(); 157 | 158 | var selectedFile = event.data.data; 159 | if (selectedFile.length == 0) { 160 | CORE.showToast("请选择一下你要保存的文件哦", "failure"); 161 | return; 162 | } 163 | 164 | for (var i = 0; i < selectedFile.length; i++) { 165 | var item = selectedFile[i]; 166 | if (item.isdir) 167 | Downloader.addFolder(item.path); 168 | else 169 | Downloader.addFile(item.fs_id, item.path); 170 | } 171 | 172 | Downloader.start(); 173 | } 174 | }); 175 | 176 | var pathPrefixLength; 177 | 178 | function getSelected() { 179 | var path = getHashParameter("path"); 180 | var level = parseInt(localStorage.getItem("rpc_fold")) || 0; 181 | console.log(level); 182 | if (path == undefined || path == "/" || level == -1) { 183 | pathPrefixLength = 1; 184 | } else if (level == 0) { 185 | pathPrefixLength = path.length + 1; 186 | } 187 | 188 | window.postMessage({ "type": "get_selected" }, "*"); 189 | } 190 | //生成请求参数 发送给后台 进行 http请求 191 | function generateParameter(rpc_list) { 192 | var paths = CORE.parseAuth(RPC_PATH); 193 | for (var i = 0; i < rpc_list.length; i++) { 194 | var parameter = { url: paths[1], dataType: "json", type: "POST", data: JSON.stringify(rpc_list[i]), headers: { Authorization: paths[0] } }; 195 | CORE.sendToBackground("rpc_data", parameter, function(success) { 196 | if (success) 197 | CORE.showToast("下载成功!赶紧去看看吧~", "MODE_SUCCESS"); 198 | else 199 | CORE.showToast("下载失败!是不是没有开启aria2?", "MODE_FAILURE"); 200 | }); 201 | } 202 | } 203 | 204 | // Init 205 | var CORE = require("./core"); 206 | CORE.init(); 207 | CORE.requestCookies([{ url: "http://pan.baidu.com/", name: "BDUSS" }, { url: "http://pcs.baidu.com/", name: "pcsett" }]); 208 | 209 | var menu = CORE.addMenu.init("home"); 210 | menu.on("click", ".rpc_export_list", function() { 211 | MODE = "RPC"; 212 | RPC_PATH = $(this).data("id"); 213 | getSelected(); 214 | }); 215 | menu.on("click", "#aria2_download", function() { 216 | MODE = "TXT"; 217 | CORE.dataBox.init("home"); 218 | // When closing download dialog, cancel all delay feteching. 219 | CORE.dataBox.onClose(Downloader.reset); 220 | getSelected(); 221 | }); 222 | CORE.showToast("初始化成功!", "success"); 223 | })(); -------------------------------------------------------------------------------- /chrome/js/core.js: -------------------------------------------------------------------------------- 1 | !function(t){function e(n){if(a[n])return a[n].exports;var r=a[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var a={};return e.m=t,e.c=a,e.p="",e(0)}([function(t,e,a){function n(t,e){var a=new Object;a[t]=e,chrome.storage.sync.set(a,function(){})}"undefined"!=typeof browser&&(chrome=browser,chrome.storage.sync||(chrome.storage.sync=chrome.storage.local)),chrome.storage.sync.get(null,function(t){for(var e in t)localStorage.setItem(e,t[e])}),window.addEventListener("message",function(t){if(t.source==window){if(t.data.type&&"config_data"==t.data.type)for(var e in t.data.data)localStorage.setItem(e,t.data.data[e]),1==t.data.data.rpc_sync?n(e,t.data.data[e]):chrome.storage.sync.clear();t.data.type&&"clear_data"==t.data.type&&chrome.storage.sync.clear()}},!1);var r=function(){const t="netdisk;5.3.4.5;PC;PC-Windows;5.1.2600;WindowsBaiduYunGuanJia",e="http://pan.baidu.com/disk/home";var n=null,o=a(1);return{init:function(){window.showToast=o.showToast,window.sendToBackground=o.sendToBackground,window.copyText=o.copyText},escapeString:function(t){if(-1!=navigator.platform.indexOf("Win"))return t;var e="'"+t.replace("'","'\\''")+"'";return e},parseAuth:function(t){function e(t){return t.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1]}function a(t){return t.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/,"$1$2$3")}var n=e(t),r=[];n&&0!=n.indexOf("token:")&&(n="Basic "+btoa(n));var o=t.match(/^(?:[^#]*)(?:#(.*))?$/)[1];o&&o.split("&").forEach(function(t){t=t.split("="),t[0].length>1&&r.push([t[0],2==t.length?t[1]:"enabled"])});var i=a(t);return[n,i,r]},requestCookies:function(t){sendToBackground("get_cookies",t,function(t){return n=t})},getHeader:function(a){var r=[],o=localStorage.getItem("UA")||t,i=localStorage.getItem("headers"),d=localStorage.getItem("referer")||e;if(r.push("User-Agent: "+o),r.push("Referer: "+d),i)for(var s=i.split("\n"),l=0;l").attr("id","export_menu"),a=$("
").addClass("menu").attr("id","aria2_list").hide().appendTo(e),n=($("").text("导出下载").addClass("g-button-menu").attr("id","aria2_download").appendTo(a),$("").text("设置").addClass("g-button-menu").appendTo(a));return"home"==t?(e.addClass("g-dropdown-button button-open").prepend($("").addClass("g-button").append($("").addClass("g-button-right").append($("").addClass("icon icon-device-tool"),$("").addClass("text").text("导出下载")))),$(".g-dropdown-button").eq(3).after(e)):"share"==t?(e.addClass("save-button").append('导出下载'),$('span a[class="new-dbtn"]').parent().prepend(e)):"album"==t&&(e.addClass("save-button").append('导出下载'),$("#albumFileSaveKey, #emphsizeButton").parent().prepend(e)),e.mouseenter(function(){a.show()}),e.mouseleave(function(){a.hide()}),n.click(function(){0==$("#setting_div").length&&r.setting.init(),$("#setting_divtopmsg").html(""),$("#setting_div").show()}),this.update(),e},update:function(){$(".rpc_export_list").remove();for(var t=JSON.parse(localStorage.getItem("rpc_list")||'[{"name":"ARIA2 RPC","url":"http://localhost:6800/jsonrpc"}]');t.length>0;){var e=t.pop();$("").addClass("g-button-menu").attr("data-id",e.url).text(e.name).prependTo($("#aria2_list"))}}},setting:{init:function(){var t=this,e=document.createElement("div");if(e.id="setting_div",0!=$("#setting_div").length)return e.id;var a=['

导出设置

','
"];return e.innerHTML=a.join(""),document.body.appendChild(e),$("#setting_divtopmsg").html(""),t.update(),$("#setting_div").on("click",function(e){switch(e.target.id){case"setting_div_close":$("#setting_div").hide();break;case"apply":t.save(),setTimeout(function(){r.addMenu.update()},60),$("#setting_divtopmsg").html("设置已保存.");break;case"reset":localStorage.clear(),window.postMessage({type:"clear_data"},"*"),$("#setting_divtopmsg").html("设置已重置."),t.update();break;case"send_test":r.getVersion();break;case"add_rpc":var a=$(".rpc_list").length+1,n='';$(n).insertAfter($(".rpc_list").eq(a-2))}}),r.setCenter($("#setting_div")),e.id},save:function(){var t={};t.UA=document.getElementById("setting_aria2_useragent_input").value,t.rpc_delay=$("#rpc_delay").val(),t.referer=$("#setting_aria2_referer_input").val(),t.rpc_dir=$("#setting_aria2_dir").val(),t.rpc_fold=$("#rpc_fold").val(),t.rpc_headers=$("#setting_aria2_headers").val(),t.rpc_sync=$("#rpc_sync").prop("checked");for(var e=[],a=0;a<$(".rpc_list").length;a++){var n=a+1;""!=$("#rpc_url_"+n).val()&&""!=$("#rpc_name_"+n).val()&&e.push({name:$("#rpc_name_"+n).val(),url:$("#rpc_url_"+n).val()})}t.rpc_list=JSON.stringify(e),sendToBackground("config_data",t),window.postMessage({type:"config_data",data:t},"*")},update:function(){$("#rpc_delay").val(localStorage.getItem("rpc_delay")||"300"),$("#rpc_fold").val(localStorage.getItem("rpc_fold")||"0");var a=localStorage.getItem("rpc_sync");"false"==a?$("#rpc_sync").prop("checked",!1):$("#rpc_sync").prop("checked",!0),$("#setting_aria2_dir").val(localStorage.getItem("rpc_dir")),$("#setting_aria2_useragent_input").val(localStorage.getItem("UA")||t),$("#setting_aria2_referer_input").val(localStorage.getItem("referer")||e),$("#setting_aria2_headers").val(localStorage.getItem("rpc_headers"));var n=JSON.parse(localStorage.getItem("rpc_list")||'[{"name":"ARIA2 RPC","url":"http://localhost:6800/jsonrpc"}]');$(".rpc_list").remove();for(var r in n){var o=+r+1,i=1==o?'ADD RPC':"",d=''+i+"";$(".rpc_list").length>0?$(d).insertAfter($(".rpc_list").eq(o-2)):$(d).prependTo($("#setting_div_table>tbody"))}}},getVersion:function(){var t={jsonrpc:"2.0",method:"aria2.getVersion",id:1,params:[]},e=$("#rpc_url_1").val(),a=r.parseAuth(e);a[0]&&a[0].startsWith("token")&&t.params.unshift(a[0]);var n={url:a[1],dataType:"json",type:"POST",data:JSON.stringify(t)};a[0]&&a[0].startsWith("Basic")&&(n.headers={Authorization:a[0]}),sendToBackground("rpc_version",n,function(t){t?$("#send_test").html("ARIA2版本为: "+response.data.result.version):$("#send_test").html("错误,请查看是否开启Aria2")})},aria2Data:function(t,e,a){var n=[],r=this;if(t.length>0)for(var o=t.length,i=0;o>i;i++){var d={jsonrpc:"2.0",method:"aria2.addUri",id:(new Date).getTime(),params:[[t[i].link],{out:t[i].name,dir:localStorage.getItem("rpc_dir")||null,header:r.getHeader()}]};if(console.log(a),a.length>0){var s=d.params[d.params.length-1];a.forEach(function(t){s[t[0]]=t[1]})}e&&0==e.indexOf("token:")&&d.params.unshift(e),n.push(d),console.log(d)}return n},dataBox:{init:function(t){if(0!=$("#download_ui").length)return this;var e=$("
").attr("id","download_ui").append('

ARIA2导出

'),a=$("
").addClass("content").attr("id","content_ui").appendTo(e);e.hide().appendTo($("body")),a.empty();var n=$("
").css({"margin-bottom":"10px"}).appendTo(a);$("").attr("id","aria2c_btn").attr({download:"aria2c.down",target:"_blank"}).addClass("save-button ").html('存为aria2文件').appendTo(n),$("").attr("id","idm_btn").attr({download:"idm.txt",target:"_blank"}).addClass("save-button ").html('存为IDM文件').appendTo(n),$("").attr("id","download_txt_btn").attr({download:"download_link.txt",target:"_blank"}).addClass("save-button ").html('保存下载链接').appendTo(n),$("").attr("id","copy_txt_btn").attr({href:"javascript:void(0);",data:""}).addClass("save-button ").html('拷贝下载链接').appendTo(n),$("', 195 | "", 196 | "", 197 | '
', 198 | '", 199 | '', 200 | "
", 201 | "
" 202 | ]; 203 | setting_div.innerHTML = html_.join(""); 204 | document.body.appendChild(setting_div); 205 | $("#setting_divtopmsg").html(""); 206 | self.update(); 207 | $("#setting_div").on("click", function (event) { 208 | switch (event.target.id) { 209 | case "setting_div_close": 210 | $("#setting_div").hide(); 211 | break; 212 | case "apply": 213 | self.save(); 214 | setTimeout(function () { 215 | CORE.addMenu.update(); 216 | }, 60); 217 | $("#setting_divtopmsg").html("设置已保存."); 218 | break; 219 | case "reset": 220 | localStorage.clear(); 221 | window.postMessage({ type: "clear_data" }, "*"); 222 | $("#setting_divtopmsg").html("设置已重置."); 223 | self.update(); 224 | break; 225 | case "send_test": 226 | CORE.getVersion(); 227 | break; 228 | case "add_rpc": 229 | var num = $(".rpc_list").length + 1; 230 | var row = ''; 231 | $(row).insertAfter($(".rpc_list").eq(num - 2)); 232 | break; 233 | default: 234 | //console.log(event); 235 | 236 | } 237 | }); 238 | CORE.setCenter($("#setting_div")); 239 | return setting_div.id; 240 | }, 241 | //保存配置数据 242 | save: function () { 243 | var config_data = {}; 244 | config_data["UA"] = document.getElementById("setting_aria2_useragent_input").value; 245 | config_data["rpc_delay"] = $("#rpc_delay").val(); 246 | config_data["referer"] = $("#setting_aria2_referer_input").val(); 247 | config_data["rpc_dir"] = $("#setting_aria2_dir").val(); 248 | config_data["rpc_fold"] = $("#rpc_fold").val(); 249 | config_data["rpc_headers"] = $("#setting_aria2_headers").val(); 250 | config_data["rpc_sync"] = $("#rpc_sync").prop("checked"); 251 | var rpc_list = []; 252 | for (var i = 0; i < $(".rpc_list").length; i++) { 253 | var num = i + 1; 254 | if ($("#rpc_url_" + num).val() != "" && $("#rpc_name_" + num).val() != "") { 255 | rpc_list.push({ "name": $("#rpc_name_" + num).val(), "url": $("#rpc_url_" + num).val() }); 256 | } 257 | } 258 | config_data["rpc_list"] = JSON.stringify(rpc_list); 259 | CORE.sendToBackground("config_data", config_data); 260 | window.postMessage({ type: "config_data", data: config_data }, "*"); 261 | }, 262 | //根据配置数据 更新 设置菜单 263 | update: function () { 264 | $("#rpc_delay").val((localStorage.getItem("rpc_delay") || "300")); 265 | $("#rpc_fold").val((localStorage.getItem("rpc_fold") || "0")); 266 | var rpc_sync = localStorage.getItem("rpc_sync"); 267 | if (rpc_sync == "false") { 268 | $("#rpc_sync").prop("checked", false); 269 | } else { 270 | $("#rpc_sync").prop("checked", true); 271 | } 272 | $("#setting_aria2_dir").val(localStorage.getItem("rpc_dir")); 273 | $("#setting_aria2_useragent_input").val(localStorage.getItem("UA") || defaultUA); 274 | $("#setting_aria2_referer_input").val(localStorage.getItem("referer") || defaultreferer); 275 | $("#setting_aria2_headers").val(localStorage.getItem("rpc_headers")); 276 | var rpc_list = JSON.parse(localStorage.getItem("rpc_list") || '[{"name":"ARIA2 RPC","url":"http://localhost:6800/jsonrpc"}]'); 277 | $(".rpc_list").remove(); 278 | for (var i in rpc_list) { 279 | var num = (+i) + 1; 280 | var addBtn = 1 == num ? 'ADD RPC' : ""; 281 | var row = '' + addBtn + ""; 282 | if ($(".rpc_list").length > 0) { 283 | $(row).insertAfter($(".rpc_list").eq(num - 2)); 284 | } else { 285 | $(row).prependTo($("#setting_div_table>tbody")); 286 | } 287 | } 288 | } 289 | }, 290 | copyText:function(text){ 291 | var input = document.createElement("textarea"); 292 | document.body.appendChild(input); 293 | input.style.position = "fixed"; 294 | input.style.left = "0"; 295 | input.style.top = "0"; 296 | input.value = text; 297 | input.focus(); 298 | input.select(); 299 | var result = document.execCommand("copy"); 300 | input.remove(); 301 | console.log(result); 302 | if (result) 303 | this.showToast("拷贝成功~", "MODE_SUCCESS"); 304 | else 305 | this.showToast("拷贝失败 QAQ", "MODE_FAILURE"); 306 | }, 307 | // names format [{"url": "http://pan.baidu.com/", "name": "BDUSS"},{"url": "http://pcs.baidu.com/", "name": "pcsett"}] 308 | requestCookies: function (names) { 309 | this.sendToBackground("get_cookies", names, function(value) {cookies = value}); 310 | }, 311 | //获取 http header信息 312 | getHeader: function (type) { 313 | var addheader = []; 314 | var UA = localStorage.getItem("UA") || defaultUA; 315 | var headers = localStorage.getItem("headers"); 316 | var referer = localStorage.getItem("referer") || defaultreferer; 317 | addheader.push("User-Agent: " + UA); 318 | addheader.push("Referer: " + referer); 319 | if (headers) { 320 | var text = headers.split("\n"); 321 | for (var i = 0; i < text.length; i++) { 322 | addheader.push(text[i]); 323 | } 324 | } 325 | if (cookies) { 326 | var format_cookies = []; 327 | for (var key in cookies) { 328 | format_cookies.push(key + "=" + cookies[key]); 329 | } 330 | addheader.push("Cookie: " + format_cookies.join(";")); 331 | } 332 | 333 | var header = ""; 334 | if (type == "aria2c_line") { 335 | for (i = 0; i < addheader.length; i++) { 336 | header += " --header " + JSON.stringify(addheader[i]); 337 | } 338 | return header; 339 | } else if (type == "aria2c_txt") { 340 | for (i = 0; i < addheader.length; i++) { 341 | header += " header=" + (addheader[i]) + " \n"; 342 | } 343 | return header; 344 | } else if (type == "idm_txt") { 345 | for (i = 0; i < addheader.length; i++) { 346 | if(addheader[i].indexOf("Referer") != 0){ 347 | header += (addheader[i].split(": ")[0].toLowerCase()+": "+addheader[i].split(": ")[1]) + "\n"; 348 | } 349 | } 350 | 351 | return header.replace(/\n$/, ""); 352 | } else { 353 | return addheader; 354 | } 355 | 356 | }, 357 | //把要下载的link和name作为数组对象传过来 358 | aria2Data: function (file_list, token, options) { 359 | var rpc_list = []; 360 | var self = this; 361 | if (file_list.length > 0) { 362 | var length = file_list.length; 363 | for (var i = 0; i < length; i++) { 364 | var rpc_data = { 365 | "jsonrpc": "2.0", 366 | "method": "aria2.addUri", 367 | "id": new Date().getTime(), 368 | "params": [[file_list[i].link], { 369 | "out": file_list[i].name, 370 | "dir": localStorage.getItem("rpc_dir") || null, 371 | "header": self.getHeader() 372 | }] 373 | }; 374 | console.log(options); 375 | if (options.length > 0) { 376 | var params = rpc_data.params[rpc_data.params.length - 1]; 377 | options.forEach(function (item) { 378 | params[item[0]] = item[1]; 379 | }); 380 | } 381 | if (token && token.indexOf("token:") == 0) { 382 | rpc_data.params.unshift(token); 383 | } 384 | 385 | rpc_list.push(rpc_data); 386 | console.log(rpc_data); 387 | } 388 | } 389 | return rpc_list; 390 | }, 391 | //文本模式的导出数据框 392 | dataBox: { 393 | init: function (type) { 394 | if ($("#download_ui").length != 0) 395 | return this; 396 | var download_ui = $("
").attr("id", "download_ui").append('

ARIA2导出

'); 397 | var content_ui = $("
").addClass("content").attr("id", "content_ui").appendTo(download_ui); 398 | download_ui.hide().appendTo($("body")); 399 | content_ui.empty(); 400 | var download_menu = $("
").css({ "margin-bottom": "10px" }).appendTo(content_ui); 401 | $("").attr("id", "aria2c_btn").attr({ "download": "aria2c.down", "target": "_blank" }).addClass("save-button ").html('存为aria2文件').appendTo(download_menu); 402 | $("").attr("id", "idm_btn").attr({ "download": "idm.ef2", "target": "_blank" }).addClass("save-button ").html('存为IDM文件').appendTo(download_menu); 403 | $("").attr("id", "download_txt_btn").attr({ "download": "download_link.txt", "target": "_blank" }).addClass("save-button ").html('保存下载链接').appendTo(download_menu); 404 | $("").attr("id", "copy_txt_btn").attr({ "href": "javascript:void(0);", "data": "" }).addClass("save-button ").html('拷贝下载链接').appendTo(download_menu); 405 | // Disable spellcheck and resize for textarea. 406 | $("', 469 | "", 470 | "", 471 | '
', 472 | '", 473 | '', 474 | "
", 475 | "
" 476 | ]; 477 | setting_div.innerHTML = html_.join(""); 478 | document.body.appendChild(setting_div); 479 | $("#setting_divtopmsg").html(""); 480 | self.update(); 481 | $("#setting_div").on("click", function (event) { 482 | switch (event.target.id) { 483 | case "setting_div_close": 484 | $("#setting_div").hide(); 485 | break; 486 | case "apply": 487 | self.save(); 488 | setTimeout(function () { 489 | CORE.addMenu.update(); 490 | }, 60); 491 | $("#setting_divtopmsg").html("设置已保存."); 492 | break; 493 | case "reset": 494 | localStorage.clear(); 495 | window.postMessage({ type: "clear_data" }, "*"); 496 | $("#setting_divtopmsg").html("设置已重置."); 497 | self.update(); 498 | break; 499 | case "send_test": 500 | CORE.getVersion(); 501 | break; 502 | case "add_rpc": 503 | var num = $(".rpc_list").length + 1; 504 | var row = ''; 505 | $(row).insertAfter($(".rpc_list").eq(num - 2)); 506 | break; 507 | default: 508 | //console.log(event); 509 | 510 | } 511 | }); 512 | CORE.setCenter($("#setting_div")); 513 | return setting_div.id; 514 | }, 515 | //保存配置数据 516 | save: function () { 517 | var config_data = {}; 518 | config_data["UA"] = document.getElementById("setting_aria2_useragent_input").value; 519 | config_data["rpc_delay"] = $("#rpc_delay").val(); 520 | config_data["referer"] = $("#setting_aria2_referer_input").val(); 521 | config_data["rpc_dir"] = $("#setting_aria2_dir").val(); 522 | config_data["rpc_fold"] = $("#rpc_fold").val(); 523 | config_data["rpc_headers"] = $("#setting_aria2_headers").val(); 524 | config_data["rpc_sync"] = $("#rpc_sync").prop("checked"); 525 | var rpc_list = []; 526 | for (var i = 0; i < $(".rpc_list").length; i++) { 527 | var num = i + 1; 528 | if ($("#rpc_url_" + num).val() != "" && $("#rpc_name_" + num).val() != "") { 529 | rpc_list.push({ "name": $("#rpc_name_" + num).val(), "url": $("#rpc_url_" + num).val() }); 530 | } 531 | } 532 | config_data["rpc_list"] = JSON.stringify(rpc_list); 533 | CORE.sendToBackground("config_data", config_data); 534 | window.postMessage({ type: "config_data", data: config_data }, "*"); 535 | }, 536 | //根据配置数据 更新 设置菜单 537 | update: function () { 538 | $("#rpc_delay").val((localStorage.getItem("rpc_delay") || "300")); 539 | $("#rpc_fold").val((localStorage.getItem("rpc_fold") || "0")); 540 | var rpc_sync = localStorage.getItem("rpc_sync"); 541 | if (rpc_sync == "false") { 542 | $("#rpc_sync").prop("checked", false); 543 | } else { 544 | $("#rpc_sync").prop("checked", true); 545 | } 546 | $("#setting_aria2_dir").val(localStorage.getItem("rpc_dir")); 547 | $("#setting_aria2_useragent_input").val(localStorage.getItem("UA") || defaultUA); 548 | $("#setting_aria2_referer_input").val(localStorage.getItem("referer") || defaultreferer); 549 | $("#setting_aria2_headers").val(localStorage.getItem("rpc_headers")); 550 | var rpc_list = JSON.parse(localStorage.getItem("rpc_list") || '[{"name":"ARIA2 RPC","url":"http://localhost:6800/jsonrpc"}]'); 551 | $(".rpc_list").remove(); 552 | for (var i in rpc_list) { 553 | var num = (+i) + 1; 554 | var addBtn = 1 == num ? 'ADD RPC' : ""; 555 | var row = '' + addBtn + ""; 556 | if ($(".rpc_list").length > 0) { 557 | $(row).insertAfter($(".rpc_list").eq(num - 2)); 558 | } else { 559 | $(row).prependTo($("#setting_div_table>tbody")); 560 | } 561 | } 562 | } 563 | }, 564 | copyText:function(text){ 565 | var input = document.createElement("textarea"); 566 | document.body.appendChild(input); 567 | input.style.position = "fixed"; 568 | input.style.left = "0"; 569 | input.style.top = "0"; 570 | input.value = text; 571 | input.focus(); 572 | input.select(); 573 | var result = document.execCommand("copy"); 574 | input.remove(); 575 | console.log(result); 576 | if (result) 577 | this.showToast("拷贝成功~", "MODE_SUCCESS"); 578 | else 579 | this.showToast("拷贝失败 QAQ", "MODE_FAILURE"); 580 | }, 581 | // names format [{"url": "http://pan.baidu.com/", "name": "BDUSS"},{"url": "http://pcs.baidu.com/", "name": "pcsett"}] 582 | requestCookies: function (names) { 583 | this.sendToBackground("get_cookies", names, function(value) {cookies = value}); 584 | }, 585 | //获取 http header信息 586 | getHeader: function (type) { 587 | var addheader = []; 588 | var UA = localStorage.getItem("UA") || defaultUA; 589 | var headers = localStorage.getItem("headers"); 590 | var referer = localStorage.getItem("referer") || defaultreferer; 591 | addheader.push("User-Agent: " + UA); 592 | addheader.push("Referer: " + referer); 593 | if (headers) { 594 | var text = headers.split("\n"); 595 | for (var i = 0; i < text.length; i++) { 596 | addheader.push(text[i]); 597 | } 598 | } 599 | if (cookies) { 600 | var format_cookies = []; 601 | for (var key in cookies) { 602 | format_cookies.push(key + "=" + cookies[key]); 603 | } 604 | addheader.push("Cookie: " + format_cookies.join(";")); 605 | } 606 | 607 | var header = ""; 608 | if (type == "aria2c_line") { 609 | for (i = 0; i < addheader.length; i++) { 610 | header += " --header " + JSON.stringify(addheader[i]); 611 | } 612 | return header; 613 | } else if (type == "aria2c_txt") { 614 | for (i = 0; i < addheader.length; i++) { 615 | header += " header=" + (addheader[i]) + " \n"; 616 | } 617 | return header; 618 | } else if (type == "idm_txt") { 619 | for (i = 0; i < addheader.length; i++) { 620 | if(addheader[i].indexOf("Referer") != 0){ 621 | header += (addheader[i].split(": ")[0].toLowerCase()+": "+addheader[i].split(": ")[1]) + "\n"; 622 | } 623 | } 624 | 625 | return header.replace(/\n$/, ""); 626 | } else { 627 | return addheader; 628 | } 629 | 630 | }, 631 | //把要下载的link和name作为数组对象传过来 632 | aria2Data: function (file_list, token, options) { 633 | var rpc_list = []; 634 | var self = this; 635 | if (file_list.length > 0) { 636 | var length = file_list.length; 637 | for (var i = 0; i < length; i++) { 638 | var rpc_data = { 639 | "jsonrpc": "2.0", 640 | "method": "aria2.addUri", 641 | "id": new Date().getTime(), 642 | "params": [[file_list[i].link], { 643 | "out": file_list[i].name, 644 | "dir": localStorage.getItem("rpc_dir") || null, 645 | "header": self.getHeader() 646 | }] 647 | }; 648 | console.log(options); 649 | if (options.length > 0) { 650 | var params = rpc_data.params[rpc_data.params.length - 1]; 651 | options.forEach(function (item) { 652 | params[item[0]] = item[1]; 653 | }); 654 | } 655 | if (token && token.indexOf("token:") == 0) { 656 | rpc_data.params.unshift(token); 657 | } 658 | 659 | rpc_list.push(rpc_data); 660 | console.log(rpc_data); 661 | } 662 | } 663 | return rpc_list; 664 | }, 665 | //文本模式的导出数据框 666 | dataBox: { 667 | init: function (type) { 668 | if ($("#download_ui").length != 0) 669 | return this; 670 | var download_ui = $("
").attr("id", "download_ui").append('

ARIA2导出

'); 671 | var content_ui = $("
").addClass("content").attr("id", "content_ui").appendTo(download_ui); 672 | download_ui.hide().appendTo($("body")); 673 | content_ui.empty(); 674 | var download_menu = $("
").css({ "margin-bottom": "10px" }).appendTo(content_ui); 675 | $("").attr("id", "aria2c_btn").attr({ "download": "aria2c.down", "target": "_blank" }).addClass("save-button ").html('存为aria2文件').appendTo(download_menu); 676 | $("").attr("id", "idm_btn").attr({ "download": "idm.ef2", "target": "_blank" }).addClass("save-button ").html('存为IDM文件').appendTo(download_menu); 677 | $("").attr("id", "download_txt_btn").attr({ "download": "download_link.txt", "target": "_blank" }).addClass("save-button ").html('保存下载链接').appendTo(download_menu); 678 | $("").attr("id", "copy_txt_btn").attr({ "href": "javascript:void(0);", "data": "" }).addClass("save-button ").html('拷贝下载链接').appendTo(download_menu); 679 | // Disable spellcheck and resize for textarea. 680 | $("