javascript: (() => {
const copy = str => {
if (location.protocol === 'https:') {
navigator.clipboard.writeText(str).then(e => {
alert('歌詞をコピーしました');
});
return;
}
const listener = e => {
e.clipboardData.setData('text/plain', str);
e.preventDefault();
document.removeEventListener('copy', listener);
};
document.addEventListener('copy', listener);
document.execCommand('copy');
alert('歌詞をコピーしました');
};
const obj = {
'joysound.com': () =>
copy(
document
.querySelector('p.ng-binding')
.textContent.replace(/<br>/g, '\n')
),
'kashinavi.com': () =>
copy(
document.querySelector('.kashi').innerHTML.trim().replace(/<br>/g, '\n')
),
'j-lyric.net': () =>
copy(document.querySelector('#Lyric').innerText.replace(/<br>/g, '\n')),
'uta-net.com': () => {
try {
copy(
document.getElementById('kashi_area').innerHTML.replace(/<br>/g, '\n')
);
} catch (error) {
copy(
document
.querySelector('.kashi')
.querySelector('h2')
.nextElementSibling.innerHTML.replace(/<br>/g, '\n')
);
}
},
'utamap.com': () =>
copy(
document
.querySelector('.noprint.kasi_honbun')
.innerHTML.trim()
.replace(/<br>/g, '\n')
),
'utaten.com': () =>
copy(
Array.from(document.querySelectorAll('.romaji .ruby')).reduce(
(acc, dom) => {
acc += dom.querySelector('.rb').textContent.trim();
if (dom.nextElementSibling.innerHTML === '') {
acc += '\n';
}
return acc;
},
''
)
),
'petitlyrics.com': async () => {
let res = await fetch('https://petitlyrics.com/lib/pl-lib.js', {
credentials: 'include',
});
const csrf_token = (await res.text())
.split('\n')[2]
.split(',')[1]
.replace('"', '')
.replace("'", '')
.replace("'", '')
.replace(')', '')
.replace(';', '');
res = await fetch('/com/get_lyrics.ajax', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': csrf_token,
},
body: `lyrics_id=${Number(location.pathname.split('/')[2])}`,
});
const data = await res.json();
const len = data.length;
let text = '';
for (let i = 0; i < len; i++) {
text += Base64.decode(data[i].lyrics);
text += '\n';
}
copy(text);
},
'kget.jp': () => {
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;
}, '');
copy(ret.trim());
},
};
const root_domain = document.domain
.split('.')
.reverse()
.splice(0, 2)
.reverse()
.join('.');
try {
obj[root_domain]();
} catch (error) {
alert('歌詞が書いているURLで実行してください');
}
})();