/g, '\n')); alert("复制成功"); return true; } catch (err) { // 回退方案 const textarea = document.createElement('textarea'); textarea.value = copytext.replace(/
/g, '\n'); document.body.appendChild(textarea); textarea.select(); const success = document.execCommand('copy'); document.body.removeChild(textarea); if (success) { alert("复制成功"); } else { alert("复制失败,请手动选择后按 Ctrl+C 复制"); } return success; } } function GetCopyStr(str, type) { const checkboxes = document.querySelectorAll(`#${str} dd.clearfix input[type="checkbox"]:checked`); let result =""; const suf = document.querySelector(`#${str} .suf`).textContent; const suffix = suf ==="迅雷下载" ?"down" : suf; checkboxes.forEach(checkbox => { const parentText = checkbox.parentNode.textContent.trim(); if (type === 2) { result += parentText +"\n"; } else if (type === 3) { result += parentText +"$" + suffix +"\n"; } else { result += checkbox.value +"\n"; } }); return result; } document.addEventListener('DOMContentLoaded', function() { InitCopy(); document.querySelectorAll('.copy1').forEach(btn => { btn.addEventListener('click', function() { const id = this.closest('[id]').id; const copystr = GetCopyStr(id, 1); CopyText(copystr); }); }); document.querySelectorAll('.copy2').forEach(btn => { btn.addEventListener('click', function() { const id = this.closest('[id]').id; const copystr = GetCopyStr(id, 2); CopyText(copystr); }); }); document.querySelectorAll('.copy3').forEach(btn => { btn.addEventListener('click', function() { const id = this.closest('[id]').id; const copystr = GetCopyStr(id, 3); CopyText(copystr); }); }); });