-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwlzy.js
123 lines (108 loc) · 4.74 KB
/
wlzy.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
120
121
122
123
// ==UserScript==
// @name 卧龙资源复制全部
// @namespace http://github.com/byhooi
// @version 2.0
// @description 卧龙资源修复复制全部按钮,添加视觉反馈,优化加载速度
// @match https://wolongzy.cc/.*
// @grant none
// @run-at document-start
// @downloadURL https://raw.githubusercontent.com/byhooi/JS/master/wlzy.js
// @updateURL https://raw.githubusercontent.com/byhooi/JS/master/wlzy.js
// ==/UserScript==
(function() {
'use strict';
function initScript() {
async function copyContent(content, button) {
try {
await navigator.clipboard.writeText(content);
const originalText = button.innerText;
const originalColor = button.style.backgroundColor;
button.innerText = '复制成功!';
button.style.backgroundColor = '#45a049';
setTimeout(() => {
button.innerText = originalText;
button.style.backgroundColor = originalColor;
}, 2000);
} catch (err) {
console.error('复制失败:', err);
button.innerText = '复制失败';
button.style.backgroundColor = '#ff4444';
setTimeout(() => {
button.innerText = '复制全部';
button.style.backgroundColor = '#4CAF50';
}, 2000);
}
}
function styleButton(button) {
button.style.cssText = `
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
`;
}
function setupCopyAllButton() {
const copyAllButton = document.querySelector('.copy_checked');
if (copyAllButton) {
styleButton(copyAllButton);
copyAllButton.innerText = '复制全部';
copyAllButton.addEventListener('click', async function() {
let content = '';
const videoItems = document.querySelectorAll('.playlist .text-style');
videoItems.forEach((item) => {
const titleElement = item.querySelector('.copy_text');
const linkElement = item.querySelector('font[color="red"]');
if (titleElement && linkElement) {
const title = titleElement.getAttribute('title');
const link = linkElement.textContent.split('$')[1];
content += `${title} ${link}\n`;
}
});
await copyContent(content, copyAllButton);
});
}
}
function setupSingleCopyLinks() {
document.addEventListener('click', async function(event) {
let target = event.target;
if (target.matches('.text-style .copy_text font[color="red"]') || target.closest('.text-style .copy_text font[color="red"]')) {
event.preventDefault();
let titleElement = target.closest('.text-style').querySelector('.copy_text');
if (!titleElement) {
console.error('未找到标题元素');
return;
}
const title = titleElement.getAttribute('title');
const linkText = target.textContent;
const link = linkText.split('$')[1];
const tempButton = document.createElement('button');
styleButton(tempButton);
tempButton.innerText = '复制';
target.parentNode.insertBefore(tempButton, target.nextSibling);
await copyContent(`${title} ${link}`, tempButton);
setTimeout(() => {
tempButton.remove();
}, 2000);
}
});
}
function scrollToBottom() {
const contentDiv = document.querySelector('#content .playlist ul');
if (contentDiv) {
contentDiv.scrollTop = contentDiv.scrollHeight;
}
}
setupCopyAllButton();
setupSingleCopyLinks();
scrollToBottom();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initScript);
} else {
initScript();
}
})();