Piped/src/main.js

143 lines
4.3 KiB
JavaScript
Raw Normal View History

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,
} from "@fortawesome/free-solid-svg-icons";
2021-06-30 20:26:04 +00:00
import { faGithub, faBitcoin, faYoutube } from "@fortawesome/free-brands-svg-icons";
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,
);
2020-11-17 05:15:35 +00:00
import("uikit/dist/css/uikit-core.css");
import("uikit/dist/js/uikit-core.min");
2020-11-17 05:15:35 +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-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) {
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]);
}
return fetch(url, options).then(response => {
return response.json();
});
},
purifyHTML(original) {
return DOMPurify.sanitize(original);
},
setPreference(key, value) {
2021-07-03 19:33:59 +00:00
if (localStorage) localStorage.setItem(key, value);
},
getPreferenceBoolean(key, defaultVal) {
var value;
2021-07-03 19:33:59 +00:00
if (
(value = this.$route.query[key]) !== undefined ||
(localStorage && (value = localStorage.getItem(key)) !== null)
) {
switch (String(value)) {
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 (
(value = this.$route.query[key]) !== undefined ||
(localStorage && (value = localStorage.getItem(key)) !== null)
) {
return value;
} else return defaultVal;
},
},
computed: {
backgroundColor() {
2021-07-03 19:33:59 +00:00
return this.getPreferenceString("theme", "dark") === "light" ? "#fff" : "#0b0e0f";
},
secondaryBackgroundColor() {
2021-07-03 19:33:59 +00:00
return this.getPreferenceString("theme", "dark") === "light" ? "#e5e5e5" : "#242727";
},
foregroundColor() {
2021-07-03 19:33:59 +00:00
return this.getPreferenceString("theme", "dark") === "light" ? "#15191a" : "#0b0e0f";
},
secondaryForegroundColor() {
2021-07-03 19:33:59 +00:00
return this.getPreferenceString("theme", "dark") === "light" ? "#666" : "#393d3d";
},
darkMode() {
2021-07-03 19:33:59 +00:00
return this.getPreferenceString("theme", "dark") !== "light";
},
},
};
const app = createApp(App);
app.use(router);
app.mixin(mixin);
app.component("font-awesome-icon", FontAwesomeIcon);
app.mount("#app");