const main = () => {
const div = document.createElement('div');
const button = document.createElement('button');
div.appendChild(button);
document.querySelector('h1').after(div);
div.style.textAlign = 'center';
button.textContent = '歌詞をコピーする';
button.style.width = '150px';
button.style.height = '50px';
button.onclick = () => {
const listener = e => {
const str = document.querySelector('#lyric-trunk').textContent.trim();
const sp = str.split('\n');
const ret = sp.reduce((acc, value, index) => {
if (index >= 11 && index <= sp.length - 12) {
acc += value + '\n';
}
return acc;
}, '');
e.clipboardData.setData('text/plain', ret.trim());
e.preventDefault();
document.removeEventListener('copy', listener);
};
document.addEventListener('copy', listener);
document.execCommand('copy');
alert('歌詞をコピーしました');
};
};
main();