-
Notifications
You must be signed in to change notification settings - Fork 1
/
dmhy_helper.js
119 lines (119 loc) · 4.09 KB
/
dmhy_helper.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
javascript:(function(){
var hosts=['share.dmhy.org'];
if(hosts.indexOf(window.location.host)===-1){
window.location.href='https://share.dmhy.org';
return;
}
if(document.readyState!=='complete'){
setTimeout(function(){
alert('请等待页面加载完成');
},0);
return;
}
if(document.getElementsByClassName('el_remove').length>0){return;}
var table=document.getElementById('topic_list');
if(!table){return;}
var rows=table.rows;
if(!rows){return;}
var el_parent=table.parentElement;
if(!el_parent){return;}
el_parent=el_parent.parentElement;
if(!el_parent){return;}
var divs=el_parent.getElementsByClassName('nav_title');
var flag_all=false;
var downloads=[];
function func_all(){
var cbs=table.getElementsByClassName('cb_select');
if(cbs.length===0){
return;
}
flag_all=!flag_all;
for(var i=0;i<cbs.length;++i){
cbs[i].checked=flag_all;
}
};
function func_copy (e){
e.clipboardData.setData('text/plain', downloads.join('\r'));
e.preventDefault();
document.removeEventListener('copy', func_copy, true);
setTimeout(function(){
alert('已复制'+downloads.length+'项到剪贴板!');
},0);
};
function func_clear (){
var els=document.getElementsByClassName('el_remove');
while(els.length){
els[0].remove();
}
};
function func_confirm (){
var cbs=table.getElementsByClassName('cb_select');
var array=[];
for(var i=0;i<cbs.length;++i){
var cb=cbs[i];
if(cb.checked){
var data=cb.getAttribute('data');
if(data){
array.push(data);
}
}
}
if(array.length>0){
var links=document.getElementsByClassName('download-arrow');
if(links.length>0){
downloads=[];
for(var i=0;i<array.length;++i){
var link=links[array[i]];
if(link){
var href=link.getAttribute('href');
if(href){
downloads.push(href);
}
}
}
}
}
document.addEventListener('copy',func_copy,true);
try{
document.execCommand('copy');
} finally {
if(typeof(func_clear)==='function'){
func_clear();
}
}
};
for(var i=0;i<rows.length;++i){
var row=rows[i];
var html='';
if(i===0){
html+='<th class="{sorter:false} el_remove" width="24px" nowrap="nowrap"><a href="javascript:;" id="all">全选</a></th>';
} else{
html+='<td width="24px" class="el_remove" align="center" nowrap="nowrap">';
html+='<input type="checkbox" data="'+(i-1)+'" class="cb_select" />';
html+='</td>';
}
row.insertAdjacentHTML('afterBegin',html);
}
var btn_all=document.getElementById('all');
if(btn_all){
btn_all.addEventListener('click',func_all);
}
for(var i=0;i<divs.length;++i){
var div=divs[i];
var id_confirm='btn_confirm_'+i;
var id_cancel='btn_cancel_'+i;
var html='<div class="fl el_remove">';
html+='<a href="javascript:;" id="'+id_confirm+'">确认</a> ';
html+='<a href="javascript:;" id="'+id_cancel+'">取消</a> ';
html+='</div>';
div.insertAdjacentHTML('afterBegin',html);
var btn_confirm=document.getElementById(id_confirm);
if(btn_confirm){
btn_confirm.addEventListener('click',func_confirm);
}
var btn_cancel=document.getElementById(id_cancel);
if(btn_cancel){
btn_cancel.addEventListener('click',func_clear);
}
}
})();