2021-04-07 11:45:40 +00:00
|
|
|
import { createApp } from "vue";
|
|
|
|
import { library } from "@fortawesome/fontawesome-svg-core";
|
2021-07-03 19:33:59 +00:00
|
|
|
import {
|
|
|
|
faThumbsUp,
|
|
|
|
faThumbsDown,
|
|
|
|
faEye,
|
|
|
|
faThumbtack,
|
|
|
|
faCheck,
|
|
|
|
faHeart,
|
|
|
|
faHeadphones,
|
2021-07-04 18:57:57 +00:00
|
|
|
faRss,
|
2021-07-20 14:45:17 +00:00
|
|
|
faChevronLeft,
|
2021-07-03 19:33:59 +00:00
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2021-06-30 20:26:04 +00:00
|
|
|
import { faGithub, faBitcoin, faYoutube } from "@fortawesome/free-brands-svg-icons";
|
2021-04-07 11:45:40 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
2021-07-03 19:33:59 +00:00
|
|
|
library.add(
|
|
|
|
faThumbsUp,
|
|
|
|
faThumbsDown,
|
|
|
|
faEye,
|
|
|
|
faGithub,
|
|
|
|
faBitcoin,
|
|
|
|
faThumbtack,
|
|
|
|
faCheck,
|
|
|
|
faHeart,
|
|
|
|
faHeadphones,
|
|
|
|
faYoutube,
|
2021-07-04 18:57:57 +00:00
|
|
|
faRss,
|
2021-08-22 10:27:09 +00:00
|
|
|
faChevronLeft,
|
2021-07-03 19:33:59 +00:00
|
|
|
);
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2021-04-24 19:07:11 +00:00
|
|
|
import("uikit/dist/css/uikit-core.css");
|
|
|
|
import("uikit/dist/js/uikit-core.min");
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2021-04-07 11:45:40 +00:00
|
|
|
import router from "@/router/router";
|
|
|
|
import App from "./App.vue";
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2021-07-03 19:33:59 +00:00
|
|
|
import DOMPurify from "dompurify";
|
2021-06-06 19:12:03 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
import TimeAgo from "javascript-time-ago";
|
|
|
|
|
|
|
|
import en from "javascript-time-ago/locale/en";
|
|
|
|
|
|
|
|
TimeAgo.addDefaultLocale(en);
|
|
|
|
|
2021-08-25 16:30:21 +00:00
|
|
|
import { createI18n } from "vue-i18n";
|
|
|
|
import enLocale from "@/locales/en.json";
|
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
const timeAgo = new TimeAgo("en-US");
|
|
|
|
|
2021-05-10 18:14:28 +00:00
|
|
|
import("./registerServiceWorker");
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2020-11-27 06:46:36 +00:00
|
|
|
const mixin = {
|
|
|
|
methods: {
|
2021-07-03 19:33:59 +00:00
|
|
|
timeFormat: function(duration) {
|
|
|
|
var pad = function(num, size) {
|
2020-11-27 06:46:36 +00:00
|
|
|
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 08:03:10 +00:00
|
|
|
if (hours > 0) str += hours + ":";
|
2020-11-27 06:46:36 +00:00
|
|
|
|
|
|
|
str += pad(minutes, 2) + ":" + pad(seconds, 2);
|
|
|
|
|
|
|
|
return str;
|
2021-02-24 09:35:41 +00:00
|
|
|
},
|
2021-05-30 22:06:35 +00:00
|
|
|
numberFormat(num) {
|
|
|
|
const digits = 2;
|
|
|
|
const si = [
|
|
|
|
{ value: 1, symbol: "" },
|
2021-07-03 19:33:59 +00:00
|
|
|
{ value: 1e3, symbol: "k" },
|
|
|
|
{ value: 1e6, symbol: "M" },
|
|
|
|
{ value: 1e9, symbol: "B" },
|
2021-05-30 22:06:35 +00:00
|
|
|
];
|
|
|
|
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-02 18:52:58 +00:00
|
|
|
addCommas(num) {
|
2021-07-03 19:33:59 +00:00
|
|
|
num = parseInt(num);
|
|
|
|
return num.toLocaleString("en-US");
|
2021-06-02 18:52:58 +00:00
|
|
|
},
|
2021-07-03 19:33:59 +00:00
|
|
|
fetchJson: function(url, params, options) {
|
2021-06-15 11:37:35 +00:00
|
|
|
if (params) {
|
|
|
|
url = new URL(url);
|
2021-07-03 19:33:59 +00:00
|
|
|
for (var param in params) url.searchParams.set(param, params[param]);
|
2021-06-15 11:37:35 +00:00
|
|
|
}
|
2021-04-07 11:45:40 +00:00
|
|
|
return fetch(url, options).then(response => {
|
|
|
|
return response.json();
|
|
|
|
});
|
|
|
|
},
|
2021-06-06 19:12:03 +00:00
|
|
|
purifyHTML(original) {
|
|
|
|
return DOMPurify.sanitize(original);
|
2021-07-03 19:24:09 +00:00
|
|
|
},
|
|
|
|
setPreference(key, value) {
|
2021-07-03 19:33:59 +00:00
|
|
|
if (localStorage) localStorage.setItem(key, value);
|
2021-07-03 19:24:09 +00:00
|
|
|
},
|
|
|
|
getPreferenceBoolean(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-03 19:33:59 +00:00
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-03 19:33:59 +00:00
|
|
|
) {
|
2021-08-25 16:30:21 +00:00
|
|
|
switch (String(value).toLowerCase()) {
|
2021-07-03 19:24:09 +00:00
|
|
|
case "true":
|
|
|
|
case "1":
|
|
|
|
case "on":
|
|
|
|
case "yes":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
|
|
|
getPreferenceString(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-03 19:33:59 +00:00
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-03 19:33:59 +00:00
|
|
|
) {
|
2021-07-03 19:24:09 +00:00
|
|
|
return value;
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
2021-07-04 18:26:02 +00:00
|
|
|
getPreferenceNumber(key, defaultVal) {
|
|
|
|
var value;
|
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-04 18:26:02 +00:00
|
|
|
) {
|
|
|
|
return Number(value);
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
|
|
|
apiUrl() {
|
|
|
|
return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks");
|
|
|
|
},
|
2021-07-05 18:33:00 +00:00
|
|
|
getEffectiveTheme() {
|
|
|
|
var theme = this.getPreferenceString("theme", "dark");
|
|
|
|
if (theme === "auto")
|
|
|
|
theme =
|
|
|
|
window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
|
|
return theme;
|
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
getAuthToken() {
|
|
|
|
return this.getPreferenceString("authToken" + this.hashCode(this.apiUrl()));
|
|
|
|
},
|
|
|
|
hashCode(s) {
|
|
|
|
return s.split("").reduce(function(a, b) {
|
|
|
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
|
|
return a & a;
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
timeAgo(time) {
|
|
|
|
return timeAgo.format(time);
|
|
|
|
},
|
2021-07-24 15:17:12 +00:00
|
|
|
urlify(string) {
|
|
|
|
const regex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
|
2021-08-22 10:27:09 +00:00
|
|
|
if (!string) return "";
|
|
|
|
return string.replace(regex, url => {
|
|
|
|
return `<a class="uk-button uk-button-text" href="${url}" target="_blank">${url}</a>`;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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));
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
if (event.target.result) {
|
|
|
|
video.watched = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2021-06-28 19:45:03 +00:00
|
|
|
computed: {
|
|
|
|
backgroundColor() {
|
2021-07-05 18:33:00 +00:00
|
|
|
return this.getEffectiveTheme() === "light" ? "#fff" : "#0b0e0f";
|
2021-06-28 19:45:03 +00:00
|
|
|
},
|
|
|
|
secondaryBackgroundColor() {
|
2021-07-05 18:33:00 +00:00
|
|
|
return this.getEffectiveTheme() === "light" ? "#e5e5e5" : "#242727";
|
2021-06-28 19:45:03 +00:00
|
|
|
},
|
|
|
|
foregroundColor() {
|
2021-07-05 18:33:00 +00:00
|
|
|
return this.getEffectiveTheme() === "light" ? "#15191a" : "#0b0e0f";
|
2021-06-28 19:45:03 +00:00
|
|
|
},
|
|
|
|
secondaryForegroundColor() {
|
2021-07-05 18:33:00 +00:00
|
|
|
return this.getEffectiveTheme() === "light" ? "#666" : "#393d3d";
|
2021-06-28 19:45:03 +00:00
|
|
|
},
|
|
|
|
darkMode() {
|
2021-07-05 18:33:00 +00:00
|
|
|
return this.getEffectiveTheme() !== "light";
|
2021-07-03 19:33:59 +00:00
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
authenticated(_this) {
|
|
|
|
return _this.getAuthToken() !== undefined;
|
|
|
|
},
|
2021-08-28 12:00:17 +00:00
|
|
|
testLocalStorage() {
|
|
|
|
try {
|
|
|
|
if (window.localStorage !== undefined) localStorage;
|
|
|
|
return true;
|
|
|
|
} catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2021-07-03 19:33:59 +00:00
|
|
|
},
|
2021-04-07 11:45:40 +00:00
|
|
|
};
|
|
|
|
|
2021-08-25 16:30:21 +00:00
|
|
|
const i18n = createI18n({
|
|
|
|
globalInjection: true,
|
|
|
|
legacy: false,
|
|
|
|
locale: "en",
|
|
|
|
fallbackLocale: "en",
|
|
|
|
messages: {
|
|
|
|
en: enLocale,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
window.i18n = i18n;
|
|
|
|
|
2021-04-07 11:45:40 +00:00
|
|
|
const app = createApp(App);
|
2021-08-25 16:30:21 +00:00
|
|
|
app.use(i18n);
|
2021-04-07 11:45:40 +00:00
|
|
|
app.use(router);
|
|
|
|
app.mixin(mixin);
|
|
|
|
app.component("font-awesome-icon", FontAwesomeIcon);
|
|
|
|
app.mount("#app");
|