Skip to content

Commit 71b6efe

Browse files
committed
➕ Add clipboard.js.
1 parent 8a3c476 commit 71b6efe

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

EX-baiduyunpan.user.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// @license MIT
88
// @supportURL https://github.com/gxvv/ex-baiduyunpan/issues
99
// @date 01/01/2017
10-
// @modified 01/10/2017
10+
// @modified 01/18/2017
1111
// @match *://pan.baidu.com/disk/home*
1212
// @match *://yun.baidu.com/disk/home*
1313
// @match *://pan.baidu.com/s/*
@@ -18,8 +18,8 @@
1818
// @run-at document-end
1919
// @grant unsafeWindow
2020
// @grant GM_addStyle
21-
// @grant GM_setClipboard
2221
// @grant GM_info
22+
// @require https://cdn.bootcss.com/clipboard.js/1.5.16/clipboard.min.js
2323
// ==/UserScript==
2424

2525
(function(require, define) {
@@ -123,7 +123,6 @@
123123
}, {
124124
title: '复制链接',
125125
'click': function() {
126-
127126
var selectedList = ctx.list.getSelected();
128127
if (selectedList.length === 0) return ctx.ui.tip({
129128
mode: 'caution',
@@ -182,12 +181,15 @@
182181
});
183182
});
184183
Promise.all(promises).then(function(result) {
184+
ctx.ui.hideTip();
185185
var dlinks = [];
186186
var needToRetry = result.filter(function(e) {
187187
return e.errno !== 0;
188188
});
189189
if (needToRetry.length > 0) {
190-
dServ.dialog && dServ.dialog.destory();
190+
try {
191+
dServ.dialog.hide();
192+
} catch (ex) {}
191193
ctx.ui.tip({
192194
mode: 'caution',
193195
msg: needToRetry.length + '个文件请求链接失败'
@@ -209,11 +211,36 @@
209211
mode: 'caution',
210212
msg: '复制失败:未获取到链接'
211213
});
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+
}
216239
});
240+
dialog.buttonIns[0].dom.attr({
241+
'data-clipboard-action': 'copy',
242+
'data-clipboard-target': '#bar'
243+
}).addClass('btn').off();
217244
}).catch(function(e) {
218245
showError(e);
219246
});

0 commit comments

Comments
 (0)