2021-04-07 17:15:40 +05:30
|
|
|
import { createApp } from "vue";
|
|
|
|
import { library } from "@fortawesome/fontawesome-svg-core";
|
2021-07-04 01:03:59 +05:30
|
|
|
import {
|
|
|
|
faEye,
|
|
|
|
faThumbtack,
|
|
|
|
faCheck,
|
|
|
|
faHeart,
|
|
|
|
faHeadphones,
|
2021-07-05 00:27:57 +05:30
|
|
|
faRss,
|
2021-07-20 20:15:17 +05:30
|
|
|
faChevronLeft,
|
2021-11-02 01:53:04 +05:30
|
|
|
faLevelDownAlt,
|
2021-10-17 19:48:51 +05:30
|
|
|
faTv,
|
2021-11-04 16:22:28 +05:30
|
|
|
faLevelUpAlt,
|
2022-01-31 05:18:27 +05:30
|
|
|
faBroadcastTower,
|
2022-04-07 08:03:25 +05:30
|
|
|
faCirclePlus,
|
|
|
|
faCircleMinus,
|
|
|
|
faXmark,
|
2022-07-22 02:21:41 +05:30
|
|
|
faClone,
|
2022-08-28 19:59:11 +05:30
|
|
|
faShare,
|
2022-09-09 23:43:56 +05:30
|
|
|
faBook,
|
|
|
|
faServer,
|
|
|
|
faDonate,
|
2021-07-04 01:03:59 +05:30
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2022-08-28 20:14:55 +05:30
|
|
|
import { faGithub, faBitcoin } from "@fortawesome/free-brands-svg-icons";
|
2021-04-07 17:15:40 +05:30
|
|
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
2021-07-04 01:03:59 +05:30
|
|
|
library.add(
|
|
|
|
faEye,
|
|
|
|
faGithub,
|
|
|
|
faBitcoin,
|
|
|
|
faThumbtack,
|
|
|
|
faCheck,
|
|
|
|
faHeart,
|
|
|
|
faHeadphones,
|
2021-07-05 00:27:57 +05:30
|
|
|
faRss,
|
2021-08-22 15:57:09 +05:30
|
|
|
faChevronLeft,
|
2021-11-02 01:53:04 +05:30
|
|
|
faLevelDownAlt,
|
2021-11-04 16:22:28 +05:30
|
|
|
faLevelUpAlt,
|
2021-10-17 19:48:51 +05:30
|
|
|
faTv,
|
2022-01-31 05:18:27 +05:30
|
|
|
faBroadcastTower,
|
2022-04-07 08:03:25 +05:30
|
|
|
faCirclePlus,
|
|
|
|
faCircleMinus,
|
|
|
|
faXmark,
|
2022-07-22 02:21:41 +05:30
|
|
|
faClone,
|
2022-08-28 19:59:11 +05:30
|
|
|
faShare,
|
2022-09-09 23:43:56 +05:30
|
|
|
faBook,
|
|
|
|
faServer,
|
|
|
|
faDonate,
|
2021-07-04 01:03:59 +05:30
|
|
|
);
|
2020-11-17 10:45:35 +05:30
|
|
|
|
2021-12-28 20:09:20 +05:30
|
|
|
import router from "@/router/router.js";
|
2021-04-07 17:15:40 +05:30
|
|
|
import App from "./App.vue";
|
2020-11-17 10:45:35 +05:30
|
|
|
|
2021-07-04 01:03:59 +05:30
|
|
|
import DOMPurify from "dompurify";
|
2021-06-07 00:42:03 +05:30
|
|
|
|
2021-07-17 04:26:41 +05:30
|
|
|
import TimeAgo from "javascript-time-ago";
|
|
|
|
|
|
|
|
import en from "javascript-time-ago/locale/en";
|
|
|
|
|
|
|
|
TimeAgo.addDefaultLocale(en);
|
|
|
|
|
2021-08-25 22:00:21 +05:30
|
|
|
import { createI18n } from "vue-i18n";
|
|
|
|
import enLocale from "@/locales/en.json";
|
2022-08-17 19:04:57 +05:30
|
|
|
import "@unocss/reset/tailwind.css";
|
|
|
|
import "uno.css";
|
2021-08-25 22:00:21 +05:30
|
|
|
|
2021-07-17 04:26:41 +05:30
|
|
|
const timeAgo = new TimeAgo("en-US");
|
|
|
|
|
2021-05-10 23:44:28 +05:30
|
|
|
import("./registerServiceWorker");
|
2020-11-17 10:45:35 +05:30
|
|
|
|
2020-11-27 12:16:36 +05:30
|
|
|
const mixin = {
|
|
|
|
methods: {
|
2022-01-01 20:12:20 +05:30
|
|
|
timeFormat: function (duration) {
|
|
|
|
var pad = function (num, size) {
|
2020-11-27 12:16:36 +05:30
|
|
|
return ("000" + num).slice(size * -1);
|
|
|
|
};
|
|
|
|
|
|
|
|
var time = parseFloat(duration).toFixed(3),
|
|
|
|
hours = Math.floor(time / 60 / 60),
|
|
|
|
minutes = Math.floor(time / 60) % 60,
|
|
|
|
seconds = Math.floor(time - minutes * 60);
|
|
|
|
|
|
|
|
var str = "";
|
|
|
|
|
2021-01-07 13:33:10 +05:30
|
|
|
if (hours > 0) str += hours + ":";
|
2020-11-27 12:16:36 +05:30
|
|
|
|
|
|
|
str += pad(minutes, 2) + ":" + pad(seconds, 2);
|
|
|
|
|
|
|
|
return str;
|
2021-02-24 15:05:41 +05:30
|
|
|
},
|
2021-05-31 03:36:35 +05:30
|
|
|
numberFormat(num) {
|
|
|
|
const digits = 2;
|
|
|
|
const si = [
|
|
|
|
{ value: 1, symbol: "" },
|
2021-07-04 01:03:59 +05:30
|
|
|
{ value: 1e3, symbol: "k" },
|
|
|
|
{ value: 1e6, symbol: "M" },
|
|
|
|
{ value: 1e9, symbol: "B" },
|
2021-05-31 03:36:35 +05:30
|
|
|
];
|
|
|
|
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
|
|
|
for (var i = si.length - 1; i > 0; i--) {
|
|
|
|
if (num >= si[i].value) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol;
|
|
|
|
},
|
2021-06-03 00:22:58 +05:30
|
|
|
addCommas(num) {
|
2021-07-04 01:03:59 +05:30
|
|
|
num = parseInt(num);
|
|
|
|
return num.toLocaleString("en-US");
|
2021-06-03 00:22:58 +05:30
|
|
|
},
|
2022-01-01 20:12:20 +05:30
|
|
|
fetchJson: function (url, params, options) {
|
2021-06-15 17:07:35 +05:30
|
|
|
if (params) {
|
|
|
|
url = new URL(url);
|
2021-07-04 01:03:59 +05:30
|
|
|
for (var param in params) url.searchParams.set(param, params[param]);
|
2021-06-15 17:07:35 +05:30
|
|
|
}
|
2021-04-07 17:15:40 +05:30
|
|
|
return fetch(url, options).then(response => {
|
|
|
|
return response.json();
|
|
|
|
});
|
|
|
|
},
|
2021-06-07 00:42:03 +05:30
|
|
|
purifyHTML(original) {
|
|
|
|
return DOMPurify.sanitize(original);
|
2021-07-04 00:54:09 +05:30
|
|
|
},
|
|
|
|
setPreference(key, value) {
|
2021-07-04 01:03:59 +05:30
|
|
|
if (localStorage) localStorage.setItem(key, value);
|
2021-07-04 00:54:09 +05:30
|
|
|
},
|
|
|
|
getPreferenceBoolean(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-04 01:03:59 +05:30
|
|
|
if (
|
2021-08-25 22:00:21 +05:30
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 17:30:17 +05:30
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-04 01:03:59 +05:30
|
|
|
) {
|
2021-08-25 22:00:21 +05:30
|
|
|
switch (String(value).toLowerCase()) {
|
2021-07-04 00:54:09 +05:30
|
|
|
case "true":
|
|
|
|
case "1":
|
|
|
|
case "on":
|
|
|
|
case "yes":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
|
|
|
getPreferenceString(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-04 01:03:59 +05:30
|
|
|
if (
|
2021-08-25 22:00:21 +05:30
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 17:30:17 +05:30
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-04 01:03:59 +05:30
|
|
|
) {
|
2021-07-04 00:54:09 +05:30
|
|
|
return value;
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
2021-07-04 23:56:02 +05:30
|
|
|
getPreferenceNumber(key, defaultVal) {
|
|
|
|
var value;
|
|
|
|
if (
|
2021-08-25 22:00:21 +05:30
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 17:30:17 +05:30
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-04 23:56:02 +05:30
|
|
|
) {
|
|
|
|
return Number(value);
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
|
|
|
apiUrl() {
|
|
|
|
return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks");
|
|
|
|
},
|
2022-07-21 09:34:57 +05:30
|
|
|
authApiUrl() {
|
|
|
|
if (this.getPreferenceBoolean("authInstance", false)) {
|
|
|
|
return this.getPreferenceString("auth_instance_url", this.apiUrl());
|
|
|
|
} else return this.apiUrl();
|
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
getAuthToken() {
|
2022-07-21 09:34:57 +05:30
|
|
|
return this.getPreferenceString("authToken" + this.hashCode(this.authApiUrl()));
|
2021-07-17 04:26:41 +05:30
|
|
|
},
|
|
|
|
hashCode(s) {
|
2022-01-01 20:12:20 +05:30
|
|
|
return s.split("").reduce(function (a, b) {
|
2021-07-17 04:26:41 +05:30
|
|
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
|
|
return a & a;
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
timeAgo(time) {
|
|
|
|
return timeAgo.format(time);
|
|
|
|
},
|
2021-07-24 20:47:12 +05:30
|
|
|
urlify(string) {
|
2021-08-22 15:57:09 +05:30
|
|
|
if (!string) return "";
|
2022-02-14 01:07:05 +05:30
|
|
|
const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
|
|
|
|
const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g;
|
|
|
|
return string
|
|
|
|
.replace(urlRegex, url => {
|
2022-10-06 14:24:01 +05:30
|
|
|
if (url.endsWith("</a>") || url.endsWith("<a")) return url;
|
2022-02-14 01:07:05 +05:30
|
|
|
return `<a href="${url}" target="_blank">${url}</a>`;
|
|
|
|
})
|
|
|
|
.replace(emailRegex, email => {
|
|
|
|
return `<a href="mailto:${email}">${email}</a>`;
|
|
|
|
});
|
2021-08-22 15:57:09 +05:30
|
|
|
},
|
|
|
|
async updateWatched(videos) {
|
|
|
|
if (window.db) {
|
|
|
|
var tx = window.db.transaction("watch_history", "readonly");
|
|
|
|
var store = tx.objectStore("watch_history");
|
|
|
|
videos.map(async video => {
|
|
|
|
var request = store.get(video.url.substr(-11));
|
2022-01-01 20:12:20 +05:30
|
|
|
request.onsuccess = function (event) {
|
2021-08-22 15:57:09 +05:30
|
|
|
if (event.target.result) {
|
|
|
|
video.watched = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-08-01 19:46:06 +05:30
|
|
|
getLocalSubscriptions() {
|
|
|
|
return JSON.parse(localStorage.getItem("localSubscriptions"));
|
|
|
|
},
|
|
|
|
isSubscribedLocally(channelId) {
|
|
|
|
const localSubscriptions = this.getLocalSubscriptions();
|
|
|
|
if (localSubscriptions == null) return false;
|
|
|
|
return localSubscriptions.includes(channelId);
|
|
|
|
},
|
|
|
|
handleLocalSubscriptions(channelId) {
|
|
|
|
var localSubscriptions = this.getLocalSubscriptions() ?? [];
|
|
|
|
if (localSubscriptions.includes(channelId))
|
|
|
|
localSubscriptions.splice(localSubscriptions.indexOf(channelId));
|
|
|
|
else localSubscriptions.push(channelId);
|
|
|
|
// Sort for better cache hits
|
|
|
|
localSubscriptions.sort();
|
|
|
|
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
|
|
|
|
},
|
|
|
|
getUnauthenticatedChannels() {
|
2022-08-04 11:38:04 +05:30
|
|
|
const localSubscriptions = this.getLocalSubscriptions() ?? [];
|
2022-08-01 19:46:06 +05:30
|
|
|
return localSubscriptions.join(",");
|
|
|
|
},
|
2022-08-02 13:44:03 +05:30
|
|
|
/* generate a temporary file and ask the user to download it */
|
|
|
|
download(text, filename, type) {
|
|
|
|
var file = new Blob([text], { type: type });
|
|
|
|
|
|
|
|
const elem = document.createElement("a");
|
|
|
|
|
|
|
|
elem.href = URL.createObjectURL(file);
|
|
|
|
elem.download = filename;
|
|
|
|
elem.click();
|
|
|
|
elem.remove();
|
2022-08-02 13:38:26 +05:30
|
|
|
},
|
2021-04-07 17:15:40 +05:30
|
|
|
},
|
2021-06-29 01:15:03 +05:30
|
|
|
computed: {
|
2021-07-17 04:26:41 +05:30
|
|
|
authenticated(_this) {
|
|
|
|
return _this.getAuthToken() !== undefined;
|
|
|
|
},
|
2021-08-28 17:30:17 +05:30
|
|
|
testLocalStorage() {
|
|
|
|
try {
|
|
|
|
if (window.localStorage !== undefined) localStorage;
|
|
|
|
return true;
|
|
|
|
} catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2022-06-26 07:23:06 +05:30
|
|
|
async defaultLangage() {
|
2021-09-24 04:27:26 +05:30
|
|
|
const languages = window.navigator.languages;
|
|
|
|
for (let i = 0; i < languages.length; i++) {
|
|
|
|
try {
|
2022-06-26 07:23:06 +05:30
|
|
|
await import("./locales/" + languages[i] + ".json");
|
2021-09-24 04:27:26 +05:30
|
|
|
return languages[i];
|
|
|
|
} catch {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "en";
|
|
|
|
},
|
2021-07-04 01:03:59 +05:30
|
|
|
},
|
2021-10-27 06:29:03 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
TimeAgo: TimeAgo,
|
|
|
|
TimeAgoConfig: timeAgo,
|
|
|
|
};
|
|
|
|
},
|
2021-04-07 17:15:40 +05:30
|
|
|
};
|
|
|
|
|
2021-08-25 22:00:21 +05:30
|
|
|
const i18n = createI18n({
|
|
|
|
globalInjection: true,
|
|
|
|
legacy: false,
|
|
|
|
locale: "en",
|
|
|
|
fallbackLocale: "en",
|
|
|
|
messages: {
|
|
|
|
en: enLocale,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
window.i18n = i18n;
|
|
|
|
|
2021-04-07 17:15:40 +05:30
|
|
|
const app = createApp(App);
|
2021-08-25 22:00:21 +05:30
|
|
|
app.use(i18n);
|
2021-04-07 17:15:40 +05:30
|
|
|
app.use(router);
|
|
|
|
app.mixin(mixin);
|
2021-10-09 00:22:51 +05:30
|
|
|
app.component("FontAwesomeIcon", FontAwesomeIcon);
|
2021-04-07 17:15:40 +05:30
|
|
|
app.mount("#app");
|