|
7 | 7 | // @license MIT
|
8 | 8 | // @supportURL https://github.com/gxvv/ex-baiduyunpan/issues
|
9 | 9 | // @date 01/01/2017
|
10 |
| -// @modified 01/10/2017 |
| 10 | +// @modified 01/18/2017 |
11 | 11 | // @match *://pan.baidu.com/disk/home*
|
12 | 12 | // @match *://yun.baidu.com/disk/home*
|
13 | 13 | // @match *://pan.baidu.com/s/*
|
|
18 | 18 | // @run-at document-end
|
19 | 19 | // @grant unsafeWindow
|
20 | 20 | // @grant GM_addStyle
|
21 |
| -// @grant GM_setClipboard |
22 | 21 | // @grant GM_info
|
| 22 | +// @require https://cdn.bootcss.com/clipboard.js/1.5.16/clipboard.min.js |
23 | 23 | // ==/UserScript==
|
24 | 24 |
|
25 | 25 | (function(require, define) {
|
|
123 | 123 | }, {
|
124 | 124 | title: '复制链接',
|
125 | 125 | 'click': function() {
|
126 |
| - |
127 | 126 | var selectedList = ctx.list.getSelected();
|
128 | 127 | if (selectedList.length === 0) return ctx.ui.tip({
|
129 | 128 | mode: 'caution',
|
|
182 | 181 | });
|
183 | 182 | });
|
184 | 183 | Promise.all(promises).then(function(result) {
|
| 184 | + ctx.ui.hideTip(); |
185 | 185 | var dlinks = [];
|
186 | 186 | var needToRetry = result.filter(function(e) {
|
187 | 187 | return e.errno !== 0;
|
188 | 188 | });
|
189 | 189 | if (needToRetry.length > 0) {
|
190 |
| - dServ.dialog && dServ.dialog.destory(); |
| 190 | + try { |
| 191 | + dServ.dialog.hide(); |
| 192 | + } catch (ex) {} |
191 | 193 | ctx.ui.tip({
|
192 | 194 | mode: 'caution',
|
193 | 195 | msg: needToRetry.length + '个文件请求链接失败'
|
|
209 | 211 | mode: 'caution',
|
210 | 212 | msg: '复制失败:未获取到链接'
|
211 | 213 | });
|
212 |
| - GM_setClipboard(dlinks.join('\n')); |
213 |
| - ctx.ui.tip({ |
214 |
| - mode: 'success', |
215 |
| - msg: '复制成功' + dlinks.length + '个文件' |
| 214 | + |
| 215 | + var clipboard = new Clipboard('.btn'); |
| 216 | + clipboard.on('success', function(e) { |
| 217 | + ctx.ui.tip({ |
| 218 | + mode: 'success', |
| 219 | + msg: '复制成功' + dlinks.length + '个文件' |
| 220 | + }); |
| 221 | + e.clearSelection(); |
| 222 | + dialog.hide(); |
| 223 | + clipboard.destroy(); |
| 224 | + }); |
| 225 | + clipboard.on('error', function(e) { |
| 226 | + ctx.ui.tip({ |
| 227 | + mode: 'caution', |
| 228 | + msg: '复制失败' |
| 229 | + }); |
| 230 | + }); |
| 231 | + var text = '<textarea id="bar" rows="' + (dlinks.length + 1) + '" style="width:100%;white-space: nowrap;">' + dlinks.join('\n') + '</textarea>'; |
| 232 | + var dialog = ctx.ui.confirm({ |
| 233 | + title: '复制链接', |
| 234 | + body: text, |
| 235 | + sureText: '复制', |
| 236 | + onClose: function() { |
| 237 | + clipboard && clipboard.destory && clipboard.destroy(); |
| 238 | + } |
216 | 239 | });
|
| 240 | + dialog.buttonIns[0].dom.attr({ |
| 241 | + 'data-clipboard-action': 'copy', |
| 242 | + 'data-clipboard-target': '#bar' |
| 243 | + }).addClass('btn').off(); |
217 | 244 | }).catch(function(e) {
|
218 | 245 | showError(e);
|
219 | 246 | });
|
|
0 commit comments