2024-03-06 18:32:29 +00:00
|
|
|
const version = 42;
|
2023-09-08 22:10:43 +01:00
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
|
|
const isIOS = ua.match("iphone os");
|
|
|
|
const isMobile = ua.match("android") || ua.match("iphone os");
|
2023-08-16 11:08:24 +01:00
|
|
|
const isSafari = ua.match("safari/");
|
2023-08-04 19:43:12 +01:00
|
|
|
const isFirefox = ua.match("firefox/");
|
|
|
|
const isOldFirefox = ua.match("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 regex = new RegExp(/https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/);
|
2024-03-06 14:11:11 +00:00
|
|
|
const notification = `<span class="notification-dot"></span>`;
|
2022-08-12 14:36:19 +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"],
|
|
|
|
"vQuality": ["1080", "max", "2160", "1440", "720", "480", "360"],
|
|
|
|
"aFormat": ["mp3", "best", "ogg", "wav", "opus"],
|
2023-03-15 16:18:31 +00:00
|
|
|
"dubLang": ["original", "auto"],
|
2023-04-03 17:36:23 +01:00
|
|
|
"vimeoDash": ["false", "true"],
|
2023-10-12 18:14:54 +01:00
|
|
|
"audioMode": ["false", "true"],
|
|
|
|
"filenamePattern": ["classic", "pretty", "basic", "nerdy"]
|
2023-05-16 21:13:11 +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-03-16 17:18:39 +00:00
|
|
|
"plausible_ignore"
|
2023-09-06 15:01:17 +01:00
|
|
|
];
|
2023-05-16 21:13:11 +01:00
|
|
|
const exceptions = { // used for mobile devices
|
2023-02-26 16:49:25 +00:00
|
|
|
"vQuality": "720"
|
2023-05-16 21:13:11 +01:00
|
|
|
};
|
2023-10-14 17:51:53 +01:00
|
|
|
const bottomPopups = ["error", "download"];
|
2023-05-16 21:13:11 +01:00
|
|
|
|
2023-09-08 22:10:43 +01:00
|
|
|
const pageQuery = new URLSearchParams(window.location.search);
|
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
let store = {};
|
2022-07-13 21:32:00 +01:00
|
|
|
|
2023-10-14 17:51:53 +01:00
|
|
|
function fixApiUrl(url) {
|
|
|
|
return url.endsWith('/') ? url.slice(0, -1) : url
|
|
|
|
}
|
|
|
|
|
|
|
|
let apiURL = fixApiUrl(defaultApiUrl);
|
|
|
|
|
|
|
|
function changeApi(url) {
|
|
|
|
apiURL = fixApiUrl(url);
|
2023-05-19 14:13:48 +01:00
|
|
|
return true
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
function eid(id) {
|
|
|
|
return document.getElementById(id)
|
|
|
|
}
|
2022-08-16 11:31:41 +01:00
|
|
|
function sGet(id) {
|
|
|
|
return localStorage.getItem(id)
|
|
|
|
}
|
|
|
|
function sSet(id, value) {
|
|
|
|
localStorage.setItem(id, value)
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
function enable(id) {
|
|
|
|
eid(id).dataset.enabled = "true";
|
|
|
|
}
|
|
|
|
function disable(id) {
|
|
|
|
eid(id).dataset.enabled = "false";
|
|
|
|
}
|
|
|
|
function vis(state) {
|
|
|
|
return (state === 1) ? "visible" : "hidden";
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
function opposite(state) {
|
2022-10-24 14:03:11 +01:00
|
|
|
return state === "true" ? "false" : "true";
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
function changeDownloadButton(action, text) {
|
|
|
|
switch (action) {
|
|
|
|
case 0:
|
|
|
|
eid("download-button").disabled = true
|
2022-10-24 14:03:11 +01:00
|
|
|
if (sGet("alwaysVisibleButton") === "true") {
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").value = text
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
} else {
|
|
|
|
eid("download-button").value = ''
|
|
|
|
eid("download-button").style.padding = '0'
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
eid("download-button").disabled = false
|
|
|
|
eid("download-button").value = text
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
eid("download-button").disabled = true
|
|
|
|
eid("download-button").value = text
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 08:14:19 +01:00
|
|
|
document.addEventListener("keydown", (event) => {
|
2022-10-24 14:03:11 +01:00
|
|
|
if (event.key === "Tab") {
|
2022-07-08 19:17:56 +01:00
|
|
|
eid("download-button").value = '>>'
|
|
|
|
eid("download-button").style.padding = '0 1rem'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
function button() {
|
2022-09-08 17:02:55 +01:00
|
|
|
let regexTest = regex.test(eid("url-input-area").value);
|
|
|
|
if ((eid("url-input-area").value).length > 0) {
|
|
|
|
eid("url-clear").style.display = "block";
|
|
|
|
} else {
|
|
|
|
eid("url-clear").style.display = "none";
|
|
|
|
}
|
|
|
|
regexTest ? changeDownloadButton(1, '>>') : changeDownloadButton(0, '>>');
|
|
|
|
}
|
|
|
|
function clearInput() {
|
|
|
|
eid("url-input-area").value = '';
|
|
|
|
button();
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2022-07-13 21:32:00 +01:00
|
|
|
function copy(id, data) {
|
2022-07-08 19:17:56 +01:00
|
|
|
let e = document.getElementById(id);
|
|
|
|
e.classList.add("text-backdrop");
|
|
|
|
setTimeout(() => { e.classList.remove("text-backdrop") }, 600);
|
2023-01-29 18:17:33 +00:00
|
|
|
data ? navigator.clipboard.writeText(data) : navigator.clipboard.writeText(e.innerText);
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2023-04-08 17:55:44 +01:00
|
|
|
async function share(url) {
|
|
|
|
try { await navigator.share({url: url}) } catch (e) {}
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
function detectColorScheme() {
|
|
|
|
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);
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
function 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;
|
2023-08-11 16:53:30 +01:00
|
|
|
|
2022-10-24 14:03:11 +01:00
|
|
|
if (tabId === "tab-about-changelog" && sGet("changelogStatus") !== `${version}`) notificationCheck("changelog");
|
|
|
|
if (tabId === "tab-about-about" && !sGet("seenAbout")) notificationCheck("about");
|
2022-10-02 15:13:33 +01:00
|
|
|
}
|
2023-01-29 18:17:33 +00:00
|
|
|
function expandCollapsible(evnt) {
|
|
|
|
let classlist = evnt.currentTarget.parentNode.classList;
|
|
|
|
let c = "expanded";
|
|
|
|
!classlist.contains(c) ? classlist.add(c) : classlist.remove(c);
|
|
|
|
}
|
2022-10-02 15:13:33 +01:00
|
|
|
function notificationCheck(type) {
|
|
|
|
let changed = true;
|
|
|
|
switch (type) {
|
|
|
|
case "about":
|
|
|
|
sSet("seenAbout", "true");
|
|
|
|
break;
|
|
|
|
case "changelog":
|
|
|
|
sSet("changelogStatus", version)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
changed = false;
|
|
|
|
}
|
2024-04-05 06:57:06 +01:00
|
|
|
if (changed && sGet("changelogStatus") === `${version}`) {
|
2022-10-02 15:13:33 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
eid("about-footer").innerHTML = eid("about-footer").innerHTML.replace(notification, '');
|
|
|
|
eid("tab-button-about-changelog").innerHTML = eid("tab-button-about-changelog").innerHTML.replace(notification, '')
|
|
|
|
}, 900)
|
|
|
|
}
|
2024-04-05 06:57:06 +01:00
|
|
|
if (!sGet("seenAbout") && !eid("about-footer").innerHTML.includes(notification)) {
|
|
|
|
eid("about-footer").innerHTML = `${notification}${eid("about-footer").innerHTML}`;
|
|
|
|
}
|
|
|
|
if (sGet("changelogStatus") !== `${version}`) {
|
|
|
|
if (!eid("about-footer").innerHTML.includes(notification)) {
|
|
|
|
eid("about-footer").innerHTML = `${notification}${eid("about-footer").innerHTML}`;
|
|
|
|
}
|
|
|
|
if (!eid("tab-button-about-changelog").innerHTML.includes(notification)) {
|
|
|
|
eid("tab-button-about-changelog").innerHTML = `${notification}${eid("tab-button-about-changelog").innerHTML}`;
|
2022-10-02 15:13:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
function hideAllPopups() {
|
|
|
|
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
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
function 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":
|
2023-10-12 12:33:26 +01:00
|
|
|
let tabId = sGet("changelogStatus") !== `${version}` ? "changelog" : "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
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
function 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-11-04 08:49:58 +00:00
|
|
|
if (isMobile && exceptions[li]) pref = exceptions[li];
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function 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
|
|
|
}
|
|
|
|
}
|
2022-10-09 18:44:00 +01:00
|
|
|
function changeButton(type, text) {
|
|
|
|
switch (type) {
|
|
|
|
case 0: //error
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
eid("url-clear").style.display = "block";
|
2023-07-18 20:50:51 +01:00
|
|
|
changeDownloadButton(2, '!!');
|
2022-10-09 18:44:00 +01:00
|
|
|
popup("error", 1, text);
|
2023-07-18 20:50:51 +01:00
|
|
|
setTimeout(() => { changeButton(1); }, 2500);
|
2022-10-09 18:44:00 +01:00
|
|
|
break;
|
|
|
|
case 1: //enable back
|
|
|
|
changeDownloadButton(1, '>>');
|
|
|
|
eid("url-clear").style.display = "block";
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
break;
|
2022-11-12 16:40:11 +00:00
|
|
|
case 2: //enable back + information popup
|
|
|
|
popup("error", 1, text);
|
|
|
|
changeDownloadButton(1, '>>');
|
|
|
|
eid("url-clear").style.display = "block";
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
break;
|
2022-10-09 18:44:00 +01:00
|
|
|
}
|
|
|
|
}
|
2023-07-18 20:50:51 +01:00
|
|
|
function internetError() {
|
|
|
|
eid("url-input-area").disabled = false
|
|
|
|
changeDownloadButton(2, '!!');
|
|
|
|
setTimeout(() => { changeButton(1); }, 2500);
|
2023-09-08 22:10:43 +01:00
|
|
|
popup("error", 1, loc.ErrorNoInternet);
|
2023-07-18 20:50:51 +01:00
|
|
|
}
|
2022-11-04 08:49:58 +00:00
|
|
|
function resetSettings() {
|
|
|
|
localStorage.clear();
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2022-09-08 17:02:55 +01:00
|
|
|
async function pasteClipboard() {
|
2023-03-29 17:08:41 +01:00
|
|
|
try {
|
|
|
|
let t = await navigator.clipboard.readText();
|
|
|
|
if (regex.test(t)) {
|
|
|
|
eid("url-input-area").value = t;
|
|
|
|
download(eid("url-input-area").value);
|
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
} catch (e) {
|
2023-09-08 22:10:43 +01:00
|
|
|
let errorMessage = loc.FeatureErrorGeneric;
|
2023-08-04 19:43:12 +01:00
|
|
|
let doError = true;
|
2023-08-11 17:07:34 +01:00
|
|
|
let error = String(e).toLowerCase();
|
2023-08-04 19:43:12 +01:00
|
|
|
|
2023-09-08 22:10:43 +01:00
|
|
|
if (error.includes("denied")) errorMessage = loc.ClipboardErrorNoPermission;
|
2023-08-11 17:07:34 +01:00
|
|
|
if (error.includes("dismissed") || isIOS) doError = false;
|
2023-09-08 22:10:43 +01:00
|
|
|
if (error.includes("function") && isFirefox) errorMessage = loc.ClipboardErrorFirefox;
|
2023-08-04 19:43:12 +01:00
|
|
|
|
|
|
|
if (doError) popup("error", 1, errorMessage);
|
|
|
|
}
|
2022-09-08 17:02:55 +01:00
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
async function download(url) {
|
|
|
|
changeDownloadButton(2, '...');
|
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;
|
2022-11-12 16:40:11 +00:00
|
|
|
let req = {
|
2023-12-14 23:46:49 +00:00
|
|
|
url,
|
2022-11-12 16:40:11 +00:00
|
|
|
aFormat: sGet("aFormat").slice(0, 4),
|
2023-10-12 18:14:54 +01:00
|
|
|
filenamePattern: sGet("filenamePattern"),
|
2023-02-26 16:49:25 +00:00
|
|
|
dubLang: false
|
|
|
|
}
|
|
|
|
if (sGet("dubLang") === "auto") {
|
|
|
|
req.dubLang = true
|
|
|
|
} else if (sGet("dubLang") === "custom") {
|
|
|
|
req.dubLang = true
|
2022-11-12 16:40:11 +00:00
|
|
|
}
|
2023-03-15 16:18:31 +00:00
|
|
|
if (sGet("vimeoDash") === "true") req.vimeoDash = true;
|
2022-11-12 16:40:11 +00:00
|
|
|
if (sGet("audioMode") === "true") {
|
2023-02-26 16:49:25 +00:00
|
|
|
req.isAudioOnly = true;
|
|
|
|
if (sGet("fullTikTokAudio") === "true") req.isTTFullAudio = true; // audio tiktok full
|
2022-08-16 11:31:41 +01:00
|
|
|
} else {
|
2023-02-26 16:49:25 +00:00
|
|
|
req.vQuality = sGet("vQuality").slice(0, 4);
|
|
|
|
if (sGet("muteAudio") === "true") req.isAudioMuted = true;
|
|
|
|
if (url.includes("youtube.com/") || url.includes("/youtu.be/")) req.vCodec = sGet("vCodec").slice(0, 4);
|
2022-08-16 11:31:41 +01:00
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
|
2023-08-24 09:31:39 +01:00
|
|
|
if (sGet("disableMetadata") === "true") req.disableMetadata = true;
|
2024-01-17 05:38:51 +00:00
|
|
|
if (sGet("twitterGif") === "true") req.twitterGif = true;
|
2023-08-24 09:31:39 +01:00
|
|
|
|
2023-05-16 21:13:11 +01:00
|
|
|
let j = await fetch(`${apiURL}/api/json`, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(req),
|
|
|
|
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }
|
|
|
|
}).then((r) => { return r.json() }).catch((e) => { return false });
|
|
|
|
if (!j) {
|
|
|
|
internetError();
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j && j.status !== "error" && j.status !== "rate-limit") {
|
|
|
|
if (j.text && (!j.url || !j.picker)) {
|
|
|
|
if (j.status === "success") {
|
|
|
|
changeButton(2, j.text)
|
2023-09-08 22:10:43 +01:00
|
|
|
} else changeButton(0, loc.ErrorNoUrlReturned);
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
|
|
|
switch (j.status) {
|
|
|
|
case "redirect":
|
|
|
|
changeDownloadButton(2, '>>>');
|
|
|
|
setTimeout(() => { changeButton(1); }, 1500);
|
|
|
|
sGet("downloadPopup") === "true" ? popup('download', 1, j.url) : window.open(j.url, '_blank');
|
|
|
|
break;
|
|
|
|
case "picker":
|
|
|
|
if (j.audio && j.picker) {
|
2023-08-13 21:07:05 +01:00
|
|
|
changeDownloadButton(2, '>>>');
|
|
|
|
popup('picker', 1, { audio: j.audio, arr: j.picker, type: j.pickerType });
|
|
|
|
setTimeout(() => { changeButton(1) }, 2500);
|
2023-05-16 21:13:11 +01:00
|
|
|
} else if (j.picker) {
|
|
|
|
changeDownloadButton(2, '>>>');
|
|
|
|
popup('picker', 1, { arr: j.picker, type: j.pickerType });
|
|
|
|
setTimeout(() => { changeButton(1) }, 2500);
|
|
|
|
} else {
|
2023-09-08 22:10:43 +01:00
|
|
|
changeButton(0, loc.ErrorNoUrlReturned);
|
2022-07-22 09:05:36 +01:00
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
break;
|
|
|
|
case "stream":
|
|
|
|
changeDownloadButton(2, '?..')
|
|
|
|
fetch(`${j.url}&p=1`).then(async (res) => {
|
|
|
|
let jp = await res.json();
|
|
|
|
if (jp.status === "continue") {
|
2023-08-11 16:53:30 +01:00
|
|
|
changeDownloadButton(2, '>>>');
|
2023-12-02 16:51:08 +00:00
|
|
|
if (sGet("downloadPopup") === "true") {
|
|
|
|
popup('download', 1, j.url)
|
|
|
|
} else {
|
|
|
|
if (isMobile || isSafari) {
|
|
|
|
window.location.href = j.url;
|
|
|
|
} else window.open(j.url, '_blank');
|
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
setTimeout(() => { changeButton(1) }, 2500);
|
|
|
|
} else {
|
|
|
|
changeButton(0, jp.text);
|
|
|
|
}
|
|
|
|
}).catch((error) => internetError());
|
|
|
|
break;
|
|
|
|
case "success":
|
|
|
|
changeButton(2, j.text);
|
|
|
|
break;
|
|
|
|
default:
|
2023-09-08 22:10:43 +01:00
|
|
|
changeButton(0, loc.ErrorUnknownStatus);
|
2023-05-16 21:13:11 +01:00
|
|
|
break;
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2023-05-16 21:13:11 +01:00
|
|
|
} else if (j && j.text) {
|
|
|
|
changeButton(0, j.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async function loadCelebrationsEmoji() {
|
|
|
|
let bac = eid("about-footer").innerHTML;
|
|
|
|
try {
|
2023-08-04 19:43:12 +01:00
|
|
|
let j = await fetch(`/onDemand?blockId=1`).then((r) => { if (r.status === 200) { return r.json() } else { return false } }).catch(() => { return false });
|
2023-05-16 21:13:11 +01:00
|
|
|
if (j && j.status === "success" && j.text) {
|
2023-08-11 16:53:30 +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
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
eid("about-footer").innerHTML = bac;
|
|
|
|
}
|
2022-07-08 19:17:56 +01:00
|
|
|
}
|
2022-09-11 16:04:06 +01:00
|
|
|
async function loadOnDemand(elementId, blockId) {
|
2023-05-16 21:31:22 +01:00
|
|
|
let j = {};
|
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 {
|
|
|
|
if (store.historyContent) {
|
|
|
|
j = store.historyContent;
|
|
|
|
} else {
|
2023-08-04 19:43:12 +01:00
|
|
|
await fetch(`/onDemand?blockId=${blockId}`).then(async(r) => {
|
2023-05-16 21:31:22 +01:00
|
|
|
j = await r.json();
|
|
|
|
if (j && j.status === "success") {
|
|
|
|
store.historyContent = j;
|
|
|
|
} else throw new Error();
|
|
|
|
}).catch(() => { throw new Error() });
|
2023-05-16 21:13:11 +01:00
|
|
|
}
|
|
|
|
if (j.text) {
|
2023-09-08 22:10:43 +01:00
|
|
|
eid(elementId).innerHTML = `<button class="switch bottom-margin" onclick="restoreUpdateHistory()">${loc.ChangelogPressToHide}</button>${j.text}`;
|
2023-05-16 21:31:22 +01:00
|
|
|
} else throw new Error()
|
2022-11-15 17:37:33 +00:00
|
|
|
} catch (e) {
|
|
|
|
eid(elementId).innerHTML = store.historyButton;
|
2022-09-11 16:04:06 +01:00
|
|
|
internetError()
|
2022-11-15 17:37:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function restoreUpdateHistory() {
|
|
|
|
eid("changelog-history").innerHTML = store.historyButton;
|
2022-09-11 16:04:06 +01:00
|
|
|
}
|
2023-09-08 22:10:43 +01:00
|
|
|
function unpackSettings(b64) {
|
2023-09-09 06:17:55 +01:00
|
|
|
let changed = null;
|
2023-09-08 22:10:43 +01:00
|
|
|
try {
|
|
|
|
let settingsToImport = JSON.parse(atob(b64));
|
|
|
|
let currentSettings = JSON.parse(JSON.stringify(localStorage));
|
|
|
|
for (let s in settingsToImport) {
|
|
|
|
if (checkboxes.includes(s) && (settingsToImport[s] === "true" || settingsToImport[s] === "false")
|
|
|
|
&& currentSettings[s] !== settingsToImport[s]) {
|
|
|
|
sSet(s, settingsToImport[s]);
|
|
|
|
changed = true
|
|
|
|
}
|
|
|
|
if (switchers[s] && switchers[s].includes(settingsToImport[s])
|
|
|
|
&& currentSettings[s] !== settingsToImport[s]) {
|
|
|
|
sSet(s, settingsToImport[s]);
|
|
|
|
changed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
changed = false;
|
|
|
|
}
|
|
|
|
return changed
|
|
|
|
}
|
2023-10-14 17:51:53 +01:00
|
|
|
function updateFilenamePreview() {
|
|
|
|
let videoFilePreview = ``;
|
|
|
|
let audioFilePreview = ``;
|
|
|
|
let resMatch = {
|
|
|
|
"max": "3840x2160",
|
|
|
|
"2160": "3840x2160",
|
|
|
|
"1440": "2560x1440",
|
|
|
|
"1080": "1920x1080",
|
|
|
|
"720": "1280x720",
|
|
|
|
"480": "854x480",
|
|
|
|
"360": "640x360",
|
|
|
|
}
|
|
|
|
// "dubLang"
|
|
|
|
// sGet("muteAudio") === "true"
|
|
|
|
switch(sGet("filenamePattern")) {
|
|
|
|
case "classic":
|
|
|
|
videoFilePreview = `youtube_yPYZpwSpKmA_${resMatch[sGet('vQuality')]}_${sGet('vCodec')}`
|
|
|
|
+ `${sGet("muteAudio") === "true" ? "_mute" : ""}.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`;
|
|
|
|
audioFilePreview = `youtube_yPYZpwSpKmA_audio.${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 "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 "nerdy":
|
|
|
|
videoFilePreview =
|
|
|
|
`${loc.FilenamePreviewVideoTitle} `
|
|
|
|
+ `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, `
|
|
|
|
+ `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube, yPYZpwSpKmA).${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
|
|
|
|
}
|
|
|
|
function loadSettings() {
|
|
|
|
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()
|
|
|
|
}
|
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
|
|
|
|
2022-07-08 19:17:56 +01:00
|
|
|
changeDownloadButton(0, '>>');
|
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");
|
|
|
|
|
2023-09-08 22:10:43 +01:00
|
|
|
if (pageQuery.has("u") && regex.test(pageQuery.get("u"))) {
|
|
|
|
eid("url-input-area").value = pageQuery.get("u");
|
|
|
|
button()
|
|
|
|
}
|
2023-09-09 06:17:55 +01:00
|
|
|
if (pageQuery.has("migration")) {
|
|
|
|
if (pageQuery.has("settingsData") && !sGet("migrated")) {
|
2023-09-08 22:10:43 +01:00
|
|
|
let setUn = unpackSettings(pageQuery.get("settingsData"));
|
2023-09-09 06:17:55 +01:00
|
|
|
if (setUn !== null) {
|
|
|
|
if (setUn) {
|
|
|
|
sSet("migrated", "true")
|
|
|
|
}
|
|
|
|
}
|
2023-09-08 22:10:43 +01:00
|
|
|
}
|
|
|
|
loadSettings();
|
|
|
|
detectColorScheme();
|
2022-08-16 11:31:41 +01:00
|
|
|
}
|
2023-09-08 22:10:43 +01:00
|
|
|
window.history.replaceState(null, '', window.location.pathname);
|
|
|
|
|
|
|
|
notificationCheck();
|
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
|
|
|
}
|
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
|
|
|
})
|
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
|
|
|
}
|