[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url] 自动提取激活码
// [url=home.php?mod=space&uid=467642]@namespace[/url] http://tampermonkey.net/
// [url=home.php?mod=space&uid=1248337]@version[/url] 0.1
// @description 自动提取激活码
// [url=home.php?mod=space&uid=686208]@AuThor[/url] superychen
// [url=home.php?mod=space&uid=195849]@match[/url] http://bot93001.qch86.top/activation
// @match http://bot93001.qch86.top/activation?*
// [url=home.php?mod=space&uid=609072]@grant[/url] none
// ==/UserScript==
(function () {
'use strict';
// 创建UI元素的通用函数
function createUIElement(type, options) {
const element = document.createElement(type);
Object.assign(element, options.props || {});
element.style.cssText = options.style || '';
if (options.text) element.textContent = options.text;
return element;
}
// 创建UI组件
const ui = {
button: createUIElement('button', {
text: '开始提取',
style: `
position: fixed;
right: 20px;
top: 20px;
z-index: 9999;
padding: 10px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
`
}),
input: createUIElement('input', {
props: { type: 'number', value: '2', min: '1' },
style: `
position: fixed;
right: 120px;
top: 20px;
z-index: 9999;
padding: 8px;
width: 60px;
border: 1px solid #ccc;
border-radius: 4px;
`
}),
label: createUIElement('span', {
text: '天数:',
style: `
position: fixed;
right: 190px;
top: 23px;
z-index: 9999;
color: #666;
`
}),
resultArea: createUIElement('div', {
style: `
position: fixed;
right: 20px;
top: 70px;
width: 300px;
max-height: 80vh;
background: white;
border: 1px solid #ccc;
border-radius: 4px;
padding: 10px;
overflow-y: auto;
z-index: 9999;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
display: none;
`
}),
copyButton: createUIElement('button', {
text: '一键复制',
style: `
padding: 4px 8px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
display: none;
`
}),
resultCount: createUIElement('div', {
style: 'font-weight: bold;'
})
};
// 状态管理
const state = {
isScrolling: false,
scrollInterval: null,
processedItems: new Set(),
totalProcessed: 0
};
// 工具函数
const utils = {
parseTimeText(timeText) {
if (timeText.includes('今天')) return 0;
if (timeText === '昨天更新' || timeText === '1天前更新') return 1;
if (timeText === '前天更新' || timeText === '2天前更新' || timeText === '两天前更新') return 2;
const match = timeText.match(/^(\d+)天前更新$/);
return match ? parseInt(match[1]) : 999;
},
copyToClipboard(text) {
const textarea = createUIElement('textarea', {
props: { value: text },
style: 'position: fixed; left: -9999px;'
});
document.body.appendChild(textarea);
try {
textarea.select();
return document.execCommand('copy');
} finally {
document.body.removeChild(textarea);
}
},
updateResultCount(message) {
ui.resultCount.textContent = message;
},
stopScrolling() {
clearInterval(state.scrollInterval);
state.isScrolling = false;
ui.button.textContent = '开始提取';
ui.button.style.background = '#4CAF50';
utils.updateResultCount(state.totalProcessed > 0
? `已完成, 总共找到 ${state.totalProcessed} 条数据`
: '没有满足条件的数据');
if (!state.totalProcessed) ui.copyButton.style.display = 'none';
}
};
// 初始化结果区域
const resultHeader = createUIElement('div', {
style: `
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
`
});
resultHeader.append(ui.resultCount, ui.copyButton);
ui.resultArea.appendChild(resultHeader);
// 事件处理
ui.copyButton.addEventListener('click', () => {
const contents = Array.from(state.processedItems)
.map(key => {
const [time, content] = key.split('-');
return `${time} ${content}`;
})
.join('\n');
if (utils.copyToClipboard(contents)) {
const originalText = ui.copyButton.textContent;
ui.copyButton.textContent = '已复制!';
ui.copyButton.style.background = '#666';
setTimeout(() => {
ui.copyButton.textContent = originalText;
ui.copyButton.style.background = '#4CAF50';
}, 1000);
}
});
ui.button.addEventListener('click', () => {
if (!state.isScrolling) {
// 重置状态
state.processedItems.clear();
state.totalProcessed = 0;
ui.resultArea.innerHTML = '';
ui.resultArea.appendChild(resultHeader);
ui.copyButton.style.display = 'none';
ui.resultArea.style.display = 'block';
window.scrollTo(0, 0);
const daysLimit = parseInt(ui.input.value) || 2;
state.isScrolling = true;
ui.button.textContent = '停止滚动';
ui.button.style.background = '#f44336';
utils.updateResultCount('正在查找...');
let foundOutOfRange = false;
state.scrollInterval = setInterval(() => {
const isLoading = document.querySelector('.van-list')?.getAttribute('aria-busy') === 'true';
const isFinished = document.querySelector('.van-list__finished-text')?.textContent.includes('没有更多了');
if (isFinished) {
utils.stopScrolling();
return;
}
document.querySelectorAll('.activation').forEach(item => {
const content = item.querySelector('.content').textContent;
const time = item.querySelector('.time').textContent;
const days = utils.parseTimeText(time);
const key = `${time}-${content}`;
if (!state.processedItems.has(key)) {
if (days < daysLimit) {
state.totalProcessed++;
utils.updateResultCount(`正在查找, 已找到 ${state.totalProcessed} 条数据`);
ui.copyButton.style.display = 'block';
const resultItem = createUIElement('div', {
style: `
margin-bottom: 10px;
padding: 8px;
background: #f5f5f5;
border-radius: 4px;
`,
props: {
innerHTML: `
<div style="color: #666; font-size: 12px;">${time}</div>
<div style="margin-top: 4px;">${content}</div>
`
}
});
ui.resultArea.appendChild(resultItem);
state.processedItems.add(key);
} else {
foundOutOfRange = true;
}
}
});
if (foundOutOfRange) {
utils.stopScrolling();
return;
}
if (!isLoading && !foundOutOfRange) {
window.scrollBy(0, 100);
}
}, 100);
} else {
utils.stopScrolling();
}
});
// 添加元素到页面
document.body.append(ui.label, ui.input, ui.button, ui.resultArea);
})();