better dl button naming

This commit is contained in:
Simon 2023-08-25 18:46:29 +07:00
parent 1fed4c32e2
commit 114548d362
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -165,8 +165,8 @@ function buildChannelButton(channelContainer) {
let spacer = buildSpacer(); let spacer = buildSpacer();
buttonDiv.appendChild(spacer); buttonDiv.appendChild(spacer);
let dlLink = buildChannelDownloadLink(); let channelDownloadButton = buildChannelDownloadButton();
buttonDiv.appendChild(dlLink); buttonDiv.appendChild(channelDownloadButton);
return buttonDiv; return buttonDiv;
} }
@ -233,36 +233,36 @@ function buildSpacer() {
return spacer; return spacer;
} }
function buildChannelDownloadLink() { function buildChannelDownloadButton() {
let dlLink = document.createElement('span'); let channelDownloadButton = document.createElement('span');
let currentLocation = window.location.href; let currentLocation = window.location.href;
let urlObj = new URL(currentLocation); let urlObj = new URL(currentLocation);
if (urlObj.pathname.startsWith('/watch')) { if (urlObj.pathname.startsWith('/watch')) {
let videoId = urlObj.search.split('=')[1]; let videoId = urlObj.search.split('=')[1];
dlLink.setAttribute('data-type', 'video'); channelDownloadButton.setAttribute('data-type', 'video');
dlLink.setAttribute('data-id', videoId); channelDownloadButton.setAttribute('data-id', videoId);
dlLink.title = `TA download video: ${videoId}`; channelDownloadButton.title = `TA download video: ${videoId}`;
} else { } else {
let toDownload = urlObj.pathname.slice(1); let toDownload = urlObj.pathname.slice(1);
dlLink.setAttribute('data-id', toDownload); channelDownloadButton.setAttribute('data-id', toDownload);
dlLink.setAttribute('data-type', 'channel'); channelDownloadButton.setAttribute('data-type', 'channel');
dlLink.title = `TA download channel ${toDownload}`; channelDownloadButton.title = `TA download channel ${toDownload}`;
} }
dlLink.innerHTML = downloadIcon; channelDownloadButton.innerHTML = downloadIcon;
dlLink.addEventListener('click', e => { channelDownloadButton.addEventListener('click', e => {
e.preventDefault(); e.preventDefault();
console.log(`download: ${currentLocation}`); console.log(`download: ${currentLocation}`);
sendUrl(currentLocation, 'download', dlLink); sendDownload(channelDownloadButton);
}); });
Object.assign(dlLink.style, { Object.assign(channelDownloadButton.style, {
filter: 'invert()', filter: 'invert()',
width: '20px', width: '20px',
padding: '0 5px', padding: '0 5px',
cursor: 'pointer', cursor: 'pointer',
}); });
return dlLink; return channelDownloadButton;
} }
function getTitleContainers() { function getTitleContainers() {