-
Notifications
You must be signed in to change notification settings - Fork 0
/
duokan.js
46 lines (44 loc) · 1.61 KB
/
duokan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ==UserScript==
// @name 多看阅读复制
// @namespace https://github.com/YujiaCheng1996/DuokanJSCopy
// @version 0.1
// @description 多看阅读复制文本
// @author YujiaCheng1996
// @match http://www.duokan.com/reader/www/app.html?id=*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.body.addEventListener('copy', function (e) {
var text = document.getElementById("button-copy").getAttribute("text");
var addExtHTML = function(e) {
if (!e) {
clipboardData.setData('Text', text);
} else if (e.clipboardData) {
e.preventDefault();
e.clipboardData.setData('text/plain', text);
} else {
var selection = window.getSelection();
var body = document.getElementsByTagName('body')[0];
var extContent = document.createElement('div');
extContent.style.position = 'absolute';
extContent.style.left = '-99999px';
extContent.innerHTML = text;
body.appendChild(extContent);
selection.select(extContent);
window.setTimeout(function() {
body.removeChild(extContent);
body = selection = null;
},
0);
}
};
if (typeof(clipboardData) !== 'undefined') {
document.body.oncopy = function() {
setTimeout(addExtHTML, 50);
};
} else {
document.oncopy = addExtHTML;
}
});
})();