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
|
// 提取CSDN博文的正文内容
function extractArticleContent() {
// 查找文章内容所在的元素,通常在 class 为 'article_content' 的 div 中
var articleContentElement = document.querySelector('.article_content');
if (articleContentElement) {
// 获取文章内容
var articleContent = articleContentElement.innerText;
// 创建文本框元素
var textBox = document.createElement('textarea');
// 设置文本框的内容为文章内容
textBox.value = articleContent;
// 设置文本框样式
textBox.style.width = '100%';
textBox.style.height = '300px';
textBox.style.resize = 'none';
// 将文本框添加到页面中
document.body.appendChild(textBox);
// 将文章内容复制到剪切板
copyToClipboard(articleContent);
// 弹出提示框提示用户内容已经提取
alert('文章内容已提取到文本框中,并已复制到剪切板,您可以复制保存。');
} else {
alert('未找到文章内容');
}
}
// 将内容复制到剪切板
function copyToClipboard(content) {
// 创建临时文本框元素
var tempTextArea = document.createElement('textarea');
// 将内容设置为临时文本框的值
tempTextArea.value = content;
// 将临时文本框添加到页面中
document.body.appendChild(tempTextArea);
// 选择临时文本框的内容
tempTextArea.select();
// 执行复制操作
document.execCommand('copy');
// 移除临时文本框元素
document.body.removeChild(tempTextArea);
}
// 调用提取文章内容的函数
extractArticleContent();
|