歌詞GET歌詞コピーページ
{
"name": "歌詞GET歌詞コピー",
"version": "1.0.0",
"manifest_version": 3,
"description": "歌詞GET歌詞コピー",
"content_scripts": [
{
"matches": ["http://www.kget.jp/lyric/*"],
"js": ["./app.js"]
}
]
}
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();