2023-05-16 21:13:11 +01:00
|
|
|
const ua = navigator.userAgent.toLowerCase();
|
2024-05-10 14:11:57 +01:00
|
|
|
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
|
|
|
|
const isMobile = ua.includes("android") || ua.includes("iphone os");
|
|
|
|
const isSafari = ua.includes("safari/");
|
|
|
|
const isFirefox = ua.includes("firefox/");
|
|
|
|
const isOldFirefox = ua.includes("firefox/") && ua.split("firefox/")[1].split('.')[0] < 103;
|
2023-08-16 11:08:24 +01:00
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
const switchers = {
|
2022-07-13 21:32:00 +01:00
|
|
|
"theme": ["auto", "light", "dark"],
|
2023-02-26 16:49:25 +00:00
|
|
|
"vCodec": ["h264", "av1", "vp9"],
|
2024-05-04 03:30:59 +01:00
|
|
|
"vQuality": ["720", "max", "2160", "1440", "1080", "480", "360", "240", "144"],
|
2023-02-26 16:49:25 +00:00
|
|
|
"aFormat": ["mp3", "best", "ogg", "wav", "opus"],
|
2023-10-12 18:14:54 +01:00
|
|
|
"audioMode": ["false", "true"],
|
|
|
|
"filenamePattern": ["classic", "pretty", "basic", "nerdy"]
|
2024-04-29 19:04:19 +01:00
|
|
|
}
|
2023-09-06 15:01:17 +01:00
|
|
|
const checkboxes = [
|
2023-09-08 22:10:43 +01:00
|
|
|
"alwaysVisibleButton",
|
|
|
|
"downloadPopup",
|
2023-09-06 15:01:17 +01:00
|
|
|
"fullTikTokAudio",
|
|
|
|
"muteAudio",
|
|
|
|
"reduceTransparency",
|
|
|
|
"disableAnimations",
|
2023-09-08 22:10:43 +01:00
|
|
|
"disableMetadata",
|
2024-01-17 05:38:51 +00:00
|
|
|
"twitterGif",
|
2024-04-29 19:04:19 +01:00
|
|
|
"plausible_ignore",
|
|
|
|
"ytDub",
|
|
|
|
"tiktokH265"
|
|
|
|
]
|
|
|
|
const bottomPopups = ["error", "download"]
|
2023-09-08 22:10:43 +01:00
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
let store = {};
|
2022-07-13 21:32:00 +01:00
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
const validLink = (link) => {
|
|
|
|
try {
|
2024-04-29 19:34:29 +01:00
|
|
|
return /^https:/i.test(new URL(link).protocol);
|
2024-04-29 19:04:19 +01:00
|
|
|
} catch {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fixApiUrl = (url) => {
|
2023-10-14 17:51:53 +01:00
|
|
|
return url.endsWith('/') ? url.slice(0, -1) : url
|
|
|
|
}
|
|
|
|
|
|
|
|
let apiURL = fixApiUrl(defaultApiUrl);
|
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
const changeApi = (url) => {
|
2023-10-14 17:51:53 +01:00
|
|
|
apiURL = fixApiUrl(url);
|
2023-05-19 14:13:48 +01:00
|
|
|
return true
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const eid = (id) => {
|
2022-07-08 19:17:56 +01:00
|
|
|
return document.getElementById(id)
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
const sGet = (id) =>{
|
2022-08-16 11:31:41 +01:00
|
|
|
return localStorage.getItem(id)
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
const sSet = (id, value) => {
|
2022-08-16 11:31:41 +01:00
|
|
|
localStorage.setItem(id, value)
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
const enable = (id) => {
|
2022-07-08 19:17:56 +01:00
|
|
|
eid(id).dataset.enabled = "true";
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
const disable = (id) => {
|
2022-07-08 19:17:56 +01:00
|
|
|
eid(id).dataset.enabled = "false";
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
const opposite = (state) => {
|
2022-10-24 14:03:11 +01:00
|
|
|
return state === "true" ? "false" : "true";
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const lazyGet = (key) => {
|
|
|
|
const value = sGet(key);
|
|
|
|
if (key in switchers) {
|
|
|
|
if (switchers[key][0] !== value)
|
|
|
|
return value;
|
|
|
|
} else if (checkboxes.includes(key)) {
|
|
|
|
if (value === 'true')
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const changeDownloadButton = (action, text) => {
|
2022-07-08 19:17:56 +01:00
|
|
|
switch (action) {
|
2024-04-29 19:04:19 +01:00
|
|
|
case "hidden": // hidden, but only visible when alwaysVisibleButton is true
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").disabled = true
|
2022-10-24 14:03:11 +01:00
|
|
|
if (sGet("alwaysVisibleButton") === "true") {
|
2024-04-29 19:04:19 +01:00
|
|
|
eid("download-button").value = '>>'
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
} else {
|
|
|
|
eid("download-button").value = ''
|
|
|
|
eid("download-button").style.padding = '0'
|
|
|
|
}
|
|
|
|
break;
|
2024-04-29 19:04:19 +01:00
|
|
|
case "disabled":
|
|
|
|
eid("download-button").disabled = true
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").value = text
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
break;
|
2024-04-29 19:04:19 +01:00
|
|
|
default:
|
|
|
|
eid("download-button").disabled = false
|
|
|
|
eid("download-button").value = '>>'
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const button = () => {
|
|
|
|
let regexTest = validLink(eid("url-input-area").value);
|
|
|
|
|
|
|
|
eid("url-clear").style.display = "none";
|
|
|
|
|
2022-09-08 17:02:55 +01:00
|
|
|
if ((eid("url-input-area").value).length > 0) {
|
|
|
|
eid("url-clear").style.display = "block";
|
2024-04-29 19:04:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (regexTest) {
|
|
|
|
changeDownloadButton()
|
2022-09-08 17:02:55 +01:00
|
|
|
} else {
|
2024-04-29 19:04:19 +01:00
|
|
|
changeDownloadButton("hidden")
|
2022-09-08 17:02:55 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const clearInput = () => {
|
2022-09-08 17:02:55 +01:00
|
|
|
eid("url-input-area").value = '';
|
|
|
|
button();
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const copy = (id, data) => {
|
|
|
|
let target = document.getElementById(id);
|
|
|
|
target.classList.add("text-backdrop");
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
target.classList.remove("text-backdrop")
|
|
|
|
}, 600);
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
navigator.clipboard.writeText(data)
|
|
|
|
} else {
|
|
|
|
navigator.clipboard.writeText(e.innerText)
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2024-04-29 19:25:43 +01:00
|
|
|
const share = url => navigator?.share({ url }).catch(() => {});
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const detectColorScheme = () => {
|
2022-07-08 19:17:56 +01:00
|
|
|
let theme = "auto";
|
2022-08-16 11:31:41 +01:00
|
|
|
let localTheme = sGet("theme");
|
2022-07-08 19:17:56 +01:00
|
|
|
if (localTheme) {
|
|
|
|
theme = localTheme;
|
|
|
|
} else if (!window.matchMedia) {
|
|
|
|
theme = "dark"
|
|
|
|
}
|
|
|
|
document.documentElement.setAttribute("data-theme", theme);
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2024-04-29 19:25:43 +01:00
|
|
|
const updateFilenamePreview = () => {
|
|
|
|
let videoFilePreview = ``;
|
|
|
|
let audioFilePreview = ``;
|
|
|
|
let resMatch = {
|
|
|
|
"max": "3840x2160",
|
|
|
|
"2160": "3840x2160",
|
|
|
|
"1440": "2560x1440",
|
|
|
|
"1080": "1920x1080",
|
|
|
|
"720": "1280x720",
|
|
|
|
"480": "854x480",
|
|
|
|
"360": "640x360",
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(sGet("filenamePattern")) {
|
|
|
|
case "classic":
|
|
|
|
videoFilePreview = `youtube_dQw4w9WgXcQ_${resMatch[sGet('vQuality')]}_${sGet('vCodec')}`
|
|
|
|
+ `${sGet("muteAudio") === "true" ? "_mute" : ""}`
|
|
|
|
+ `.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`;
|
|
|
|
audioFilePreview = `youtube_dQw4w9WgXcQ_audio`
|
|
|
|
+ `.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`;
|
|
|
|
break;
|
|
|
|
case "basic":
|
|
|
|
videoFilePreview = `${loc.FilenamePreviewVideoTitle} `
|
|
|
|
+ `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, `
|
|
|
|
+ `${sGet('vCodec')}${sGet("muteAudio") === "true" ? ", mute" : ""})`
|
|
|
|
+ `.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`;
|
|
|
|
audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor}`
|
|
|
|
+ `.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`;
|
|
|
|
break;
|
|
|
|
case "pretty":
|
|
|
|
videoFilePreview = `${loc.FilenamePreviewVideoTitle} `
|
|
|
|
+ `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, `
|
|
|
|
+ `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube)`
|
|
|
|
+ `.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`;
|
|
|
|
audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor} (soundcloud)`
|
|
|
|
+ `.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`;
|
|
|
|
break;
|
|
|
|
case "nerdy":
|
|
|
|
videoFilePreview = `${loc.FilenamePreviewVideoTitle} `
|
|
|
|
+ `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, `
|
|
|
|
+ `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube, dQw4w9WgXcQ)`
|
|
|
|
+ `.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`;
|
|
|
|
audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor} `
|
|
|
|
+ `(soundcloud, 1242868615)`
|
|
|
|
+ `.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
eid("video-filename-text").innerHTML = videoFilePreview
|
|
|
|
eid("audio-filename-text").innerHTML = audioFilePreview
|
|
|
|
}
|
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
const changeTab = (evnt, tabId, tabClass) => {
|
2023-10-14 17:51:53 +01:00
|
|
|
if (tabId === "tab-settings-other") updateFilenamePreview();
|
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
let tabcontent = document.getElementsByClassName(`tab-content-${tabClass}`);
|
|
|
|
let tablinks = document.getElementsByClassName(`tab-${tabClass}`);
|
2023-08-11 16:53:30 +01:00
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
for (let i = 0; i < tabcontent.length; i++) {
|
2023-08-11 16:53:30 +01:00
|
|
|
tabcontent[i].dataset.enabled = "false";
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
for (let i = 0; i < tablinks.length; i++) {
|
|
|
|
tablinks[i].dataset.enabled = "false";
|
|
|
|
}
|
2023-08-11 16:53:30 +01:00
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
evnt.currentTarget.dataset.enabled = "true";
|
2023-08-11 16:53:30 +01:00
|
|
|
eid(tabId).dataset.enabled = "true";
|
2023-09-07 17:42:33 +01:00
|
|
|
eid(tabId).parentElement.scrollTop = 0;
|
2022-10-02 15:13:33 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const expandCollapsible = (evnt) => {
|
2023-01-29 18:17:33 +00:00
|
|
|
let classlist = evnt.currentTarget.parentNode.classList;
|
|
|
|
let c = "expanded";
|
|
|
|
!classlist.contains(c) ? classlist.add(c) : classlist.remove(c);
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const hideAllPopups = () => {
|
2022-08-12 14:36:19 +01:00
|
|
|
let filter = document.getElementsByClassName('popup');
|
|
|
|
for (let i = 0; i < filter.length; i++) {
|
2023-08-04 19:43:12 +01:00
|
|
|
filter[i].classList.remove("visible");
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-08-13 20:36:19 +01:00
|
|
|
eid("popup-backdrop").classList.remove("visible");
|
|
|
|
store.isPopupOpen = false;
|
|
|
|
|
|
|
|
// clear the picker
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("picker-holder").innerHTML = '';
|
|
|
|
eid("picker-download").href = '/';
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("picker-download").classList.remove("visible");
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const popup = (type, action, text) => {
|
2022-10-24 14:03:11 +01:00
|
|
|
if (action === 1) {
|
2022-10-02 15:13:33 +01:00
|
|
|
hideAllPopups(); // hide the previous popup before showing a new one
|
2023-08-04 19:43:12 +01:00
|
|
|
store.isPopupOpen = true;
|
2022-10-02 15:13:33 +01:00
|
|
|
switch (type) {
|
|
|
|
case "about":
|
2024-04-29 19:04:19 +01:00
|
|
|
let tabId = "about";
|
2022-11-20 13:46:08 +00:00
|
|
|
if (text) tabId = text;
|
2022-10-02 15:13:33 +01:00
|
|
|
eid(`tab-button-${type}-${tabId}`).click();
|
|
|
|
break;
|
|
|
|
case "settings":
|
|
|
|
eid(`tab-button-${type}-video`).click();
|
|
|
|
break;
|
|
|
|
case "error":
|
|
|
|
eid("desc-error").innerHTML = text;
|
|
|
|
break;
|
|
|
|
case "download":
|
2022-07-13 21:32:00 +01:00
|
|
|
eid("pd-download").href = text;
|
2022-08-04 12:22:40 +01:00
|
|
|
eid("pd-copy").setAttribute("onClick", `copy('pd-copy', '${text}')`);
|
2023-04-08 17:55:44 +01:00
|
|
|
eid("pd-share").setAttribute("onClick", `share('${text}')`);
|
|
|
|
if (navigator.canShare) eid("pd-share").style.display = "flex";
|
2022-10-02 15:13:33 +01:00
|
|
|
break;
|
2022-10-09 18:44:00 +01:00
|
|
|
case "picker":
|
2024-01-28 08:13:53 +00:00
|
|
|
eid("picker-title").innerHTML = loc.MediaPickerTitle;
|
|
|
|
eid("picker-subtitle").innerHTML = isMobile ? loc.MediaPickerExplanationPhone : loc.MediaPickerExplanationPC;
|
|
|
|
|
2022-10-09 18:44:00 +01:00
|
|
|
switch (text.type) {
|
|
|
|
case "images":
|
2023-08-13 20:36:19 +01:00
|
|
|
eid("picker-holder").classList.remove("various");
|
|
|
|
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("picker-download").href = text.audio;
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("picker-download").classList.add("visible");
|
2023-08-13 20:36:19 +01:00
|
|
|
|
2022-10-09 18:44:00 +01:00
|
|
|
for (let i in text.arr) {
|
2023-08-20 14:14:31 +01:00
|
|
|
eid("picker-holder").innerHTML +=
|
|
|
|
`<a class="picker-image-container" ${
|
2023-08-21 18:40:37 +01:00
|
|
|
isIOS ? `onClick="share('${text.arr[i]["url"]}')"` : `href="${text.arr[i]["url"]}" target="_blank"`
|
2023-08-20 14:14:31 +01:00
|
|
|
}>` +
|
2024-01-13 00:35:46 +00:00
|
|
|
`<img class="picker-image" src="${text.arr[i]["url"]}" onerror="this.parentNode.style.display='none'">` +
|
2023-08-20 14:14:31 +01:00
|
|
|
`</a>`
|
2022-10-09 18:44:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2023-08-13 20:36:19 +01:00
|
|
|
eid("picker-holder").classList.add("various");
|
|
|
|
|
2022-10-09 18:44:00 +01:00
|
|
|
for (let i in text.arr) {
|
2023-08-20 14:14:31 +01:00
|
|
|
eid("picker-holder").innerHTML +=
|
|
|
|
`<a class="picker-image-container" ${
|
2023-08-21 20:15:07 +01:00
|
|
|
isIOS ? `onClick="share('${text.arr[i]["url"]}')"` : `href="${text.arr[i]["url"]}" target="_blank"`
|
2023-08-20 14:14:31 +01:00
|
|
|
}>` +
|
|
|
|
`<div class="picker-element-name">${text.arr[i].type}</div>` +
|
2023-10-10 22:06:32 +01:00
|
|
|
(text.arr[i].type === 'photo' ? '' : '<div class="imageBlock"></div>') +
|
2024-01-13 00:35:46 +00:00
|
|
|
`<img class="picker-image" src="${text.arr[i]["thumb"]}" onerror="this.style.display='none'">` +
|
2023-08-20 14:14:31 +01:00
|
|
|
`</a>`
|
2022-10-09 18:44:00 +01:00
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("picker-download").classList.remove("visible");
|
2022-10-09 18:44:00 +01:00
|
|
|
break;
|
2022-10-02 15:13:33 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2023-08-04 19:43:12 +01:00
|
|
|
store.isPopupOpen = false;
|
2022-10-24 14:03:11 +01:00
|
|
|
if (type === "picker") {
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("picker-download").href = '/';
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("picker-download").classList.remove("visible");
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("picker-holder").innerHTML = ''
|
2022-10-02 15:13:33 +01:00
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
if (bottomPopups.includes(type)) eid(`popup-${type}-container`).classList.toggle("visible");
|
|
|
|
eid("popup-backdrop").classList.toggle("visible");
|
|
|
|
eid(`popup-${type}`).classList.toggle("visible");
|
|
|
|
eid(`popup-${type}`).focus();
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const changeSwitcher = (li, b) => {
|
2022-07-08 19:17:56 +01:00
|
|
|
if (b) {
|
2023-02-26 16:49:25 +00:00
|
|
|
if (!switchers[li].includes(b)) b = switchers[li][0];
|
2022-08-16 11:31:41 +01:00
|
|
|
sSet(li, b);
|
2022-09-01 15:02:37 +01:00
|
|
|
for (let i in switchers[li]) {
|
2022-10-24 14:03:11 +01:00
|
|
|
(switchers[li][i] === b) ? enable(`${li}-${b}`) : disable(`${li}-${switchers[li][i]}`)
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2022-10-24 14:03:11 +01:00
|
|
|
if (li === "theme") detectColorScheme();
|
2023-10-14 17:51:53 +01:00
|
|
|
if (li === "filenamePattern") updateFilenamePreview();
|
2022-07-08 19:17:56 +01:00
|
|
|
} else {
|
2022-08-06 16:21:48 +01:00
|
|
|
let pref = switchers[li][0];
|
2022-08-22 08:30:45 +01:00
|
|
|
sSet(li, pref);
|
2022-09-01 15:02:37 +01:00
|
|
|
for (let i in switchers[li]) {
|
2022-10-24 14:03:11 +01:00
|
|
|
(switchers[li][i] === pref) ? enable(`${li}-${pref}`) : disable(`${li}-${switchers[li][i]}`)
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const checkbox = (action) => {
|
2023-03-29 17:08:41 +01:00
|
|
|
sSet(action, !!eid(action).checked);
|
|
|
|
switch(action) {
|
|
|
|
case "alwaysVisibleButton": button(); break;
|
2023-08-04 19:43:12 +01:00
|
|
|
case "reduceTransparency": eid("cobalt-body").classList.toggle('no-transparency'); break;
|
|
|
|
case "disableAnimations": eid("cobalt-body").classList.toggle('no-animation'); break;
|
2022-09-01 15:02:37 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const changeButton = (type, text) => {
|
2022-10-09 18:44:00 +01:00
|
|
|
switch (type) {
|
2024-04-29 19:04:19 +01:00
|
|
|
case "error": //error
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
eid("url-clear").style.display = "block";
|
2024-04-29 19:04:19 +01:00
|
|
|
changeDownloadButton("disabled", '!!');
|
2022-10-09 18:44:00 +01:00
|
|
|
popup("error", 1, text);
|
2024-04-29 19:04:19 +01:00
|
|
|
setTimeout(() => { changeButton("default") }, 2500);
|
2022-10-09 18:44:00 +01:00
|
|
|
break;
|
2024-04-29 19:04:19 +01:00
|
|
|
case "default": //enable back
|
|
|
|
changeDownloadButton();
|
2022-10-09 18:44:00 +01:00
|
|
|
eid("url-clear").style.display = "block";
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
break;
|
2024-04-29 19:04:19 +01:00
|
|
|
case "error-default": //enable back + information popup
|
2022-11-12 16:40:11 +00:00
|
|
|
popup("error", 1, text);
|
2024-04-29 19:04:19 +01:00
|
|
|
changeDownloadButton();
|
2022-11-12 16:40:11 +00:00
|
|
|
eid("url-clear").style.display = "block";
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
break;
|
2022-10-09 18:44:00 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const internetError = () => {
|
2023-07-18 20:50:51 +01:00
|
|
|
eid("url-input-area").disabled = false
|
2024-04-29 19:04:19 +01:00
|
|
|
changeDownloadButton("disabled", '!!');
|
|
|
|
setTimeout(() => { changeButton("default") }, 2500);
|
2023-09-08 22:10:43 +01:00
|
|
|
popup("error", 1, loc.ErrorNoInternet);
|
2023-07-18 20:50:51 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const resetSettings = () => {
|
2022-11-04 08:49:58 +00:00
|
|
|
localStorage.clear();
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const download = async(url) => {
|
|
|
|
changeDownloadButton("disabled", '...');
|
|
|
|
|
2022-09-08 17:02:55 +01:00
|
|
|
eid("url-clear").style.display = "none";
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("url-input-area").disabled = true;
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2022-11-12 16:40:11 +00:00
|
|
|
let req = {
|
2023-12-14 23:46:49 +00:00
|
|
|
url,
|
2024-04-29 19:04:19 +01:00
|
|
|
vCodec: lazyGet("vCodec"),
|
|
|
|
vQuality: lazyGet("vQuality"),
|
|
|
|
aFormat: lazyGet("aFormat"),
|
|
|
|
filenamePattern: lazyGet("filenamePattern"),
|
|
|
|
isAudioOnly: lazyGet("audioMode"),
|
|
|
|
isTTFullAudio: lazyGet("fullTikTokAudio"),
|
|
|
|
isAudioMuted: lazyGet("muteAudio"),
|
|
|
|
disableMetadata: lazyGet("disableMetadata"),
|
2024-04-29 19:25:43 +01:00
|
|
|
dubLang: lazyGet("ytDub"),
|
2024-04-29 19:04:19 +01:00
|
|
|
twitterGif: lazyGet("twitterGif"),
|
|
|
|
tiktokH265: lazyGet("tiktokH265"),
|
2022-08-16 11:31:41 +01:00
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
|
|
|
|
let j = await fetch(`${apiURL}/api/json`, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(req),
|
2024-04-29 19:04:19 +01:00
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}).then(r => r.json()).catch(() => {});
|
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
if (!j) {
|
|
|
|
internetError();
|
2024-04-29 19:04:19 +01:00
|
|
|
return;
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
if ((j.status === "error" || j.status === "rate-limit") && j && j.text) {
|
|
|
|
changeButton("error", j.text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j.text && (!j.url || !j.picker)) {
|
|
|
|
if (j.status === "success") {
|
|
|
|
changeButton("error-default", j.text)
|
|
|
|
} else {
|
|
|
|
changeButton("error", loc.ErrorNoUrlReturned);
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
}
|
|
|
|
switch (j.status) {
|
|
|
|
case "redirect":
|
|
|
|
changeDownloadButton("disabled", '>>>');
|
|
|
|
setTimeout(() => { changeButton("default") }, 1500);
|
|
|
|
|
|
|
|
if (sGet("downloadPopup") === "true") {
|
|
|
|
popup('download', 1, j.url)
|
|
|
|
} else {
|
|
|
|
window.open(j.url, '_blank')
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "stream":
|
|
|
|
changeDownloadButton("disabled", '?..');
|
|
|
|
|
|
|
|
let probeStream = await fetch(`${j.url}&p=1`).then(r => r.json()).catch(() => {});
|
|
|
|
if (!probeStream) return internetError();
|
|
|
|
|
|
|
|
if (probeStream.status !== "continue") {
|
|
|
|
changeButton("error", probeStream.text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
changeDownloadButton("disabled", '>>>');
|
|
|
|
if (sGet("downloadPopup") === "true") {
|
|
|
|
popup('download', 1, j.url)
|
|
|
|
} else {
|
|
|
|
if (isMobile || isSafari) {
|
|
|
|
window.location.href = j.url;
|
2023-05-16 21:13:11 +01:00
|
|
|
} else {
|
2024-04-29 19:04:19 +01:00
|
|
|
window.open(j.url, '_blank');
|
2022-07-22 09:05:36 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
}
|
|
|
|
setTimeout(() => { changeButton("default") }, 2500);
|
|
|
|
break;
|
|
|
|
case "picker":
|
|
|
|
if (j.audio && j.picker) {
|
|
|
|
changeDownloadButton("disabled", '>>>');
|
|
|
|
popup('picker', 1, {
|
|
|
|
audio: j.audio,
|
|
|
|
arr: j.picker,
|
|
|
|
type: j.pickerType
|
|
|
|
});
|
|
|
|
setTimeout(() => { changeButton("default") }, 2500);
|
|
|
|
} else if (j.picker) {
|
|
|
|
changeDownloadButton("disabled", '>>>');
|
|
|
|
popup('picker', 1, {
|
|
|
|
arr: j.picker,
|
|
|
|
type: j.pickerType
|
|
|
|
});
|
|
|
|
setTimeout(() => { changeButton("default") }, 2500);
|
|
|
|
} else {
|
|
|
|
changeButton("error", loc.ErrorNoUrlReturned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "success":
|
|
|
|
changeButton("error-default", j.text);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
changeButton("error", loc.ErrorUnknownStatus);
|
|
|
|
break;
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2024-04-29 19:25:43 +01:00
|
|
|
const pasteClipboard = async() => {
|
|
|
|
try {
|
|
|
|
let clipboard = await navigator.clipboard.readText();
|
2024-04-29 19:34:29 +01:00
|
|
|
let onlyURL = clipboard.match(/https:\/\/[^\s]+/g)
|
|
|
|
if (onlyURL) {
|
|
|
|
eid("url-input-area").value = onlyURL;
|
2024-04-29 19:25:43 +01:00
|
|
|
download(eid("url-input-area").value);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
let errorMessage = loc.FeatureErrorGeneric;
|
|
|
|
let doError = true;
|
|
|
|
let error = String(e).toLowerCase();
|
|
|
|
|
|
|
|
if (error.includes("denied")) errorMessage = loc.ClipboardErrorNoPermission;
|
|
|
|
if (error.includes("dismissed") || isIOS) doError = false;
|
|
|
|
if (error.includes("function") && isFirefox) errorMessage = loc.ClipboardErrorFirefox;
|
|
|
|
|
|
|
|
if (doError) popup("error", 1, errorMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
const loadCelebrationsEmoji = async() => {
|
|
|
|
let aboutButtonBackup = eid("about-footer").innerHTML;
|
2023-05-16 21:13:11 +01:00
|
|
|
try {
|
2024-04-29 19:04:19 +01:00
|
|
|
let j = await fetch(`/onDemand?blockId=1`).then(r => r.json()).catch(() => {});
|
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
if (j && j.status === "success" && j.text) {
|
2024-04-29 19:04:19 +01:00
|
|
|
eid("about-footer").innerHTML = eid("about-footer").innerHTML.replace(
|
|
|
|
`<img class="emoji"
|
|
|
|
draggable="false"
|
|
|
|
height="22"
|
|
|
|
width="22
|
|
|
|
alt="🐲"
|
|
|
|
src="emoji/dragon_face.svg"
|
|
|
|
loading="lazy">`,
|
|
|
|
j.text
|
|
|
|
)
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
} catch {
|
|
|
|
eid("about-footer").innerHTML = aboutButtonBackup;
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const loadOnDemand = async(elementId, blockId) => {
|
2022-11-15 17:37:33 +00:00
|
|
|
store.historyButton = eid(elementId).innerHTML;
|
2023-08-11 16:53:30 +01:00
|
|
|
eid(elementId).innerHTML = `<div class="loader">...</div>`;
|
2023-05-16 21:31:22 +01:00
|
|
|
|
2022-11-15 17:37:33 +00:00
|
|
|
try {
|
2024-04-29 19:04:19 +01:00
|
|
|
if (!store.historyContent) {
|
|
|
|
let j = await fetch(`/onDemand?blockId=${blockId}`).then(r => r.json()).catch(() => {});
|
|
|
|
if (!j) throw new Error();
|
|
|
|
|
|
|
|
if (j.status === "success") {
|
|
|
|
store.historyContent = j.text
|
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
eid(elementId).innerHTML =
|
|
|
|
`<button class="switch bottom-margin" onclick="restoreUpdateHistory()">
|
|
|
|
${loc.ChangelogPressToHide}
|
|
|
|
</button>
|
|
|
|
${store.historyContent}`;
|
|
|
|
} catch {
|
2022-11-15 17:37:33 +00:00
|
|
|
eid(elementId).innerHTML = store.historyButton;
|
2022-09-11 16:04:06 +01:00
|
|
|
internetError()
|
2022-11-15 17:37:33 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const restoreUpdateHistory = () => {
|
2022-11-15 17:37:33 +00:00
|
|
|
eid("changelog-history").innerHTML = store.historyButton;
|
2022-09-11 16:04:06 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
const loadSettings = () => {
|
2023-10-14 17:51:53 +01:00
|
|
|
if (sGet("alwaysVisibleButton") === "true") {
|
|
|
|
eid("alwaysVisibleButton").checked = true;
|
|
|
|
eid("download-button").value = '>>'
|
|
|
|
eid("download-button").style.padding = '0 1rem';
|
|
|
|
}
|
|
|
|
if (sGet("downloadPopup") === "true" && !isIOS) {
|
|
|
|
eid("downloadPopup").checked = true;
|
|
|
|
}
|
|
|
|
if (sGet("reduceTransparency") === "true" || isOldFirefox) {
|
|
|
|
eid("cobalt-body").classList.add('no-transparency');
|
|
|
|
}
|
|
|
|
if (sGet("disableAnimations") === "true") {
|
|
|
|
eid("cobalt-body").classList.add('no-animation');
|
|
|
|
}
|
|
|
|
for (let i = 0; i < checkboxes.length; i++) {
|
2024-03-16 17:33:33 +00:00
|
|
|
try {
|
|
|
|
if (sGet(checkboxes[i]) === "true") eid(checkboxes[i]).checked = true;
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
console.error(`checkbox ${checkboxes[i]} failed to initialize`)
|
|
|
|
}
|
2023-10-14 17:51:53 +01:00
|
|
|
}
|
|
|
|
for (let i in switchers) {
|
|
|
|
changeSwitcher(i, sGet(i))
|
|
|
|
}
|
|
|
|
updateFilenamePreview()
|
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2022-08-16 08:14:19 +01:00
|
|
|
window.onload = () => {
|
2023-09-08 22:10:43 +01:00
|
|
|
loadCelebrationsEmoji();
|
|
|
|
|
2022-07-08 19:17:56 +01:00
|
|
|
loadSettings();
|
|
|
|
detectColorScheme();
|
2023-09-08 22:10:43 +01:00
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
changeDownloadButton("hidden");
|
2023-09-08 22:10:43 +01:00
|
|
|
eid("url-input-area").value = "";
|
|
|
|
|
2023-08-04 20:06:02 +01:00
|
|
|
if (isIOS) {
|
|
|
|
sSet("downloadPopup", "true");
|
2023-08-11 16:53:30 +01:00
|
|
|
eid("downloadPopup-chkbx").style.display = "none";
|
2023-08-04 20:06:02 +01:00
|
|
|
}
|
2023-08-13 19:09:50 +01:00
|
|
|
|
|
|
|
eid("home").style.visibility = 'visible';
|
|
|
|
eid("home").classList.toggle("visible");
|
|
|
|
|
2024-04-29 19:04:19 +01:00
|
|
|
const pageQuery = new URLSearchParams(window.location.search);
|
|
|
|
if (pageQuery.has("u") && validLink(pageQuery.get("u"))) {
|
2023-09-08 22:10:43 +01:00
|
|
|
eid("url-input-area").value = pageQuery.get("u");
|
|
|
|
button()
|
|
|
|
}
|
|
|
|
window.history.replaceState(null, '', window.location.pathname);
|
|
|
|
|
2024-01-13 00:20:36 +00:00
|
|
|
// fix for animations not working in Safari
|
|
|
|
if (isIOS) {
|
|
|
|
document.addEventListener('touchstart', () => {}, true);
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2024-04-29 19:04:19 +01:00
|
|
|
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("url-input-area").addEventListener("keydown", (e) => {
|
2022-09-08 17:02:55 +01:00
|
|
|
button();
|
|
|
|
})
|
2023-08-04 19:43:12 +01:00
|
|
|
eid("url-input-area").addEventListener("keyup", (e) => {
|
|
|
|
if (e.key === 'Enter') eid("download-button").click();
|
2022-08-04 19:09:41 +01:00
|
|
|
})
|
2024-04-29 19:04:19 +01:00
|
|
|
|
|
|
|
document.addEventListener("keydown", (event) => {
|
|
|
|
if (event.key === "Tab") {
|
|
|
|
eid("download-button").value = '>>'
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
}
|
|
|
|
})
|
2023-08-04 19:43:12 +01:00
|
|
|
document.onkeydown = (e) => {
|
|
|
|
if (!store.isPopupOpen) {
|
2023-12-20 18:31:48 +00:00
|
|
|
if (e.metaKey || e.ctrlKey || e.key === "/") eid("url-input-area").focus();
|
2023-08-13 19:09:50 +01:00
|
|
|
if (e.key === "Escape" || e.key === "Clear") clearInput();
|
2023-08-04 19:43:12 +01:00
|
|
|
|
2023-12-26 00:55:30 +00:00
|
|
|
if (e.target === eid("url-input-area")) return;
|
|
|
|
|
2023-08-04 19:43:12 +01:00
|
|
|
// top buttons
|
|
|
|
if (e.key === "D") pasteClipboard();
|
|
|
|
if (e.key === "K") changeSwitcher('audioMode', 'false');
|
|
|
|
if (e.key === "L") changeSwitcher('audioMode', 'true');
|
|
|
|
|
|
|
|
// popups
|
2023-08-11 16:53:30 +01:00
|
|
|
if (e.key === "B") popup('about', 1, 'about'); // open about
|
|
|
|
if (e.key === "N") popup('about', 1, 'changelog'); // open changelog
|
2023-08-04 19:43:12 +01:00
|
|
|
if (e.key === "M") popup('settings', 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (e.key === "Escape") hideAllPopups();
|
|
|
|
}
|
2023-04-03 17:36:23 +01:00
|
|
|
}
|