Tree shake DomPurify.

This commit is contained in:
Kavin
2023-07-22 17:22:57 +01:00
parent 9252751fd6
commit 22c10a6f9a
7 changed files with 56 additions and 32 deletions

View File

@@ -56,8 +56,6 @@ library.add(
import router from "@/router/router.js";
import App from "./App.vue";
import DOMPurify from "dompurify";
import TimeAgo from "javascript-time-ago";
import en from "javascript-time-ago/locale/en";
@@ -120,9 +118,6 @@ const mixin = {
return response.json();
});
},
purifyHTML(original) {
return DOMPurify.sanitize(original);
},
setPreference(key, value, disableAlert = false) {
try {
localStorage.setItem(key, value);
@@ -195,19 +190,6 @@ const mixin = {
timeAgo(time) {
return timeAgo.format(time);
},
urlify(string) {
if (!string) return "";
const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g;
return string
.replace(urlRegex, url => {
if (url.endsWith("</a>") || url.endsWith("<a")) return url;
return `<a href="${url}" target="_blank">${url}</a>`;
})
.replace(emailRegex, email => {
return `<a href="mailto:${email}">${email}</a>`;
});
},
async updateWatched(videos) {
if (window.db && this.getPreferenceBoolean("watchHistory", false)) {
var tx = window.db.transaction("watch_history", "readonly");
@@ -265,15 +247,6 @@ const mixin = {
elem.click();
elem.remove();
},
rewriteDescription(text) {
return this.urlify(text)
.replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1")
.replaceAll(
/(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm,
"/watch?v=$1",
)
.replaceAll("\n", "<br>");
},
getChannelGroupsCursor() {
if (!window.db) return;
var tx = window.db.transaction("channel_groups", "readonly");