// ==UserScript==
// @name VoidVerified
// @version 1.9.1
// @namespace http://tampermonkey.net/
// @author voidnyan
// @description Social enhancements for AniList.
// @homepageURL https://github.com/voidnyan/void-verified#voidverified
// @supportURL https://github.com/voidnyan/void-verified/issues
// @grant GM_xmlhttpRequest
// @match https://anilist.co/*
// @license MIT
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
const categories = {
users: "users",
paste: "paste",
css: "css",
misc: "misc",
};
const defaultSettings = {
copyColorFromProfile: {
defaultValue: true,
description: "Copy user color from their profile.",
category: categories.users,
},
moveSubscribeButtons: {
defaultValue: false,
description:
"Move activity subscribe button next to comments and likes.",
category: categories.misc,
},
hideLikeCount: {
defaultValue: false,
description: "Hide activity and reply like counts.",
category: categories.misc,
},
enabledForUsername: {
defaultValue: true,
description: "Display a verified sign next to usernames.",
category: categories.users,
},
enabledForProfileName: {
defaultValue: false,
description: "Display a verified sign next to a profile name.",
category: categories.users,
},
defaultSign: {
defaultValue: "✔",
description: "The default sign displayed next to a username.",
category: categories.users,
},
highlightEnabled: {
defaultValue: true,
description: "Highlight user activity with a border.",
category: categories.users,
},
highlightEnabledForReplies: {
defaultValue: true,
description: "Highlight replies with a border.",
category: categories.users,
},
highlightSize: {
defaultValue: "5px",
description: "Width of the highlight border.",
category: categories.users,
},
colorUserActivity: {
defaultValue: false,
description: "Color user activity links with user color.",
category: categories.users,
},
colorUserReplies: {
defaultValue: false,
description: "Color user reply links with user color.",
category: categories.users,
},
useDefaultHighlightColor: {
defaultValue: false,
description:
"Use fallback highlight color when user color is not specified.",
category: categories.users,
},
defaultHighlightColor: {
defaultValue: "#FFFFFF",
description: "Fallback highlight color.",
category: categories.users,
},
globalCssEnabled: {
defaultValue: false,
description: "Enable custom global CSS.",
category: categories.css,
},
globalCssAutoDisable: {
defaultValue: true,
description: "Disable global CSS when a profile has custom CSS.",
category: categories.css,
},
profileCssEnabled: {
defaultValue: false,
description: "Load user's custom CSS when viewing their profile.",
category: categories.css,
authRequired: true,
},
activityCssEnabled: {
defaultValue: false,
description:
"Load user's custom CSS when viewing their activity (direct link).",
category: categories.css,
authRequired: true,
},
onlyLoadCssFromVerifiedUser: {
defaultValue: false,
description: "Only load custom CSS from verified users.",
category: categories.css,
},
layoutDesignerEnabled: {
defaultValue: false,
description: "Enable Layout Designer in the settings tab.",
category: categories.misc,
authRequired: true,
},
quickAccessEnabled: {
defaultValue: false,
description: "Display quick access of users in home page.",
category: categories.users,
},
quickAccessBadge: {
defaultValue: false,
description:
"Display a badge on quick access when changes are detected on user's layout.",
category: categories.users,
},
quickAccessTimer: {
defaultValue: true,
description: "Display a timer until next update of Quick Access.",
category: categories.users,
},
pasteEnabled: {
defaultValue: false,
description:
"Automatically wrap pasted links and images with link and image tags.",
category: categories.paste,
},
pasteWrapImagesWithLink: {
defaultValue: false,
description: "Wrap images with a link tag.",
category: categories.paste,
},
pasteImageWidth: {
defaultValue: "420",
description: "Width used when pasting images.",
category: categories.paste,
},
pasteImagesToHostService: {
defaultValue: false,
description:
"Upload image from the clipboard to image host (configure below).",
category: categories.paste,
},
toasterEnabled: {
defaultValue: true,
description: "Enable toast notifications.",
category: categories.misc,
},
useElevatedFetch: {
defaultValue: false,
description:
"Query AniList API with elevated browser access (this might solve some API issues).",
category: categories.misc,
},
removeAnilistBlanks: {
defaultValue: false,
description: "Open AniList links in the same tab.",
category: categories.misc,
},
gifKeyboardEnabled: {
defaultValue: false,
description: "Add a GIF keyboard to activity fields.",
category: categories.misc,
},
};
class ColorFunctions {
static hexToRgb(hex) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `${r}, ${g}, ${b}`;
}
static rgbToHex(rgb) {
const [r, g, b] = rgb.split(",");
const hex = this.generateHex(r, g, b);
return hex;
}
static generateHex(r, g, b) {
return (
"#" +
[r, g, b]
.map((x) => {
const hex = Number(x).toString(16);
return hex.length === 1 ? "0" + hex : hex;
})
.join("")
);
}
static defaultColors = [
"blue",
"purple",
"green",
"orange",
"red",
"pink",
"gray",
];
static defaultColorRgb = {
gray: "103, 123, 148",
blue: "61, 180, 242",
purple: "192, 99, 255",
green: "76, 202, 81",
orange: "239, 136, 26",
red: "225, 51, 51",
pink: "252, 157, 214",
};
static handleAnilistColor(color) {
if (this.defaultColors.includes(color)) {
return this.defaultColorRgb[color];
}
return this.hexToRgb(color);
}
}
class DOM {
static create(element, classes = null, children = null) {
const el = document.createElement(element);
if (classes !== null) {
for (const className of classes?.split(" ")) {
if (className.startsWith("#")) {
el.setAttribute("id", `void-${className.slice(1)}`);
continue;
}
el.classList.add(`void-${className}`);
}
}
if (children) {
if (Array.isArray(children)) {
el.append(...children);
} else {
el.append(children);
}
}
return el;
}
static getOrCreate(element, classes) {
const id = classes
.split(" ")
.find((className) => className.startsWith("#"));
return this.get(id) ?? this.create(element, classes);
}
static get(selector) {
return document.querySelector(selector);
}
static getAll(selector) {
return document.querySelectorAll(selector);
}
}
// MIT License
// Copyright (c) 2020 Refactoring UI Inc.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
const RefreshIcon = () => {
const icon = new DOMParser().parseFromString(
``,
"text/html"
).body.childNodes[0];
return icon;
};
const EyeIcon = () => {
const icon = new DOMParser().parseFromString(
` ;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const EyeClosedIcon = () => {
const icon = new DOMParser().parseFromString(
`;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const TrashcanIcon = () => {
const icon = new DOMParser().parseFromString(
`;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const AddIcon = () => {
const icon = new DOMParser().parseFromString(
`;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const GifIcon = () => {
const icon = new DOMParser().parseFromString(
`;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const HeartIcon = () => {
const icon = new DOMParser().parseFromString(
`;
`,
"text/html"
).body.childNodes[0];
return icon;
};
const DoubleChevronLeftIcon = () => {
const icon = new DOMParser().parseFromString(
`
`,
"text/html"
).body.childNodes[0];
return icon;
};
const DoubleChevronRightIcon = () => {
const icon = new DOMParser().parseFromString(
`
`,
"text/html"
).body.childNodes[0];
return icon;
};
const ColorPicker = (value, onChange) => {
const container = DOM.create("div", "color-picker-container");
const colorPicker = DOM.create("input", "color-picker");
colorPicker.setAttribute("type", "color");
colorPicker.value = value;
colorPicker.addEventListener("change", (event) => {
onChange(event);
});
container.append(colorPicker);
const inputField = DOM.create("input", "color-picker-input");
inputField.value = value ?? "#";
inputField.addEventListener("change", (event) => {
onChange(event);
});
container.append(inputField);
return container;
};
const InputField = (value, onChange, classes) => {
const inputField = DOM.create("input", transformClasses("input", classes));
inputField.value = value;
inputField.addEventListener("change", (event) => {
onChange(event);
});
return inputField;
};
const SecretField = (value, onChange) => {
const secret = InputField(value, onChange);
secret.setAttribute("type", "password");
const eyeIcon = EyeIcon();
const closedEyeIcon = EyeClosedIcon();
const container = DOM.create("div", "action-container", secret);
const iconButton = IconButton(eyeIcon, (event) => {
if (event.target.firstChild === eyeIcon) {
event.target.replaceChildren(closedEyeIcon);
secret.setAttribute("type", "text");
return;
}
event.target.replaceChildren(eyeIcon);
secret.setAttribute("type", "password");
});
container.append(iconButton);
return container;
};
const ActionInputField = (value, onClick, icon) => {
const inputField = InputField(value, () => {});
const container = DOM.create("div", "action-container", inputField);
const iconButton = IconButton(icon, (event) => {
onClick(event, inputField);
});
container.append(iconButton);
return container;
};
const RangeField = (value, onChange, max, step = 1, min = 0, unit) => {
const container = DOM.create("div", "range-container");
const range = DOM.create("input", "range");
const display = DOM.create("div", "range-display", `${value}${unit ?? ""}`);
range.setAttribute("type", "range");
range.addEventListener("change", (event) => {
onChange(event);
});
range.addEventListener("input", () => {
display.replaceChildren(`${event.target.value}${unit ?? ""}`);
});
range.setAttribute("max", max);
range.setAttribute("min", min);
range.setAttribute("step", step);
range.setAttribute("value", value);
container.append(range, display);
return container;
};
const Button = (text, onClick) => {
const button = DOM.create("button", "button", text);
button.addEventListener("click", (event) => {
onClick(event);
});
return button;
};
const IconButton = (text, onClick, classes) => {
const button = DOM.create(
"div",
transformClasses("icon-button", classes),
text
);
button.addEventListener("click", (event) => {
onClick(event);
});
return button;
};
const Note = (text) => {
const note = DOM.create("div", "notice", text);
return note;
};
const Link = (text, href, target = "_blank", classes) => {
const link = DOM.create("a", transformClasses("link", classes), text);
link.setAttribute("href", href);
link.setAttribute("target", target);
return link;
};
const TextArea = (text, onChange, classes) => {
const textArea = DOM.create(
"textarea",
transformClasses("textarea", classes),
text
);
textArea.addEventListener("change", (event) => {
onChange(event);
});
return textArea;
};
const Toast = (message, type) => {
const toast = DOM.create("div", transformClasses("toast", type), message);
return toast;
};
const Select = (options) => {
const container = DOM.create("div", "select");
for (const option of options) {
container.append(option);
}
return container;
};
const Option$1 = (value, selected, onClick) => {
const option = DOM.create("div", "option", value);
if (selected) {
option.classList.add("active");
}
option.addEventListener("click", onClick);
return option;
};
const Label = (text, element) => {
const container = DOM.create("div", "label-container");
const label = DOM.create("label", "label-span", text);
const id = Math.random();
label.setAttribute("for", id);
element.setAttribute("id", id);
container.append(label, element);
return container;
};
const Table = (head, body) => {
const table = DOM.create("table", "table", [head, body]);
return table;
};
const TableHead = (...headers) => {
const headerCells = headers.map((header) => DOM.create("th", null, header));
const headerRow = DOM.create("tr", null, headerCells);
const head = DOM.create("thead", null, headerRow);
return head;
};
const TableBody = (rows) => {
const tableBody = DOM.create("tbody", null, rows);
return tableBody;
};
const Checkbox = (checked, onChange, title, disabled = false) => {
const checkbox = DOM.create("input", "checkbox");
checkbox.setAttribute("type", "checkbox");
checkbox.checked = checked;
if (disabled) {
checkbox.setAttribute("disabled", "");
}
checkbox.addEventListener("change", onChange);
checkbox.title = title;
return checkbox;
};
const SettingLabel = (text, input) => {
const container = DOM.create("div", "setting-label-container", input);
const label = DOM.create("label", "setting-label", text);
const id = Math.random();
label.setAttribute("for", id);
input.setAttribute("id", id);
container.append(label);
return container;
};
const GifKeyboard = (header) => {
const container = DOM.create("div", "gif-keyboard-container");
container.append(header);
const gifList = DOM.create("div", "gif-keyboard-list");
const controls = DOM.create("div", "gif-keyboard-control-container");
container.append(
DOM.create("div", "gif-keyboard-list-container", [controls, gifList])
);
return container;
};
const GifItem = (url, onClick, onLike, gifs) => {
const container = DOM.create("div", "gif-keyboard-item");
container.addEventListener("click", () => {
onClick();
});
const img = DOM.create("img");
img.setAttribute("src", url);
container.append(GifContainer(img, onLike, gifs));
return container;
};
const GifContainer = (imgElement, onLike, gifs) => {
const container = DOM.create("div", "gif-like-container");
container.append(
imgElement,
IconButton(
HeartIcon(),
(event) => {
event.stopPropagation();
event.preventDefault();
onLike(event);
if (event.target.classList.contains("void-liked")) {
event.target.classList.remove("void-liked");
} else {
event.target.classList.add("void-liked");
}
},
`gif-like ${gifs.includes(imgElement.src) && "liked"}`
)
);
return container;
};
const Pagination = (currentPage, maxPage, onClick) => {
const container = DOM.create("div", "pagination-container");
if (maxPage <= 1) {
return container;
}
let displayedPages = [];
if (maxPage > 3) {
container.append(
IconButton(
DoubleChevronLeftIcon(),
() => {
onClick(0);
},
`pagination-skip ${currentPage === 0 && "active"}`
)
);
if (currentPage >= maxPage - 1) {
displayedPages.push(maxPage - 2, maxPage - 1, maxPage);
} else if (currentPage === 0) {
displayedPages.push(currentPage, currentPage + 1, currentPage + 2);
} else {
displayedPages.push(currentPage - 1, currentPage, currentPage + 1);
}
} else {
for (let i = 0; i <= maxPage; i++) {
displayedPages.push(i);
}
}
for (const page of displayedPages) {
container.append(
IconButton(
page + 1,
() => {
onClick(page);
},
currentPage === page && "active"
)
);
}
if (maxPage > 3) {
container.append(
IconButton(
DoubleChevronRightIcon(),
() => {
onClick(maxPage);
},
`pagination-skip ${currentPage === maxPage && "active"}`
)
);
}
return container;
};
const transformClasses = (base, additional) => {
let classes = base;
if (additional) {
classes += ` ${additional}`;
}
return classes;
};
const toastTypes = {
info: "info",
success: "success",
warning: "warning",
error: "error",
};
const toastLevels = {
info: 0,
success: 1,
warning: 2,
error: 3,
};
const toastDurations = [1, 3, 5, 10];
const toastLocations = ["top-left", "top-right", "bottom-left", "bottom-right"];
class ToasterConfig {
toastLevel;
duration;
location;
constructor(config) {
this.toastLevel = config?.toastLevel ?? 2;
this.duration = config?.duration ?? 5;
this.location = config?.location ?? "bottom-left";
}
}
class ToastInstance {
type;
message;
duration;
// durationLeft;
// interval;
constructor(message, type, duration) {
this.type = type;
this.message = message;
this.duration = duration * 1000;
}
toast() {
const toast = Toast(this.message, this.type);
this.durationLeft = this.duration;
// This code can be used for a visual indicator
// this.interval = setInterval(
// (toast) => {
// if (this.durationLeft <= 0) {
// this.delete(toast);
// clearInterval(this.interval);
// return;
// }
// this.durationLeft -= 100;
// },
// 100,
// toast
// );
setTimeout(() => {
this.delete(toast);
}, this.duration);
return toast;
}
delete(toast) {
toast.remove();
}
}
class Toaster {
static #config;
static #configInLocalStorage = "void-verified-toaster-config";
static #settings;
static initializeToaster(settings) {
this.#settings = settings;
const config = JSON.parse(
localStorage.getItem(this.#configInLocalStorage)
);
this.#config = new ToasterConfig(config);
const toastContainer = DOM.create(
"div",
`#toast-container ${this.#config.location}`
);
document.body.append(toastContainer);
}
static debug(message) {
if (!this.#shouldToast(toastTypes.info)) {
return;
}
DOM.get("#void-toast-container").append(
new ToastInstance(
message,
toastTypes.info,
this.#config.duration
).toast()
);
}
static success(message) {
if (!this.#shouldToast(toastTypes.success)) {
return;
}
DOM.get("#void-toast-container").append(
new ToastInstance(
message,
toastTypes.success,
this.#config.duration
).toast()
);
}
static warning(message) {
if (!this.#shouldToast(toastTypes.warning)) {
return;
}
DOM.get("#void-toast-container").append(
new ToastInstance(
message,
toastTypes.warning,
this.#config.duration
).toast()
);
}
static error(message) {
if (!this.#shouldToast(toastTypes.error)) {
return;
}
DOM.get("#void-toast-container").append(
new ToastInstance(
message,
toastTypes.error,
this.#config.duration
).toast()
);
}
static critical(message) {
DOM.get("#void-toast-container").append(
new ToastInstance(message, toastTypes.error, 8).toast()
);
}
static #shouldToast(type) {
return (
this.#settings.options.toasterEnabled.getValue() &&
this.#config.toastLevel <= toastLevels[type]
);
}
static renderSettings(settingsUi) {
const container = DOM.create("div");
container.append(DOM.create("h3", null, "Configure Toasts"));
container.append(
DOM.create(
"p",
null,
"Toasts are notifications that pop up in the corner of your screen when things are happening."
)
);
const options = Object.values(toastTypes).map((type) =>
Option$1(type, this.#config.toastLevel === toastLevels[type], () => {
this.#handleLevelChange(type);
settingsUi.renderSettingsUiContent();
})
);
container.append(Label("Toast level", Select(options)));
const locationOptions = toastLocations.map((location) =>
Option$1(location, this.#config.location === location, () => {
this.#handleLocationChange(location);
settingsUi.renderSettingsUiContent();
})
);
container.append(Label("Toast location", Select(locationOptions)));
const durationOptions = toastDurations.map((duration) =>
Option$1(`${duration}s`, duration === this.#config.duration, () => {
this.#handleDurationChange(duration);
settingsUi.renderSettingsUiContent();
})
);
container.append(Label("Toast duration", Select(durationOptions)));
container.append(
Button("Test Toasts", () => {
Toaster.debug("This is a debug toast.");
Toaster.success("This is a success toast.");
Toaster.warning("This is a warning toast.");
Toaster.error("This is an error toast.");
})
);
return container;
}
static #handleLevelChange(type) {
this.#config.toastLevel = toastLevels[type];
this.#saveConfig();
}
static #handleLocationChange(location) {
this.#config.location = location;
this.#saveConfig();
const container = DOM.get("#void-toast-container");
for (const className of container.classList) {
container.classList.remove(className);
}
container.classList.add(`void-${location}`);
}
static #handleDurationChange(duration) {
this.#config.duration = duration;
this.#saveConfig();
}
static #saveConfig() {
localStorage.setItem(
this.#configInLocalStorage,
JSON.stringify(this.#config)
);
}
}
class AnilistAPI {
settings;
#userId;
#url = "https://graphql.anilist.co";
constructor(settings) {
this.settings = settings;
this.#userId = Number(JSON.parse(localStorage.getItem("auth")).id);
}
async getActivityCss(activityId) {
const query = `query ($activityId: Int) {
Activity(id: $activityId) {
... on ListActivity {
user {
name
about
options {
profileColor
}
}}
... on TextActivity {
user {
name
about
options {
profileColor
}
}
}
... on MessageActivity {
recipient {
name
about
options {
profileColor
}
}
}
}
}`;
const variables = { activityId };
const options = this.#getQueryOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data.Activity;
} catch (error) {
throw new Error("Error querying activity.", error);
}
}
async getUserAbout(username) {
const query = `query ($username: String) {
User(name: $username) {
about
}
}`;
const variables = { username };
const options = this.#getQueryOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data.User.about;
} catch (error) {
throw new Error("Error querying user about.", error);
}
}
async saveUserAbout(about) {
const query = `mutation ($about: String) {
UpdateUser(about: $about) {
about
}
}`;
const variables = { about };
const options = this.#getMutationOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data;
} catch (error) {
throw new Error("failed to save user about.", error);
}
}
async saveUserColor(color) {
const query = `mutation ($color: String) {
UpdateUser(profileColor: $color) {
options {
profileColor
}
}
}`;
const variables = { color };
const options = this.#getMutationOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data;
} catch (error) {
throw new Error("Failed to publish profile color", error);
}
}
async saveDonatorBadge(text) {
const query = `mutation ($text: String) {
UpdateUser(donatorBadge: $text) {
donatorBadge
}
}`;
const variables = { text };
const options = this.#getMutationOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data;
} catch (error) {
throw new Error("Failed to publish donator badge", error);
}
}
async queryVerifiedUsers() {
const accountUser = await this.queryUser(this.settings.anilistUser);
this.settings.updateUserFromApi(accountUser);
await this.#queryUsers(1);
}
async queryUser(username) {
const variables = { username };
const query = `query ($username: String!) {
User(name: $username) {
name
id
avatar {
large
}
bannerImage
options {
profileColor
}
}
}
`;
const options = this.#getQueryOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
return data.User;
} catch (error) {
throw new Error("Failed to query user from Anilist API", error);
}
}
async #elevatedFetch(options) {
const runElevated = this.settings.options.useElevatedFetch.getValue();
if (runElevated && GM.xmlHttpRequest) {
try {
const response = await GM.xmlHttpRequest({
method: "POST",
url: this.#url,
data: options.body,
headers: options.headers,
});
const data = JSON.parse(response.response);
return data.data;
} catch (error) {
if (error.error.includes("Request was blocked by the user")) {
Toaster.warning(
"Elevated access has been enabled in the userscript settings but user has refused permissions to run it. Using regular fetch."
);
} else {
Toaster.debug(
"Could not query AniList API with elevated access. Using regular fetch."
);
}
console.error(error);
}
}
const response = await fetch(this.#url, options);
const data = await response.json();
return data.data;
}
async #queryUsers(page) {
const variables = { page, userId: this.#userId };
const query = `query ($page: Int, $userId: Int!) {
Page(page: $page) {
following(userId: $userId) {
name
id
avatar {
large
}
bannerImage
options {
profileColor
}
},
pageInfo {
total
perPage
currentPage
lastPage
hasNextPage
}
}
}
`;
const options = this.#getQueryOptions(query, variables);
try {
const data = await this.#elevatedFetch(options);
this.#handleQueriedUsers(data.Page.following);
const pageInfo = data.Page.pageInfo;
if (pageInfo.hasNextPage) {
await this.#queryUsers(pageInfo.currentPage + 1);
}
} catch (error) {
throw new Error("Failed to query followed users.", error);
}
}
#handleQueriedUsers(users) {
for (const user of users) {
this.settings.updateUserFromApi(user);
}
}
#getQueryOptions(query, variables) {
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query,
variables,
}),
};
if (this.settings.auth?.token) {
options.headers.Authorization = `Bearer ${this.settings.auth.token}`;
}
return options;
}
#getMutationOptions(query, variables) {
if (!this.settings.auth?.token) {
Toaster.error(
"Tried to make API query without authorizing VoidVerified. You can do so in the settings."
);
throw new Error("VoidVerified is missing auth token.");
}
let queryOptions = this.#getQueryOptions(query, variables);
return queryOptions;
}
}
class Option {
value;
defaultValue;
description;
category;
authRequired;
constructor(option) {
this.defaultValue = option.defaultValue;
this.description = option.description;
this.category = option.category;
this.authRequired = option.authRequired;
}
getValue() {
if (this.value === "") {
return this.defaultValue;
}
return this.value ?? this.defaultValue;
}
}
class Settings {
localStorageUsers = "void-verified-users";
localStorageSettings = "void-verified-settings";
localStorageAuth = "void-verified-auth";
version = GM_info.script.version;
auth = null;
anilistUser;
verifiedUsers = [];
options = {};
constructor() {
this.verifiedUsers =
JSON.parse(localStorage.getItem(this.localStorageUsers)) ?? [];
const settingsInLocalStorage =
JSON.parse(localStorage.getItem(this.localStorageSettings)) ?? {};
for (const [key, value] of Object.entries(defaultSettings)) {
this.options[key] = new Option(value);
}
for (const [key, value] of Object.entries(settingsInLocalStorage)) {
if (!this.options[key]) {
continue;
}
this.options[key].value = value.value;
}
this.auth =
JSON.parse(localStorage.getItem(this.localStorageAuth)) ?? null;
const auth = JSON.parse(localStorage.getItem("auth"));
this.anilistUser = auth?.name;
}
async verifyUser(username) {
if (
this.verifiedUsers.find(
(user) => user.username.toLowerCase() === username.toLowerCase()
)
) {
return;
}
this.verifiedUsers.push({ username });
localStorage.setItem(
this.localStorageUsers,
JSON.stringify(this.verifiedUsers)
);
try {
Toaster.debug(`Querying ${username}.`);
const anilistAPI = new AnilistAPI(this);
const user = await anilistAPI.queryUser(username);
this.updateUserFromApi(user);
} catch (error) {
Toaster.error("Failed to query new user.");
console.error(error);
}
}
getUser(username) {
return this.verifiedUsers.find((user) => user.username === username);
}
isVerified(username) {
return this.verifiedUsers.some((user) => user.username === username);
}
updateUserOption(username, key, value) {
this.verifiedUsers = this.verifiedUsers.map((u) =>
u.username === username
? {
...u,
[key]: value,
}
: u
);
localStorage.setItem(
this.localStorageUsers,
JSON.stringify(this.verifiedUsers)
);
}
updateUserFromApi(apiUser) {
let user = this.#findVerifiedUser(apiUser);
if (!user) {
return;
}
const newUser = this.#mapApiUser(user, apiUser);
this.#mapVerifiedUsers(newUser);
localStorage.setItem(
this.localStorageUsers,
JSON.stringify(this.verifiedUsers)
);
}
#findVerifiedUser(apiUser) {
let user = this.verifiedUsers.find((u) => u.id && u.id === apiUser.id);
if (user) {
return user;
}
return this.verifiedUsers.find(
(u) => u.username.toLowerCase() === apiUser.name.toLowerCase()
);
}
#mapVerifiedUsers(newUser) {
if (this.verifiedUsers.find((u) => u.id && u.id === newUser.id)) {
this.verifiedUsers = this.verifiedUsers.map((u) =>
u.id === newUser.id ? newUser : u
);
return;
}
this.verifiedUsers = this.verifiedUsers.map((u) =>
u.username.toLowerCase() === newUser.username.toLowerCase()
? newUser
: u
);
}
#mapApiUser(user, apiUser) {
let userObject = { ...user };
userObject.color = ColorFunctions.handleAnilistColor(
apiUser.options.profileColor
);
userObject.username = apiUser.name;
userObject.avatar = apiUser.avatar.large;
userObject.banner = apiUser.bannerImage;
userObject.id = apiUser.id;
userObject.lastFetch = new Date();
if (this.options.quickAccessBadge.getValue() || user.quickAccessBadge) {
if (
(user.avatar && user.avatar !== userObject.avatar) ||
(user.color && user.color !== userObject.color) ||
(user.banner && user.banner !== userObject.banner) ||
(user.username &&
user.username.toLowerCase() !==
userObject.username.toLowerCase())
) {
userObject.quickAccessBadgeDisplay = true;
}
}
return userObject;
}
saveAuthToken(tokenObject) {
this.auth = tokenObject;
localStorage.setItem(
this.localStorageAuth,
JSON.stringify(tokenObject)
);
}
removeAuthToken() {
this.auth = null;
localStorage.removeItem(this.localStorageAuth);
}
removeUser(username) {
this.verifiedUsers = this.verifiedUsers.filter(
(user) => user.username !== username
);
localStorage.setItem(
this.localStorageUsers,
JSON.stringify(this.verifiedUsers)
);
}
saveSettingToLocalStorage(key, value) {
let localSettings = JSON.parse(
localStorage.getItem(this.localStorageSettings)
);
this.options[key].value = value;
if (localSettings === null) {
const settings = {
[key]: value,
};
localStorage.setItem(
this.localStorageSettings,
JSON.stringify(settings)
);
return;
}
localSettings[key] = { value };
localStorage.setItem(
this.localStorageSettings,
JSON.stringify(localSettings)
);
}
}
class StyleHandler {
settings;
usernameStyles = "";
highlightStyles = "";
otherStyles = "";
constructor(settings) {
this.settings = settings;
}
refreshStyles() {
this.createStyles();
this.createStyleLink(this.usernameStyles, "username");
this.createStyleLink(this.highlightStyles, "highlight");
this.createStyleLink(this.otherStyles, "other");
}
createStyles() {
this.usernameStyles = "";
this.otherStyles = "";
for (const user of this.settings.verifiedUsers) {
if (
this.settings.options.enabledForUsername.getValue() ||
user.enabledForUsername
) {
this.createUsernameCSS(user);
}
}
if (this.settings.options.moveSubscribeButtons.getValue()) {
this.otherStyles += `
.has-label::before {
top: -30px !important;
left: unset !important;
right: -10px;
}
.has-label[label="Unsubscribe"],
.has-label[label="Subscribe"] {
font-size: 0.875em !important;
}
.has-label[label="Unsubscribe"] {
color: rgba(var(--color-green),.8);
}
`;
}
this.createHighlightStyles();
if (this.settings.options.hideLikeCount.getValue()) {
this.otherStyles += `
.like-wrap .count {
display: none;
}
`;
}
}
createHighlightStyles() {
this.highlightStyles = "";
for (const user of this.settings.verifiedUsers) {
if (
this.settings.options.highlightEnabled.getValue() ||
user.highlightEnabled
) {
this.createHighlightCSS(
user,
`div.wrap:has( div.header > a.name[href*="/${user.username}/" i] )`
);
this.createHighlightCSS(
user,
`div.wrap:has( div.details > a.name[href*="/${user.username}/" i] )`
);
}
if (
this.settings.options.highlightEnabledForReplies.getValue() ||
user.highlightEnabledForReplies
) {
this.createHighlightCSS(
user,
`div.reply:has( a.name[href*="/${user.username}/" i] )`
);
}
this.#createActivityCss(user);
}
this.disableHighlightOnSmallCards();
}
#createActivityCss(user) {
const colorUserActivity =
this.settings.options.colorUserActivity.getValue() ??
user.colorUserActivity;
const colorUserReplies =
this.settings.options.colorUserReplies.getValue() ??
user.colorUserReplies;
if (colorUserActivity) {
this.highlightStyles += `
div.wrap:has( div.header > a.name[href*="/${
user.username
}/"]) a,
div.wrap:has( div.details > a.name[href*="/${
user.username
}/"]) a
{
color: ${this.getUserColor(user)};
}
`;
}
if (colorUserReplies) {
this.highlightStyles += `
.reply:has(a.name[href*="/${user.username}/"]) a,
.reply:has(a.name[href*="/${
user.username
}/"]) .markdown-spoiler::before
{
color: ${this.getUserColor(user)};
}
`;
}
}
createUsernameCSS(user) {
this.usernameStyles += `
a.name[href*="/${user.username}/" i]::after {
content: "${
this.stringIsEmpty(user.sign) ??
this.settings.options.defaultSign.getValue()
}";
color: ${this.getUserColor(user) ?? "rgb(var(--color-blue))"}
}
`;
}
createHighlightCSS(user, selector) {
this.highlightStyles += `
${selector} {
margin-right: -${this.settings.options.highlightSize.getValue()};
border-right: ${this.settings.options.highlightSize.getValue()} solid ${
this.getUserColor(user) ?? this.getDefaultHighlightColor()
};
border-radius: 5px;
}
`;
}
disableHighlightOnSmallCards() {
this.highlightStyles += `
div.wrap:has(div.small) {
margin-right: 0px !important;
border-right: 0px solid black !important;
}
`;
}
refreshHomePage() {
if (!this.settings.options.highlightEnabled.getValue()) {
return;
}
this.createHighlightStyles();
this.createStyleLink(this.highlightStyles, "highlight");
}
clearStyles(id) {
const styles = document.getElementById(`void-verified-${id}-styles`);
styles?.remove();
}
verifyProfile() {
if (!this.settings.options.enabledForProfileName.getValue()) {
return;
}
const username =
window.location.pathname.match(/^\/user\/([^/]*)\/?/)[1];
const user = this.settings.verifiedUsers.find(
(u) => u.username.toLowerCase() === username.toLowerCase()
);
if (!user) {
this.clearStyles("profile");
return;
}
const profileStyle = `
.name-wrapper h1.name::after {
content: "${
this.stringIsEmpty(user.sign) ??
this.settings.options.defaultSign.getValue()
}"
}
`;
this.createStyleLink(profileStyle, "profile");
}
getStyleLink(id) {
return document.getElementById(`void-verified-${id}-styles`);
}
copyUserColor() {
const usernameHeader = document.querySelector("h1.name");
const username = usernameHeader.innerHTML.trim();
const user = this.settings.verifiedUsers.find(
(u) => u.username === username
);
if (!user) {
return;
}
if (
!(
user.copyColorFromProfile ||
this.settings.options.copyColorFromProfile.getValue()
)
) {
return;
}
const color =
getComputedStyle(usernameHeader).getPropertyValue("--color-blue");
this.settings.updateUserOption(user.username, "color", color);
}
getUserColor(user) {
return (
user.colorOverride ??
(user.color &&
(user.copyColorFromProfile ||
this.settings.options.copyColorFromProfile.getValue())
? `rgb(${user.color})`
: undefined)
);
}
getDefaultHighlightColor() {
if (this.settings.options.useDefaultHighlightColor.getValue()) {
return this.settings.options.defaultHighlightColor.getValue();
}
return "rgb(var(--color-blue))";
}
createStyleLink(styles, id) {
const oldLink = document.getElementById(`void-verified-${id}-styles`);
const link = document.createElement("link");
link.setAttribute("id", `void-verified-${id}-styles`);
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute(
"href",
"data:text/css;charset=UTF-8," + encodeURIComponent(styles)
);
document.head?.append(link);
oldLink?.remove();
return link;
}
stringIsEmpty(string) {
if (!string || string.length === 0) {
return undefined;
}
return string;
}
}
class GlobalCSS {
settings;
styleHandler;
styleId = "global-css";
isCleared = false;
cssInLocalStorage = "void-verified-global-css";
constructor(settings) {
this.settings = settings;
this.styleHandler = new StyleHandler(settings);
this.css = localStorage.getItem(this.cssInLocalStorage) ?? "";
}
createCss() {
if (!this.settings.options.globalCssEnabled.getValue()) {
this.styleHandler.clearStyles(this.styleId);
return;
}
if (!this.shouldRender()) {
return;
}
this.isCleared = false;
this.styleHandler.createStyleLink(this.css, this.styleId);
}
updateCss(css) {
this.css = css;
this.createCss();
localStorage.setItem(this.cssInLocalStorage, css);
}
clearCssForProfile() {
if (this.isCleared) {
return;
}
if (!this.shouldRender()) {
this.styleHandler.clearStyles(this.styleId);
this.isCleared = true;
}
}
shouldRender() {
if (window.location.pathname.startsWith("/settings")) {
return false;
}
if (!this.settings.options.globalCssAutoDisable.getValue()) {
return true;
}
if (
!window.location.pathname.startsWith("/user/") &&
!window.location.pathname.startsWith("/activity/")
) {
return true;
}
const profileCustomCss = document.getElementById(
"customCSS-automail-styles"
);
const styleHandler = new StyleHandler(this.settings);
const voidActivityStyles = styleHandler.getStyleLink("activity-css");
const voidUserStyles = styleHandler.getStyleLink("user-css");
if (voidActivityStyles || voidUserStyles) {
return false;
}
if (!profileCustomCss) {
return true;
}
const shouldRender = profileCustomCss.innerHTML.trim().length === 0;
return shouldRender;
}
}
class ActivityHandler {
settings;
constructor(settings) {
this.settings = settings;
}
moveAndDisplaySubscribeButton() {
if (!this.settings.options.moveSubscribeButtons.getValue()) {
return;
}
const subscribeButtons = DOM.getAll(
"span[label='Unsubscribe'], span[label='Subscribe']"
);
for (const subscribeButton of subscribeButtons) {
if (subscribeButton.parentNode.classList.contains("actions")) {
continue;
}
const container = subscribeButton.parentNode.parentNode;
const actions = container.querySelector(".actions");
actions.append(subscribeButton);
}
}
removeBlankFromAnilistLinks() {
if (!this.settings.options.removeAnilistBlanks.getValue()) {
return;
}
const anilistLinks = DOM.getAll(
"a:not(.void-link)[href^='https://anilist.co'][target='_blank']"
);
for (const link of anilistLinks) {
link.removeAttribute("target");
}
}
}
class ImageHostBase {
conventToBase64(image) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onloadend = function (e) {
resolve({
fileName: this.name,
result: e.target.result,
error: e.target.error,
});
};
reader.readAsDataURL(image);
});
}
}
const imageHosts = {
imgbb: "imgbb",
imgur: "imgur",
catbox: "catbox",
};
const imageHostConfiguration = {
selectedHost: imageHosts.catbox,
configurations: {
imgbb: {
name: "imgbb",
apiKey: "",
},
imgur: {
name: "imgur",
clientId: "",
clientSecret: "",
expires: null,
refreshToken: null,
authToken: null,
},
catbox: {
name: "catbox",
userHash: "",
},
},
};
class ImageHostService {
#configuration;
#localStorage = "void-verified-image-host-config";
constructor() {
const config = JSON.parse(localStorage.getItem(this.#localStorage));
if (!config) {
localStorage.setItem(
this.#localStorage,
JSON.stringify(imageHostConfiguration)
);
} else {
for (const key of Object.keys(
imageHostConfiguration.configurations
)) {
if (config.configurations[key]) {
continue;
}
config.configurations[key] =
imageHostConfiguration.configurations[key];
}
localStorage.setItem(this.#localStorage, JSON.stringify(config));
}
this.#configuration = config ?? imageHostConfiguration;
}
getImageHostConfiguration(host) {
return this.#configuration.configurations[host];
}
getSelectedHost() {
return this.#configuration.selectedHost;
}
setSelectedHost(host) {
this.#configuration.selectedHost = host;
localStorage.setItem(
this.#localStorage,
JSON.stringify(this.#configuration)
);
}
setImageHostConfiguration(host, config) {
this.#configuration.configurations[host] = config;
localStorage.setItem(
this.#localStorage,
JSON.stringify(this.#configuration)
);
}
}
class CatboxConfig {
userHash;
name = "catbox";
constructor(config) {
this.userHash = config?.userHash ?? "";
}
}
class CatboxAPI extends ImageHostBase {
#url = "https://catbox.moe/user/api.php";
#configuration;
constructor(configuration) {
super();
this.#configuration = new CatboxConfig(configuration);
}
async uploadImage(image) {
if (!image) {
return;
}
const form = new FormData();
form.append("reqtype", "fileupload");
form.append("fileToUpload", image);
if (this.#configuration.userHash !== "") {
form.append("userhash", this.#configuration.userHash);
}
try {
if (GM.xmlHttpRequest) {
Toaster.debug("Uploading image to catbox.");
const response = await GM.xmlHttpRequest({
method: "POST",
url: this.#url,
data: form,
});
if (response.status !== 200) {
console.error(response.response);
throw new Error("Image upload to catbox failed.");
}
return response.response;
}
} catch (error) {
Toaster.error("Failed to upload image to catbox.");
return null;
}
}
renderSettings() {
const container = DOM.create("div");
container.append(
Label(
"Userhash",
SecretField(this.#configuration.userHash, (event) => {
this.#updateUserhash(event, this.#configuration);
})
)
);
const p = Note(
"Catbox.moe works out of the box, but you can provide your userhash to upload images to your account. Your userscript manager should promt you to allow xmlHttpRequest. This is required to upload images to Catbox on AniList."
);
container.append(p);
return container;
}
#updateUserhash(event, configuration) {
const userHash = event.target.value;
const config = {
...configuration,
userHash,
};
new ImageHostService().setImageHostConfiguration(config.name, config);
}
}
class ImgbbAPI extends ImageHostBase {
#url = "https://api.imgbb.com/1/upload";
#configuration;
constructor(configuration) {
super();
this.#configuration = configuration;
}
async uploadImage(image) {
const file = await this.conventToBase64(image);
if (!file.result) {
return;
}
if (!this.#configuration.apiKey) {
return;
}
const base64 = file.result.split("base64,")[1];
const settings = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
body:
"image=" +
encodeURIComponent(base64) +
"&name=" +
image.name.split(".")[0],
};
try {
Toaster.debug("Uploading image to imgbb.");
const response = await fetch(
`${this.#url}?key=${this.#configuration.apiKey}`,
settings
);
const data = await response.json();
Toaster.success("Uploaded image to imgbb.");
return data.data.url;
} catch (error) {
Toaster.error("Failed to upload image to imgbb.");
console.error(error);
return null;
}
}
renderSettings() {
const container = document.createElement("div");
const apiKey = Label(
"API key",
SecretField(this.#configuration.apiKey, (event) => {
this.#updateApiKey(event, this.#configuration);
})
);
const note = Note(
"You need to get the API key from the following link: "
);
note.append(Link("api.imgbb.com", "https://api.imgbb.com/", "_blank"));
container.append(apiKey, note);
return container;
}
#updateApiKey(event, configuration) {
const apiKey = event.target.value;
const config = {
...configuration,
apiKey,
};
new ImageHostService().setImageHostConfiguration(config.name, config);
}
}
class ImgurAPI extends ImageHostBase {
#url = "https://api.imgur.com/3/image";
#configuration;
constructor(configuration) {
super();
this.#configuration = configuration;
}
async uploadImage(image) {
const file = await this.conventToBase64(image);
if (!file.result) {
return;
}
if (!this.#configuration.clientId) {
return;
}
const base64 = file.result.split("base64,")[1];
const formData = new FormData();
formData.append("image", base64);
formData.append("title", image.name.split(".")[0]);
const settings = {
method: "POST",
headers: {
Authorization: this.#configuration.authToken
? `Bearer ${this.#configuration.authToken}`
: `Client-ID ${this.#configuration.clientId}`,
},
body: formData,
};
try {
Toaster.debug("Uploading image to imgur.");
const response = await fetch(this.#url, settings);
const data = await response.json();
Toaster.success("Uploaded image to imgur.");
return data.data.link;
} catch (error) {
Toaster.error("Failed to upload image to imgur.");
console.error("Failed to upload image to imgur.", error);
return null;
}
}
renderSettings(settingsUi) {
const container = DOM.create("div");
const clientId = Label(
"Client ID",
SecretField(this.#configuration?.clientId ?? "", (event) => {
this.#updateConfig(event, "clientId", this.#configuration);
settingsUi.renderSettingsUiContent();
})
);
const clientSecret = Label(
"Client Secret",
SecretField(this.#configuration?.clientSecret ?? "", (event) => {
this.#updateConfig(event, "clientSecret", this.#configuration);
settingsUi.renderSettingsUiContent();
})
);
container.append(clientId, clientSecret);
if (
this.#configuration.clientId &&
this.#configuration.clientSecret &&
!this.#configuration.authToken
) {
const authLink = DOM.create("a", null, "Authorize Imgur");
authLink.classList.add("button");
authLink.setAttribute(
"href",
`https://api.imgur.com/oauth2/authorize?client_id=${
this.#configuration.clientId
}&response_type=token`
);
container.append(authLink);
}
if (this.#configuration.authToken) {
const revokeAuthButton = DOM.create(
"button",
null,
"Clear Authorization"
);
revokeAuthButton.classList.add("button");
revokeAuthButton.addEventListener("click", () => {
this.#revokeAuth();
settingsUi.renderSettingsUiContent();
});
container.append(revokeAuthButton);
}
this.#renderNote(container);
return container;
}
handleAuth() {
const hash = window.location.hash.substring(1);
if (!hash) {
return;
}
const [path, token, expires, _, refreshToken] = hash.split("&");
if (path !== "void_imgur") {
return;
}
let config = { ...this.#configuration };
config.authToken = token.split("=")[1];
config.refreshToken = refreshToken.split("=")[1];
config.expires = new Date(
new Date().getTime() + Number(expires.split("=")[1])
);
new ImageHostService().setImageHostConfiguration(
imageHosts.imgur,
config
);
window.history.replaceState(
null,
"",
"https://anilist.co/settings/developer"
);
}
async refreshAuthToken() {
if (
!this.#configuration.refreshToken ||
!this.#configuration.clientSecret ||
!this.#configuration.clientId
) {
return;
}
if (new Date() < new Date(this.#configuration.expires)) {
return;
}
const formData = new FormData();
formData.append("refresh_token", this.#configuration.refreshToken);
formData.append("client_id", this.#configuration.clientId);
formData.append("client_secret", this.#configuration.clientSecret);
formData.append("grant_type", "refresh_token");
try {
Toaster.debug("Refreshing imgur token.");
const response = await fetch("https://api.imgur.com/oauth2/token", {
method: "POST",
body: formData,
});
if (!response.status === 200) {
console.error("Failed to reauthorize Imgur");
return;
}
const data = await response.json();
const config = {
...this.#configuration,
authToken: data.access_token,
expires: new Date(new Date().getTime() + data.expires_in),
};
new ImageHostService().setImageHostConfiguration(
imageHosts.imgur,
config
);
Toaster.success("Refreshed imgur access token.");
} catch (error) {
Toaster.error("Error while refreshing imgur token.");
console.error(error);
}
}
#renderNote(container) {
const note = Note("How to setup Imgur integration");
const registerLink = Link(
"api.imgur.com",
"https://api.imgur.com/oauth2/addclient",
"_blank"
);
const stepList = DOM.create("ol", null, [
DOM.create("li", null, [
"Register your application: ",
registerLink,
". Use 'https://anilist.co/settings/developer#void_imgur' as callback URL.",
]),
DOM.create(
"li",
null,
"Fill the client id and secret fields with the value Imgur provided."
),
DOM.create(
"li",
null,
"Click on authorize (you can skip this step if you don't want images tied to your account)."
),
]);
note.append(stepList);
note.append(
"Hitting Imgur API limits might get your API access blocked."
);
container.append(note);
}
#revokeAuth() {
const config = {
...this.#configuration,
authToken: null,
refreshToken: null,
};
new ImageHostService().setImageHostConfiguration(
imageHosts.imgur,
config
);
}
#updateConfig(event, key, configuration) {
const value = event.target.value;
const config = {
...configuration,
[key]: value,
};
new ImageHostService().setImageHostConfiguration(
imageHosts.imgur,
config
);
}
}
class ImageApiFactory {
getImageHostInstance() {
const imageHostService = new ImageHostService();
switch (imageHostService.getSelectedHost()) {
case imageHosts.imgbb:
return new ImgbbAPI(
imageHostService.getImageHostConfiguration(imageHosts.imgbb)
);
case imageHosts.imgur:
return new ImgurAPI(
imageHostService.getImageHostConfiguration(imageHosts.imgur)
);
case imageHosts.catbox:
return new CatboxAPI(
imageHostService.getImageHostConfiguration(
imageHosts.catbox
)
);
}
}
}
const subCategories = {
users: "users",
authorization: "authorization",
imageHost: "image host",
layout: "layout & CSS",
globalCss: "global CSS",
toasts: "toasts",
};
class SettingsUserInterface {
settings;
styleHandler;
globalCSS;
userCSS;
layoutDesigner;
AnilistBlue = "120, 180, 255";
#activeCategory = "all";
#activeSubCategory = subCategories.users;
constructor(settings, styleHandler, globalCSS, userCSS, layoutDesigner) {
this.settings = settings;
this.styleHandler = styleHandler;
this.globalCSS = globalCSS;
this.userCSS = userCSS;
this.layoutDesigner = layoutDesigner;
}
renderSettingsUi() {
this.#checkAuthFromUrl();
const container = DOM.get(".settings.container > .content");
const settingsContainerExists =
DOM.get("#void-verified-settings") !== null;
if (!settingsContainerExists) {
const settingsContainer = DOM.create(
"div",
"#verified-settings settings"
);
container.append(settingsContainer);
}
this.renderSettingsUiContent();
}
renderSettingsUiContent() {
const settingsContainer = DOM.create("div");
this.#renderSettingsHeader(settingsContainer);
this.#renderCategories(settingsContainer);
this.#renderOptions(settingsContainer);
this.#handleSubcategories(settingsContainer);
DOM.get("#void-verified-settings").replaceChildren(settingsContainer);
}
#handleSubcategories(settingsContainer) {
this.#renderSubCategoriesNavigation(settingsContainer);
switch (this.#activeSubCategory) {
case subCategories.users:
this.#renderUserTable(settingsContainer);
break;
case subCategories.authorization:
this.#creatAuthenticationSection(settingsContainer);
break;
case subCategories.imageHost:
this.#renderImageHostSettings(settingsContainer);
break;
case subCategories.layout:
settingsContainer.append(
this.layoutDesigner.renderSettings(this)
);
if (
this.settings.auth?.token &&
(this.settings.options.profileCssEnabled.getValue() ||
this.settings.options.activityCssEnabled.getValue())
) {
this.#renderCustomCssEditor(
settingsContainer,
this.userCSS
);
}
break;
case subCategories.globalCss:
if (this.settings.options.globalCssEnabled.getValue()) {
this.#renderCustomCssEditor(
settingsContainer,
this.globalCSS
);
}
break;
case subCategories.toasts:
settingsContainer.append(Toaster.renderSettings(this));
}
}
#renderOptions(settingsContainer) {
const settingsListContainer = DOM.create("div", "settings-list");
for (const [key, setting] of Object.entries(this.settings.options)) {
if (
setting.category !== this.#activeCategory &&
this.#activeCategory !== "all"
) {
continue;
}
this.#renderSetting(setting, settingsListContainer, key);
}
settingsContainer.append(settingsListContainer);
}
removeSettingsUi() {
const settings = document.querySelector("#void-verified-settings");
settings?.remove();
}
#renderSettingsHeader(settingsContainer) {
const headerContainer = DOM.create("div", "settings-header");
const header = DOM.create("h1", null, "VoidVerified Settings");
const versionInfo = DOM.create("p", null, [
"Version: ",
DOM.create("span", null, this.settings.version),
]);
headerContainer.append(header);
headerContainer.append(versionInfo);
const author = DOM.create("p", null, [
"Author: ",
Link("voidnyan", "https://anilist.co/user/voidnyan/"),
]);
headerContainer.append(header, versionInfo, author);
settingsContainer.append(headerContainer);
}
#renderCategories(settingsContainer) {
const nav = DOM.create("nav", "nav");
const list = DOM.create("ol");
const onClick = (_category) => {
this.#activeCategory = _category;
this.renderSettingsUiContent();
};
list.append(
this.#createNavBtn("all", "all" === this.#activeCategory, () => {
onClick("all");
})
);
for (const category of Object.values(categories)) {
list.append(
this.#createNavBtn(
category,
category === this.#activeCategory,
() => {
onClick(category);
}
)
);
}
nav.append(list);
settingsContainer.append(nav);
}
#renderSubCategoriesNavigation(settingsContainer) {
const nav = DOM.create("nav", "nav");
const list = DOM.create("ol");
for (const subCategory of Object.values(subCategories)) {
if (!this.#shouldDisplaySubCategory(subCategory)) {
continue;
}
list.append(
this.#createNavBtn(
subCategory,
this.#activeSubCategory === subCategory,
() => {
this.#activeSubCategory = subCategory;
this.renderSettingsUiContent();
}
)
);
}
nav.append(list);
settingsContainer.append(nav);
}
#shouldDisplaySubCategory(subCategory) {
switch (subCategory) {
case subCategories.users:
return true;
case subCategories.authorization:
return true;
case subCategories.imageHost:
return this.settings.options.pasteImagesToHostService.getValue();
case subCategories.layout:
return (
this.settings.auth?.token &&
(this.settings.options.profileCssEnabled.getValue() ||
this.settings.options.activityCssEnabled.getValue() ||
this.settings.options.layoutDesignerEnabled.getValue())
);
case subCategories.globalCss:
return this.settings.options.globalCssEnabled.getValue();
case subCategories.toasts:
return this.settings.options.toasterEnabled.getValue();
}
}
#createNavBtn(category, isActive, onClick) {
const className = isActive ? "active" : null;
const li = DOM.create("li", className, category);
li.addEventListener("click", () => {
onClick();
});
return li;
}
#renderUserTable(settingsContainer) {
const tableContainer = DOM.create("div", "table #verified-user-table");
tableContainer.style = `
margin-top: 25px;
`;
const head = TableHead("Username", "Sign", "Color", "Other");
const rows = this.settings.verifiedUsers.map((user) =>
this.#createUserRow(user)
);
const body = TableBody(rows);
const table = Table(head, body);
tableContainer.append(table);
const inputForm = DOM.create("form");
inputForm.addEventListener("submit", (event) => {
this.#handleVerifyUserForm(event, this.settings);
});
const inputFormLabel = DOM.create("label", null, "Add user");
inputFormLabel.setAttribute("for", "void-verified-add-user");
inputForm.append(inputFormLabel);
inputForm.append(InputField("", () => {}, "#verified-add-user"));
tableContainer.append(inputForm);
settingsContainer.append(tableContainer);
const fallbackColorOption = this.settings.options.defaultHighlightColor;
settingsContainer.append(
DOM.create("h5", null, "Fallback color"),
ColorPicker(fallbackColorOption.getValue(), (event) => {
this.#handleOption(event, "fallbackColor");
})
);
}
#createUserRow(user) {
const row = DOM.create("tr");
const userLink = DOM.create("a", null, user.username);
userLink.setAttribute(
"href",
`https://anilist.co/user/${user.username}/`
);
userLink.setAttribute("target", "_blank");
row.append(DOM.create("td", null, userLink));
const signInput = InputField(
user.sign ?? "",
(event) => {
this.#updateUserOption(
user.username,
"sign",
event.target.value
);
},
"sign"
);
const signCell = DOM.create("td", null, signInput);
signCell.append(
this.#createUserCheckbox(
user.enabledForUsername,
user.username,
"enabledForUsername",
this.settings.options.enabledForUsername.getValue()
)
);
row.append(DOM.create("th", null, signCell));
const colorInputContainer = DOM.create("div");
const colorInput = DOM.create("input");
colorInput.setAttribute("type", "color");
colorInput.value = this.#getUserColorPickerColor(user);
colorInput.addEventListener(
"change",
(event) => this.#handleUserColorChange(event, user.username),
false
);
colorInputContainer.append(colorInput);
colorInputContainer.append(
IconButton(RefreshIcon(), () => {
this.#handleUserColorReset(user.username);
})
);
colorInputContainer.append(
this.#createUserCheckbox(
user.copyColorFromProfile,
user.username,
"copyColorFromProfile",
this.settings.options.copyColorFromProfile.getValue()
)
);
colorInputContainer.append(
this.#createUserCheckbox(
user.highlightEnabled,
user.username,
"highlightEnabled",
this.settings.options.highlightEnabled.getValue()
)
);
colorInputContainer.append(
this.#createUserCheckbox(
user.highlightEnabledForReplies,
user.username,
"highlightEnabledForReplies",
this.settings.options.highlightEnabledForReplies.getValue()
)
);
colorInputContainer.append(
this.#createUserCheckbox(
user.colorUserActivity,
user.username,
"colorUserActivity",
this.settings.options.colorUserActivity.getValue()
)
);
colorInputContainer.append(
this.#createUserCheckbox(
user.colorUserReplies,
user.username,
"colorUserReplies",
this.settings.options.colorUserReplies.getValue()
)
);
const colorCell = DOM.create("td", null, colorInputContainer);
row.append(colorCell);
const quickAccessCheckbox = this.#createUserCheckbox(
user.quickAccessEnabled,
user.username,
"quickAccessEnabled",
this.settings.options.quickAccessEnabled.getValue()
);
const otherCell = DOM.create("td", null, quickAccessCheckbox);
const cssEnabledCheckbox = this.#createUserCheckbox(
user.onlyLoadCssFromVerifiedUser,
user.username,
"onlyLoadCssFromVerifiedUser",
this.settings.options.onlyLoadCssFromVerifiedUser.getValue()
);
otherCell.append(cssEnabledCheckbox);
row.append(otherCell);
const deleteButton = DOM.create("button", null, "❌");
deleteButton.addEventListener("click", () =>
this.#removeUser(user.username)
);
row.append(DOM.create("th", null, deleteButton));
return row;
}
#getUserColorPickerColor(user) {
if (user.colorOverride) {
return user.colorOverride;
}
if (
user.color &&
(user.copyColorFromProfile ||
this.settings.options.copyColorFromProfile.getValue())
) {
return ColorFunctions.rgbToHex(user.color);
}
if (this.settings.options.useDefaultHighlightColor.getValue()) {
return this.settings.options.defaultHighlightColor.getValue();
}
return ColorFunctions.rgbToHex(this.AnilistBlue);
}
#createUserCheckbox(isChecked, username, settingKey, disabled) {
const onChange = (event) => {
this.#updateUserOption(username, settingKey, event.target.checked);
this.renderSettingsUiContent();
};
const checkbox = Checkbox(
isChecked,
onChange,
this.settings.options[settingKey].description,
disabled);
return checkbox;
}
#handleUserColorReset(username) {
this.#updateUserOption(username, "colorOverride", undefined);
this.renderSettingsUiContent();
}
#handleUserColorChange(event, username) {
const color = event.target.value;
this.#updateUserOption(username, "colorOverride", color);
}
async #handleVerifyUserForm(event, settings) {
event.preventDefault();
const usernameInput = DOM.get("#void-verified-add-user");
const username = usernameInput.value;
await settings.verifyUser(username);
usernameInput.value = "";
this.renderSettingsUiContent();
}
#updateUserOption(username, key, value) {
this.settings.updateUserOption(username, key, value);
this.styleHandler.refreshStyles();
}
#removeUser(username) {
this.settings.removeUser(username);
this.renderSettingsUiContent();
this.styleHandler.refreshStyles();
}
#renderSetting(setting, settingsContainer, settingKey) {
if (setting.category === categories.hidden) {
return;
}
const value = setting.getValue();
const type = typeof value;
let input;
const onChange = (event) => {
this.#handleOption(event, settingKey, type);
};
if (type === "boolean") {
input = Checkbox(value, onChange);
} else if (settingKey == "defaultHighlightColor") {
return;
} else if (type === "string") {
input = InputField(value, onChange);
}
input.setAttribute("id", settingKey);
settingsContainer.append(SettingLabel(setting.description, input));
}
#handleOption(event, settingKey, type) {
const value =
type === "boolean" ? event.target.checked : event.target.value;
this.settings.saveSettingToLocalStorage(settingKey, value);
this.styleHandler.refreshStyles();
if (!this.#shouldDisplaySubCategory(this.#activeSubCategory)) {
this.#activeSubCategory = subCategories.users;
}
this.renderSettingsUiContent();
}
// TODO: separate userCSS
#renderCustomCssEditor(settingsContainer, cssHandler) {
const cssName = cssHandler instanceof GlobalCSS ? "global" : "user";
const container = DOM.create("div", "css-editor");
const label = DOM.create("label", null, `Custom ${cssName} CSS`);
label.setAttribute("for", `void-verified-${cssName}-css-editor`);
container.append(label);
const textarea = TextArea(cssHandler.css, (event) => {
this.#handleCustomCssEditor(event, cssHandler);
});
container.append(textarea);
if (cssName === "global") {
const notice = DOM.create("div");
notice.innerText =
"Please note that Custom CSS is disabled in the settings. \nIn the event that you accidentally disable rendering of critical parts of AniList, navigate to the settings by URL";
notice.style.fontSize = "11px";
container.append(notice);
} else {
const publishButton = DOM.create("button", null, "Publish");
publishButton.classList.add("button");
publishButton.addEventListener("click", (event) =>
this.#handlePublishCss(event, cssHandler)
);
const previewButton = DOM.create(
"button",
null,
cssHandler.preview ? "Disable Preview" : "Enable Preview"
);
previewButton.classList.add("button");
previewButton.addEventListener("click", () => {
cssHandler.togglePreview();
previewButton.innerText = cssHandler.preview
? "Disable Preview"
: "Enable Preview";
});
const resetButton = DOM.create("button", null, "Reset");
resetButton.classList.add("button");
resetButton.addEventListener("click", () => {
if (window.confirm("Your changes will be lost.")) {
cssHandler.getAuthUserCss().then(() => {
textarea.value = cssHandler.css;
});
}
});
container.append(publishButton);
container.append(previewButton);
container.append(resetButton);
}
settingsContainer.append(container);
}
// TODO: separate userCSS
#handlePublishCss(event, cssHandler) {
const btn = event.target;
btn.innerText = "Publishing...";
cssHandler.publishUserCss().then(() => {
btn.innerText = "Publish";
});
}
// TODO: separate userCSS
#handleCustomCssEditor(event, cssHandler) {
const value = event.target.value;
cssHandler.updateCss(value);
}
// TODO: separate to imageHostService?
#renderImageHostSettings(settingsContainer) {
const container = DOM.create("div");
const imageHostService = new ImageHostService();
const imageApiFactory = new ImageApiFactory();
const imageHostOptions = Object.values(imageHosts).map((imageHost) =>
Option$1(
imageHost,
imageHost === imageHostService.getSelectedHost(),
() => {
imageHostService.setSelectedHost(imageHost);
this.renderSettingsUiContent();
}
)
);
const select = Select(imageHostOptions);
container.append(Label("Image host", select));
const hostSpecificSettings = DOM.create("div");
const imageHostApi = imageApiFactory.getImageHostInstance();
hostSpecificSettings.append(imageHostApi.renderSettings(this));
container.append(hostSpecificSettings);
settingsContainer.append(container);
}
#creatAuthenticationSection(settingsContainer) {
const isAuthenticated =
this.settings.auth !== null &&
new Date(this.settings.auth?.expires) > new Date();
const clientId = 15519;
const authenticationContainer = DOM.create("div");
const header = DOM.create("h3", null, "Authorize VoidVerified");
const description = DOM.create(
"p",
null,
"Some features of VoidVerified might need your access token to work correctly or fully. Below is a list of features using your access token. If you do not wish to use any of these features, you do not need to authenticate. If revoking authentication, be sure to revoke VoidVerified from Anilist Apps as well."
);
const list = DOM.create("ul");
for (const option of Object.values(this.settings.options).filter(
(o) => o.authRequired
)) {
list.append(DOM.create("li", null, option.description));
}
const authLink = DOM.create("a", "button", "Authenticate VoidVerified");
authLink.setAttribute(
"href",
`https://anilist.co/api/v2/oauth/authorize?client_id=${clientId}&response_type=token`
);
const removeAuthButton = DOM.create(
"button",
null,
"Revoke auth token"
);
removeAuthButton.classList.add("button");
removeAuthButton.addEventListener("click", () => {
this.settings.removeAuthToken();
this.renderSettingsUiContent();
});
authenticationContainer.append(header);
authenticationContainer.append(description);
authenticationContainer.append(list);
authenticationContainer.append(
!isAuthenticated ? authLink : removeAuthButton
);
settingsContainer.append(authenticationContainer);
}
#checkAuthFromUrl() {
const hash = window.location.hash.substring(1);
if (!hash) {
return;
}
const [path, token, type, expiress] = hash.split("&");
if (path === "void_imgur") {
const imgurConfig =
new ImageHostService().getImageHostConfiguration(
imageHosts.imgur
);
new ImgurAPI(imgurConfig).handleAuth();
}
if (path !== "void_auth") {
return;
}
const expiresDate = new Date(
new Date().getTime() + Number(expiress.split("=")[1]) * 1000
);
this.settings.saveAuthToken({
token: token.split("=")[1],
expires: expiresDate,
});
window.history.replaceState(
null,
"",
"https://anilist.co/settings/developer"
);
}
}
class QuickAccess {
settings;
#quickAccessId = "void-quick-access";
#lastFetchedLocalStorage = "void-verified-last-fetched";
#lastFetched;
#queryInProgress = false;
#apiQueryTimeoutInMinutes = 15;
#apiQueryTimeout = this.#apiQueryTimeoutInMinutes * 60 * 1000;
constructor(settings) {
this.settings = settings;
const fetched = localStorage.getItem(this.#lastFetchedLocalStorage);
if (fetched) {
this.#lastFetched = new Date(fetched);
}
}
async renderQuickAccess() {
if (this.#queryInProgress) {
return;
}
const queried = await this.#queryUsers();
if (!queried && this.#quickAccessRendered()) {
this.#updateTimer();
return;
}
if (
!this.settings.options.quickAccessEnabled.getValue() &&
!this.settings.verifiedUsers.some((user) => user.quickAccessEnabled)
) {
return;
}
const quickAccessContainer = DOM.getOrCreate(
"div",
"#quick-access quick-access"
);
const sectionHeader = document.createElement("div");
sectionHeader.setAttribute("class", "section-header");
const title = document.createElement("h2");
title.append("Quick Access");
title.setAttribute(
"title",
`Last updated at ${this.#lastFetched.toLocaleTimeString()}`
);
sectionHeader.append(title);
const timer = DOM.create("span", "quick-access-timer", "");
const refreshButton = IconButton(RefreshIcon(), () => {
this.#queryUsers(true);
});
sectionHeader.append(DOM.create("div", null, [timer, refreshButton]));
const quickAccessBody = document.createElement("div");
quickAccessBody.setAttribute("class", "void-quick-access-wrap");
for (const user of this.#getQuickAccessUsers()) {
quickAccessBody.append(this.#createQuickAccessLink(user));
}
const section = document.querySelector(
".container > .home > div:nth-child(2)"
);
quickAccessContainer.replaceChildren(sectionHeader, quickAccessBody);
if (DOM.get("#void-quick-access")) {
return;
}
section.insertBefore(quickAccessContainer, section.firstChild);
}
#updateTimer() {
if (!this.settings.options.quickAccessTimer.getValue()) {
return;
}
const timer = DOM.get(".void-quick-access-timer");
const nextQuery = new Date(
this.#lastFetched.getTime() + this.#apiQueryTimeout
);
const timeLeftInSeconds = Math.floor((nextQuery - new Date()) / 1000);
const timeLeftInMinutes = timeLeftInSeconds / 60;
if (timeLeftInMinutes > 1) {
timer.replaceChildren(`${Math.floor(timeLeftInSeconds / 60)}m`);
return;
}
timer.replaceChildren(`${timeLeftInSeconds}s`);
}
async #queryUsers(ignoreLastFetched = false) {
const currentTime = new Date();
if (
!this.#lastFetched ||
currentTime - this.#lastFetched > this.#apiQueryTimeout ||
ignoreLastFetched
) {
try {
Toaster.debug("Querying Quick Access users.");
this.#queryInProgress = true;
const anilistAPI = new AnilistAPI(this.settings);
await anilistAPI.queryVerifiedUsers();
Toaster.success("Quick Access users updated.");
} catch (error) {
Toaster.error("Querying Quick Access failed.");
console.error(error);
} finally {
this.#lastFetched = new Date();
localStorage.setItem(
this.#lastFetchedLocalStorage,
this.#lastFetched
);
this.#queryInProgress = false;
return true;
}
} else {
return false;
}
}
clearBadge() {
const username =
window.location.pathname.match(/^\/user\/([^/]*)\/?/)[1];
this.settings.updateUserOption(
username,
"quickAccessBadgeDisplay",
false
);
}
#createQuickAccessLink(user) {
const container = document.createElement("a");
container.setAttribute("class", "void-quick-access-item");
container.setAttribute(
"href",
`https://anilist.co/user/${user.username}/`
);
const image = document.createElement("div");
image.style.backgroundImage = `url(${user.avatar})`;
image.setAttribute("class", "void-quick-access-pfp");
container.append(image);
const username = document.createElement("div");
username.append(user.username);
username.setAttribute("class", "void-quick-access-username");
if (
(this.settings.options.quickAccessBadge.getValue() ||
user.quickAccessBadge) &&
user.quickAccessBadgeDisplay
) {
container.classList.add("void-quick-access-badge");
}
container.append(username);
return container;
}
#quickAccessRendered() {
const quickAccess = document.getElementById(this.#quickAccessId);
return quickAccess !== null;
}
#getQuickAccessUsers() {
if (this.settings.options.quickAccessEnabled.getValue()) {
return this.settings.verifiedUsers;
}
return this.settings.verifiedUsers.filter(
(user) => user.quickAccessEnabled
);
}
}
// Copyright (c) 2013 Pieroxy
// This work is free. You can redistribute it and/or modify it
// under the terms of the WTFPL, Version 2
// For more information see LICENSE.txt or http://www.wtfpl.net/
//
// For more information, the home page:
// http://pieroxy.net/blog/pages/lz-string/testing.html
//
// LZ-based compression algorithm, version 1.4.4
var LZString = (function () {
// private property
var f = String.fromCharCode;
var keyStrBase64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var keyStrUriSafe =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
var baseReverseDic = {};
function getBaseValue(alphabet, character) {
if (!baseReverseDic[alphabet]) {
baseReverseDic[alphabet] = {};
for (var i = 0; i < alphabet.length; i++) {
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
}
}
return baseReverseDic[alphabet][character];
}
var LZString = {
compressToBase64: function (input) {
if (input == null) return "";
var res = LZString._compress(input, 6, function (a) {
return keyStrBase64.charAt(a);
});
switch (
res.length % 4 // To produce valid Base64
) {
default: // When could this happen ?
case 0:
return res;
case 1:
return res + "===";
case 2:
return res + "==";
case 3:
return res + "=";
}
},
decompressFromBase64: function (input) {
if (input == null) return "";
if (input == "") return null;
return LZString._decompress(input.length, 32, function (index) {
return getBaseValue(keyStrBase64, input.charAt(index));
});
},
compressToUTF16: function (input) {
if (input == null) return "";
return (
LZString._compress(input, 15, function (a) {
return f(a + 32);
}) + " "
);
},
decompressFromUTF16: function (compressed) {
if (compressed == null) return "";
if (compressed == "") return null;
return LZString._decompress(
compressed.length,
16384,
function (index) {
return compressed.charCodeAt(index) - 32;
}
);
},
//compress into uint8array (UCS-2 big endian format)
compressToUint8Array: function (uncompressed) {
var compressed = LZString.compress(uncompressed);
var buf = new Uint8Array(compressed.length * 2); // 2 bytes per character
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
var current_value = compressed.charCodeAt(i);
buf[i * 2] = current_value >>> 8;
buf[i * 2 + 1] = current_value % 256;
}
return buf;
},
//decompress from uint8array (UCS-2 big endian format)
decompressFromUint8Array: function (compressed) {
if (compressed === null || compressed === undefined) {
return LZString.decompress(compressed);
} else {
var buf = new Array(compressed.length / 2); // 2 bytes per character
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
}
var result = [];
buf.forEach(function (c) {
result.push(f(c));
});
return LZString.decompress(result.join(""));
}
},
//compress into a string that is already URI encoded
compressToEncodedURIComponent: function (input) {
if (input == null) return "";
return LZString._compress(input, 6, function (a) {
return keyStrUriSafe.charAt(a);
});
},
//decompress from an output of compressToEncodedURIComponent
decompressFromEncodedURIComponent: function (input) {
if (input == null) return "";
if (input == "") return null;
input = input.replace(/ /g, "+");
return LZString._decompress(input.length, 32, function (index) {
return getBaseValue(keyStrUriSafe, input.charAt(index));
});
},
compress: function (uncompressed) {
return LZString._compress(uncompressed, 16, function (a) {
return f(a);
});
},
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
if (uncompressed == null) return "";
var i,
value,
context_dictionary = {},
context_dictionaryToCreate = {},
context_c = "",
context_wc = "",
context_w = "",
context_enlargeIn = 2, // Compensate for the first entry which should not count
context_dictSize = 3,
context_numBits = 2,
context_data = [],
context_data_val = 0,
context_data_position = 0,
ii;
for (ii = 0; ii < uncompressed.length; ii += 1) {
context_c = uncompressed.charAt(ii);
if (
!Object.prototype.hasOwnProperty.call(
context_dictionary,
context_c
)
) {
context_dictionary[context_c] = context_dictSize++;
context_dictionaryToCreate[context_c] = true;
}
context_wc = context_w + context_c;
if (
Object.prototype.hasOwnProperty.call(
context_dictionary,
context_wc
)
) {
context_w = context_wc;
} else {
if (
Object.prototype.hasOwnProperty.call(
context_dictionaryToCreate,
context_w
)
) {
if (context_w.charCodeAt(0) < 256) {
for (i = 0; i < context_numBits; i++) {
context_data_val = context_data_val << 1;
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i = 0; i < 8; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i = 0; i < context_numBits; i++) {
context_data_val =
(context_data_val << 1) | value;
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i = 0; i < 16; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i = 0; i < context_numBits; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
// Add wc to the dictionary.
context_dictionary[context_wc] = context_dictSize++;
context_w = String(context_c);
}
}
// Output the code for w.
if (context_w !== "") {
if (
Object.prototype.hasOwnProperty.call(
context_dictionaryToCreate,
context_w
)
) {
if (context_w.charCodeAt(0) < 256) {
for (i = 0; i < context_numBits; i++) {
context_data_val = context_data_val << 1;
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i = 0; i < 8; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i = 0; i < context_numBits; i++) {
context_data_val = (context_data_val << 1) | value;
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i = 0; i < 16; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(
getCharFromInt(context_data_val)
);
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i = 0; i < context_numBits; i++) {
context_data_val =
(context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
}
// Mark the end of the stream
value = 2;
for (i = 0; i < context_numBits; i++) {
context_data_val = (context_data_val << 1) | (value & 1);
if (context_data_position == bitsPerChar - 1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
// Flush the last char
while (true) {
context_data_val = context_data_val << 1;
if (context_data_position == bitsPerChar - 1) {
context_data.push(getCharFromInt(context_data_val));
break;
} else context_data_position++;
}
return context_data.join("");
},
decompress: function (compressed) {
if (compressed == null) return "";
if (compressed == "") return null;
return LZString._decompress(
compressed.length,
32768,
function (index) {
return compressed.charCodeAt(index);
}
);
},
_decompress: function (length, resetValue, getNextValue) {
var dictionary = [],
enlargeIn = 4,
dictSize = 4,
numBits = 3,
entry = "",
result = [],
i,
w,
bits,
resb,
maxpower,
power,
c,
data = { val: getNextValue(0), position: resetValue, index: 1 };
for (i = 0; i < 3; i += 1) {
dictionary[i] = i;
}
bits = 0;
maxpower = Math.pow(2, 2);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
switch ((bits)) {
case 0:
bits = 0;
maxpower = Math.pow(2, 8);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
c = f(bits);
break;
case 1:
bits = 0;
maxpower = Math.pow(2, 16);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
c = f(bits);
break;
case 2:
return "";
}
dictionary[3] = c;
w = c;
result.push(c);
while (true) {
if (data.index > length) {
return "";
}
bits = 0;
maxpower = Math.pow(2, numBits);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
switch ((c = bits)) {
case 0:
bits = 0;
maxpower = Math.pow(2, 8);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
dictionary[dictSize++] = f(bits);
c = dictSize - 1;
enlargeIn--;
break;
case 1:
bits = 0;
maxpower = Math.pow(2, 16);
power = 1;
while (power != maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb > 0 ? 1 : 0) * power;
power <<= 1;
}
dictionary[dictSize++] = f(bits);
c = dictSize - 1;
enlargeIn--;
break;
case 2:
return result.join("");
}
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
if (dictionary[c]) {
entry = dictionary[c];
} else {
if (c === dictSize) {
entry = w + w.charAt(0);
} else {
return null;
}
}
result.push(entry);
// Add w+entry[0] to the dictionary.
dictionary[dictSize++] = w + entry.charAt(0);
enlargeIn--;
w = entry;
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
}
},
};
return LZString;
})();
var LZString$1 = LZString;
class UserCSS {
#settings;
#currentActivity;
#currentUser;
css = "";
preview = false;
cssInLocalStorage = "void-verified-user-css";
broadcastChannel;
constructor(settings) {
this.#settings = settings;
if (
this.#settings.auth?.token &&
this.#settings.options.profileCssEnabled.getValue()
) {
const cssInLocalStorage = JSON.parse(
localStorage.getItem(this.cssInLocalStorage)
);
if (cssInLocalStorage) {
this.css = cssInLocalStorage.css;
this.preview = cssInLocalStorage.preview;
} else {
this.getAuthUserCss();
}
}
this.broadcastChannel = new BroadcastChannel("user-css");
this.broadcastChannel.addEventListener("message", (event) =>
this.#handleBroadcastMessage(event, this.#settings)
);
}
async checkActivityCss() {
if (
!this.#settings.options.activityCssEnabled.getValue() ||
!window.location.pathname.startsWith("/activity/")
) {
return;
}
const activityId = window.location.pathname.match(
/^\/activity\/([^/]*)\/?/
)[1];
if (this.#currentActivity === activityId) {
return;
}
this.#currentActivity = activityId;
let activity;
try {
Toaster.debug("Querying user activity.");
const anilistAPI = new AnilistAPI(this.#settings);
activity = await anilistAPI.getActivityCss(activityId);
} catch {
Toaster.error("Failed to get activity CSS.");
return;
}
const username = activity.user?.name ?? activity.recipient?.name;
const userColor =
activity.user?.options.profileColor ??
activity.recipient?.options.profileColor;
const rgb = ColorFunctions.handleAnilistColor(userColor);
const activityEntry = document.querySelector(
".container > .activity-entry"
);
activityEntry.style.setProperty("--color-blue", rgb);
activityEntry.style.setProperty("--color-blue-dim", rgb);
if (username === this.#settings.anilistUser && this.preview) {
this.#renderCss(this.css, "user-css");
return;
}
if (username === this.#currentUser) {
this.#clearGlobalCss();
return;
}
new StyleHandler(this.#settings).clearStyles("user-css");
if (!this.#shouldRenderCss(username)) {
return;
}
const about = activity.user?.about ?? activity.recipient?.about;
const css = this.#decodeAbout(about)?.customCSS;
if (css) {
this.#renderCss(css, "user-css");
} else {
Toaster.debug("User has no custom CSS.");
}
this.#currentUser = username;
}
resetCurrentActivity() {
this.#currentActivity = null;
}
async checkUserCss() {
if (
!this.#settings.options.profileCssEnabled.getValue() ||
!window.location.pathname.startsWith("/user/")
) {
return;
}
const username =
window.location.pathname.match(/^\/user\/([^/]*)\/?/)[1];
if (username === this.#currentUser) {
return;
}
if (username === this.#settings.anilistUser && this.preview) {
this.#renderCss(this.css, "user-css");
return;
}
if (!this.#shouldRenderCss(username)) {
new StyleHandler(this.#settings).clearStyles("user-css");
return;
}
this.#currentUser = username;
let about;
try {
Toaster.debug("Querying user CSS.");
const anilistAPI = new AnilistAPI(this.#settings);
about = await anilistAPI.getUserAbout(username);
} catch (error) {
Toaster.error("Failed to load user's CSS.");
return;
}
const css = this.#decodeAbout(about)?.customCSS;
if (!css) {
Toaster.debug("User has no custom CSS.");
new StyleHandler(this.#settings).clearStyles("user-css");
}
this.#renderCss(css, "user-css");
}
resetCurrentUser() {
this.#currentUser = null;
}
updateCss(css) {
this.css = css;
if (this.preview) {
this.broadcastChannel.postMessage({ type: "css", css });
}
this.#saveToLocalStorage();
}
async publishUserCss() {
const username = this.#settings.anilistUser;
if (!username) {
return;
}
const anilistAPI = new AnilistAPI(this.#settings);
let about;
try {
Toaster.debug("Querying account user about to merge changes into.");
about = await anilistAPI.getUserAbout(username);
} catch (error) {
Toaster.error("Failed to get current about for merging new CSS.");
}
if (!about) {
about = "";
}
let aboutJson = this.#decodeAbout(about);
aboutJson.customCSS = this.css;
const compressedAbout = LZString$1.compressToBase64(
JSON.stringify(aboutJson)
);
const target = about.match(/^\[\]\(json([A-Za-z0-9+/=]+)\)/)?.[1];
if (target) {
about = about.replace(target, compressedAbout);
} else {
about = `[](json${compressedAbout})\n\n` + about;
}
try {
Toaster.debug("Publishing CSS.");
await anilistAPI.saveUserAbout(about);
Toaster.success("CSS published.");
} catch (error) {
Toaster.error("Failed to publish CSS changes.");
}
}
togglePreview() {
this.preview = !this.preview;
this.broadcastChannel.postMessage({
type: "preview",
preview: this.preview,
});
this.#saveToLocalStorage();
}
async getAuthUserCss() {
const anilistAPI = new AnilistAPI(this.#settings);
const username = this.#settings.anilistUser;
if (!username) {
return;
}
try {
Toaster.debug("Querying account user CSS.");
const about = await anilistAPI.getUserAbout(username);
const css = this.#decodeAbout(about).customCSS;
this.css = css;
this.#saveToLocalStorage();
return css;
} catch (error) {
Toaster.error("Failed to query account user CSS.");
}
}
#handleBroadcastMessage(event, settings) {
switch (event.data.type) {
case "css":
this.#handlePreviewCssMessage(event.data.css, settings);
break;
case "preview":
this.#handlePreviewToggleMessage(event.data.preview);
break;
}
}
#handlePreviewCssMessage(css, settings) {
this.css = css;
const hasUserCss = document.getElementById(
"void-verified-user-css-styles"
);
if (hasUserCss) {
new StyleHandler(settings).createStyleLink(css, "user-css");
}
}
#handlePreviewToggleMessage(preview) {
this.preview = preview;
const hasUserCss = document.getElementById(
"void-verified-user-css-styles"
);
if (!hasUserCss) {
return;
}
this.resetCurrentUser();
this.resetCurrentActivity();
this.checkUserCss();
this.checkActivityCss();
}
#saveToLocalStorage() {
localStorage.setItem(
this.cssInLocalStorage,
JSON.stringify({
css: this.css,
preview: this.preview,
})
);
}
#shouldRenderCss(username) {
const user = this.#settings.getUser(username);
if (
this.#settings.options.onlyLoadCssFromVerifiedUser.getValue() &&
!this.#settings.isVerified(username)
) {
return false;
}
if (user?.onlyLoadCssFromVerifiedUser) {
return true;
}
return !this.#userSpecificRenderingExists();
}
#userSpecificRenderingExists() {
return this.#settings.verifiedUsers.some(
(user) => user.onlyLoadCssFromVerifiedUser
);
}
#renderCss(css, id) {
if (!css) {
return;
}
const styleHandler = new StyleHandler(this.#settings);
styleHandler.createStyleLink(css, id);
this.#clearGlobalCss();
}
#clearGlobalCss() {
if (this.#settings.options.globalCssAutoDisable.getValue()) {
new StyleHandler(this.#settings).clearStyles("global-css");
}
}
#decodeAbout(about) {
let json = (about || "").match(/^\[\]\(json([A-Za-z0-9+/=]+)\)/);
if (!json) {
return {
customCss: "",
};
}
let jsonData;
try {
jsonData = JSON.parse(atob(json[1]));
} catch (e) {
jsonData = JSON.parse(LZString$1.decompressFromBase64(json[1]));
}
return jsonData;
}
}
const markdownRegex = [
{
regex: /^##### (.*$)/gim,
format: "$1
",
},
{
regex: /^#### (.*$)/gim,
format: "$1
",
},
{
regex: /^### (.*$)/gim,
format: "$1
",
},
{
regex: /^## (.*$)/gim,
format: "$1
",
},
{
regex: /^# (.*$)/gim,
format: "$1
",
},
{
regex: /\_\_(.*)\_\_/gim,
format: "$1",
},
{
regex: /\_(.*)\_/gim,
format: "$1",
},
{
regex: /(?:\r\n|\r|\n)/g,
format: "
",
},
{
regex: /\~~~(.*)\~~~/gim,
format: "$1",
},
{
regex: /\[([^\]]*)\]\(([^\)]+)\)/gi,
format: "$1",
},
{
regex: /\~\!(.*)\!\~/gi,
format: "$1",
},
{
regex: /img([0-9]+%?)\(([^\)]+)\)/g,
format: "
",
},
];
class Markdown {
static parse(markdown) {
let html = markdown;
for (const parser of markdownRegex) {
html = html.replace(parser.regex, parser.format);
}
return html;
}
}
class Layout {
avatar;
banner;
bio;
color;
donatorBadge;
name;
constructor(layout) {
this.avatar = layout?.avatar ?? "";
this.banner = layout?.banner ?? "";
this.bio = layout?.bio ?? "";
this.color = layout?.color ?? "";
this.donatorBadge = layout?.donatorBadge ?? "";
this.name = layout?.name ?? "New Layout";
}
}
class LayoutDesigner {
#settings;
#layoutsInLocalStorage = "void-verified-layouts";
#originalHtml;
#broadcastChannel;
#donatorTier = 0;
#anilistSettings;
#layout;
#layouts = {
selectedLayout: 0,
preview: false,
disableCss: false,
layoutsList: [new Layout()],
};
constructor(settings) {
this.#settings = settings;
this.#broadcastChannel = new BroadcastChannel("void-layouts");
this.#broadcastChannel.addEventListener("message", (event) =>
this.#handleBroadcastMessage(event)
);
const layouts = JSON.parse(
localStorage.getItem(this.#layoutsInLocalStorage)
);
if (layouts) {
this.#layouts = layouts;
this.#layouts.layoutsList = layouts.layoutsList.map(
(layout) => new Layout(layout)
);
}
this.#anilistSettings = JSON.parse(localStorage.getItem("auth"));
this.#donatorTier = this.#anilistSettings?.donatorTier;
this.#layout = this.#getSelectedLayout();
}
renderLayoutPreview() {
if (!this.#settings.options.layoutDesignerEnabled.getValue()) {
return;
}
if (!window.location.pathname.startsWith("/user/")) {
return;
}
const username =
window.location.pathname.match(/^\/user\/([^/]*)\/?/)[1];
if (username !== this.#settings.anilistUser || !this.#layouts.preview) {
return;
}
this.#handleAvatar(this.#layout.avatar);
this.#handleBanner(this.#layout.banner);
this.#handleColor(this.#layout.color);
this.#handleDonatorBadge(this.#layout.donatorBadge);
this.#handleCss();
this.#handleAbout(Markdown.parse(this.#layout.bio ?? ""));
}
#handleBroadcastMessage(event) {
switch (event.data.type) {
case "preview":
this.#handlePreviewToggleMessage(event.data.preview);
break;
case "layout":
this.#handleLayoutMessage(event.data.layout);
break;
case "css":
this.#handleCssMessage(event.data.disableCss);
break;
}
}
#handlePreviewToggleMessage(preview) {
this.#layouts.preview = preview;
if (preview) {
return;
}
this.#handleAvatar(this.#anilistSettings?.avatar?.large);
this.#handleBanner(this.#anilistSettings?.bannerImage);
this.#handleColor(this.#anilistSettings.options.profileColor);
this.#handleDonatorBadge(this.#anilistSettings.donatorBadge);
this.#layouts.disableCss = false;
this.#handleCss();
this.#handleAbout(this.#originalHtml);
}
#handleLayoutMessage(layout) {
this.#layout = layout;
}
#handleCssMessage(disableCss) {
this.#layouts.disableCss = disableCss;
}
#handleAvatar(avatar) {
if (avatar === "") {
return;
}
const avatarElement = DOM.get("img.avatar");
avatarElement.src = avatar;
const avatarLinks = DOM.getAll(
`a.avatar[href*="${this.#settings.anilistUser}"]`
);
for (const avatarLink of avatarLinks) {
avatarLink.style = `background-image: url(${avatar})`;
}
}
#handleBanner(banner) {
if (banner === "") {
return;
}
const bannerElement = DOM.get(".banner");
bannerElement.style = `background-image: url(${banner})`;
}
#handleColor(value) {
let color;
try {
color = ColorFunctions.handleAnilistColor(value);
} catch (err) {
return;
}
const pageContent = DOM.get(".page-content > .user");
pageContent.style.setProperty("--color-blue", color);
pageContent.style.setProperty("--color-blue-dim", color);
}
#handleDonatorBadge(donatorText) {
if (this.#donatorTier < 3 || donatorText === "") {
return;
}
const donatorBadge = DOM.get(".donator-badge");
donatorBadge.innerText = donatorText;
}
#handleCss() {
if (this.#layouts.disableCss) {
DOM.get("#void-verified-user-css-styles")?.setAttribute(
"disabled",
true
);
} else {
DOM.get("#void-verified-user-css-styles")?.removeAttribute(
"disabled"
);
}
}
#handleAbout(about) {
const aboutContainer = DOM.get(".about .markdown");
if (!this.#originalHtml) {
this.#originalHtml = aboutContainer.innerHTML;
}
aboutContainer.innerHTML = about !== "" ? about : this.#originalHtml;
}
renderSettings(settingsUi) {
if (!this.#settings.options.layoutDesignerEnabled.getValue()) {
return "";
}
const container = DOM.create("div", "layout-designer-container");
const header = DOM.create("h3", null, "Layout Designer");
const layoutSelector = this.#createLayoutSelector(settingsUi);
const layoutInfoSection = this.#layoutInfoSection(settingsUi);
const imageSection = DOM.create("div");
imageSection.append(
this.#createImageField("avatar", this.#layout.avatar, settingsUi)
);
imageSection.append(
this.#createImageField("banner", this.#layout.banner, settingsUi)
);
const imageUploadNote = Note(
"You can preview avatar & banner by providing a link to an image. If you have configured a image host, you can upload images by pasting them to the fields. "
);
imageUploadNote.append(
DOM.create("br"),
"Unfortunately AniList API does not support third parties uploading new avatars or banners. You have to upload them separately."
);
const colorSelection = this.#createColorSelection(settingsUi);
const previewButton = Button(
this.#layouts.preview ? "Disable Preview" : "Enable Preview",
() => {
this.#togglePreview(settingsUi);
}
);
const cssButton = Button(
this.#layouts.disableCss ? "Enable Css" : "Disable Css",
() => {
this.#toggleCss();
cssButton.innerText = this.#layouts.disableCss
? "Enable Css"
: "Disable Css";
}
);
const getAboutButton = Button("Reset About", () => {
this.#getUserAbout(settingsUi);
});
container.append(
header,
layoutSelector,
layoutInfoSection,
imageSection,
imageUploadNote,
colorSelection
);
if (this.#donatorTier >= 3) {
container.append(this.#createDonatorBadgeField(settingsUi));
}
container.append(this.#createAboutSection(settingsUi), getAboutButton);
if (this.#settings.auth?.token) {
const saveAboutButton = Button("Publish About", (event) => {
this.#publishAbout(event, settingsUi);
});
container.append(saveAboutButton);
}
container.append(previewButton);
if (this.#layouts.preview) {
container.append(cssButton);
}
return container;
}
#createLayoutSelector(settingsUi) {
const container = DOM.create("div");
container.append(
IconButton(AddIcon(), () => {
this.#addLayout();
settingsUi.renderSettingsUiContent();
})
);
const options = this.#layouts.layoutsList.map((layout, index) =>
Option$1(
`${layout.name} #${index + 1}`,
index === this.#layouts.selectedLayout,
() => {
this.#switchLayout(index);
settingsUi.renderSettingsUiContent();
}
)
);
container.append(Select(options));
return container;
}
#switchLayout(index) {
this.#layout = this.#layouts.layoutsList[index];
this.#layouts.selectedLayout = index;
this.#saveToLocalStorage();
this.#broadcastLayoutChange();
}
#addLayout() {
const layout = new Layout();
this.#layout = layout;
this.#layouts.layoutsList.push(layout);
this.#layouts.selectedLayout = Math.max(
this.#layouts.layoutsList.length - 1,
0
);
this.#saveToLocalStorage();
this.#broadcastLayoutChange();
}
#deleteLayout() {
if (!window.confirm("Are you sure you want to delete this layout?")) {
return;
}
this.#layouts.layoutsList.splice(this.#layouts.selectedLayout, 1);
this.#layouts.selectedLayout = Math.max(
this.#layouts.selectedLayout - 1,
0
);
if (this.#layouts.layoutsList.length === 0) {
this.#layouts.layoutsList.push(new Layout());
}
this.#layout = this.#layouts.layoutsList[this.#layouts.selectedLayout];
this.#saveToLocalStorage();
this.#broadcastLayoutChange();
}
#layoutInfoSection(settingsUi) {
const container = Label(
"Layout name",
InputField(this.#layout?.name, (event) => {
this.#updateOption("name", event.target.value, settingsUi);
})
);
container.append(
IconButton(TrashcanIcon(), () => {
this.#deleteLayout();
settingsUi.renderSettingsUiContent();
})
);
return container;
}
#createInputField(field, value, settingsUi) {
const input = InputField(value, (event) => {
this.#updateOption(field, event.target.value, settingsUi);
});
return input;
}
#createImageField(field, value, settingsUi) {
const container = DOM.create("div", "layout-image-container");
const header = DOM.create("h5", "layout-header", field);
const display = DOM.create("div", `layout-image-display ${field}`);
display.style.backgroundImage = `url(${value})`;
const input = this.#createInputField(field, value, settingsUi);
container.append(header, display, input);
return container;
}
#createDonatorBadgeField(settingsUi) {
const container = DOM.create("div", "layout-donator-badge-container");
const donatorHeader = DOM.create(
"h5",
"layout-header",
"Donator Badge"
);
const donatorInput = InputField(this.#layout.donatorBadge, (event) => {
this.#updateOption("donatorBadge", event.target.value, settingsUi);
});
donatorInput.setAttribute("maxlength", 24);
container.append(donatorHeader, donatorInput);
if (
this.#layout.donatorBadge !== this.#anilistSettings.donatorBadge &&
this.#layout.donatorBadge !== "" &&
this.#settings.auth?.token
) {
const publishButton = Button("Publish Donator Badge", (event) => {
this.#publishDonatorText(event, settingsUi);
});
container.append(DOM.create("div", null, publishButton));
}
return container;
}
#createColorSelection(settingsUi) {
const container = DOM.create("div", "layout-color-selection");
const header = DOM.create("h5", "layout-header", "Color");
container.append(header);
for (const anilistColor of ColorFunctions.defaultColors) {
container.append(this.#createColorButton(anilistColor, settingsUi));
}
if (this.#donatorTier >= 2) {
const isDefaultColor = ColorFunctions.defaultColors.some(
(color) => color === this.#layout.color
);
const colorInput = ColorPicker(
isDefaultColor ? "" : this.#layout.color,
(event) => {
this.#updateOption("color", event.target.value, settingsUi);
}
);
if (!isDefaultColor && this.#layout.color !== "") {
colorInput.classList.add("active");
}
container.append(colorInput);
}
if (
this.#settings.auth?.token &&
this.#layout.color.toLocaleLowerCase() !==
this.#anilistSettings?.options?.profileColor?.toLocaleLowerCase() &&
this.#layout.color !== ""
) {
const publishButton = Button("Publish Color", (event) => {
this.#publishColor(event, settingsUi);
});
container.append(DOM.create("div", null, publishButton));
}
return container;
}
#createAboutSection(settingsUi) {
const container = DOM.create("div");
const aboutHeader = DOM.create("h5", "layout-header", "About");
const aboutInput = TextArea(this.#layout.bio, (event) => {
this.#updateOption("bio", event.target.value, settingsUi);
});
const note = Note(
"Please note that VoidVerified does not have access to AniList's markdown parser. AniList specific features might not be available while previewing. Recommended to be used for smaller changes like previewing a different image for a layout."
);
container.append(aboutHeader, aboutInput, note);
return container;
}
async #publishAbout(event, settingsUi) {
const button = event.target;
button.innerText = "Publishing...";
try {
const anilistAPI = new AnilistAPI(this.#settings);
let currentAbout = await anilistAPI.getUserAbout(
this.#settings.anilistUser
);
if (!currentAbout) {
currentAbout = "";
}
const about = this.#transformAbout(currentAbout, this.#layout.bio);
await anilistAPI.saveUserAbout(about);
Toaster.success("About published.");
settingsUi.renderSettingsUiContent();
} catch (error) {
console.error(error);
Toaster.error("Failed to publish about.");
}
}
#transformAbout(currentAbout, newAbout) {
const json = currentAbout.match(/^\[\]\(json([A-Za-z0-9+/=]+)\)/)?.[1];
if (!json) {
return newAbout;
}
const about = `[](json${json})` + newAbout;
return about;
}
async #publishColor(event, settingsUi) {
const button = event.target;
const color = this.#layout.color;
button.innerText = "Publishing...";
try {
const anilistAPI = new AnilistAPI(this.#settings);
const result = await anilistAPI.saveUserColor(color);
const profileColor = result.UpdateUser?.options?.profileColor;
this.#anilistSettings.options.profileColor = profileColor;
Toaster.success("Color published.");
} catch (error) {
Toaster.error("Failed to publish color.");
console.error("Failed to publish color.", error);
} finally {
settingsUi.renderSettingsUiContent();
}
}
async #publishDonatorText(event, settingsUi) {
const button = event.target;
const donatorText = this.#layout.donatorBadge;
button.innerText = "Publishing...";
try {
const anilistAPI = new AnilistAPI(this.#settings);
const result = await anilistAPI.saveDonatorBadge(donatorText);
const donatorBadge = result.UpdateUser?.donatorBadge;
this.#anilistSettings.donatorBadge = donatorBadge;
Toaster.success("Donator badge published.");
} catch (error) {
Toaster.error("Failed to publish donator badge.");
console.error("Failed to publish donator badge.", error);
} finally {
settingsUi.renderSettingsUiContent();
}
}
async #getUserAbout(settingsUi) {
if (
this.#layout.bio !== "" &&
!window.confirm(
"Are you sure you want to reset about? Any changes will be lost."
)
) {
return;
}
try {
Toaster.debug("Querying user about.");
const anilistAPI = new AnilistAPI(this.#settings);
const about = await anilistAPI.getUserAbout(
this.#settings.anilistUser
);
const clearedAbout = this.#removeJson(about);
this.#updateOption("bio", clearedAbout, settingsUi);
Toaster.success("About reset.");
} catch (error) {
Toaster.error("Failed to query current about from AniList API.");
}
}
#removeJson(about) {
return about.replace(/^\[\]\(json([A-Za-z0-9+/=]+)\)/, "");
}
#createColorButton(anilistColor, settingsUi) {
const button = DOM.create("div", "color-button");
button.style.backgroundColor = `rgb(${ColorFunctions.handleAnilistColor(
anilistColor
)})`;
button.addEventListener("click", () => {
this.#updateOption("color", anilistColor, settingsUi);
});
if (this.#layout.color === anilistColor) {
button.classList.add("active");
}
return button;
}
#updateOption(field, value, settingsUi) {
this.#layout[field] = value;
this.#updateLayout(this.#layout);
settingsUi.renderSettingsUiContent();
}
#togglePreview(settingsUi) {
this.#layouts.preview = !this.#layouts.preview;
if (!this.#layouts.preview) {
this.#layouts.disableCss = false;
}
this.#broadcastChannel.postMessage({
type: "preview",
preview: this.#layouts.preview,
});
this.#saveToLocalStorage();
settingsUi.renderSettingsUiContent();
}
#toggleCss() {
this.#layouts.disableCss = !this.#layouts.disableCss;
this.#broadcastChannel.postMessage({
type: "css",
disableCss: this.#layouts.disableCss,
});
this.#saveToLocalStorage();
}
#getSelectedLayout() {
return this.#layouts.layoutsList[this.#layouts.selectedLayout];
}
#updateLayout(layout) {
this.#layouts.layoutsList[this.#layouts.selectedLayout] = layout;
this.#saveToLocalStorage();
this.#broadcastLayoutChange();
}
#broadcastLayoutChange() {
this.#broadcastChannel.postMessage({
type: "layout",
layout: this.#layout,
});
}
#saveToLocalStorage() {
localStorage.setItem(
this.#layoutsInLocalStorage,
JSON.stringify(this.#layouts)
);
}
}
const ImageFormats = [
"jpg",
"png",
"gif",
"webp",
"apng",
"avif",
"jpeg",
"svg",
];
const keyboardTabs = {
gifs: "GIFS",
images: "Images",
};
class GifKeyboardConfig {
gifs;
gifSize;
images;
#configInLocalStorage = "void-verified-gif-keyboard";
constructor() {
const config = JSON.parse(
localStorage.getItem(this.#configInLocalStorage)
);
this.gifs = config?.gifs ?? [];
this.images = config?.images ?? [];
this.gifSize = config?.gifSize ?? 260;
}
save() {
localStorage.setItem(
"void-verified-gif-keyboard",
JSON.stringify(this)
);
}
}
class GifKeyboardHandler {
#settings;
#activeTab = keyboardTabs.gifs;
#paginationPage = 0;
#pageSize = 30;
config;
constructor(settings) {
this.#settings = settings;
this.config = new GifKeyboardConfig();
}
handleGifKeyboard() {
this.#addGifKeyboards();
this.#addMediaLikeButtons();
}
#addMediaLikeButtons() {
if (!this.#settings.options.gifKeyboardEnabled.getValue()) {
return;
}
const gifs = DOM.getAll(".markdown img[src$='.gif']");
for (const gif of gifs) {
this.#addMediaLikeButton(gif, keyboardTabs.gifs, this.config.gifs);
}
const images = ImageFormats.map((format) => {
return [...DOM.getAll(`.markdown img[src$='.${format}']`)];
}).flat(1);
for (const image of images) {
this.#addMediaLikeButton(
image,
keyboardTabs.images,
this.config.images
);
}
}
#addMediaLikeButton(media, mediaType, mediaList) {
if (media.parentElement.classList.contains("void-gif-like-container")) {
return;
}
const img = media.cloneNode();
media.replaceWith(
GifContainer(
img,
() => {
this.#addOrRemoveMedia(media.src, mediaType);
this.config.save();
this.#refreshKeyboards();
},
mediaList
)
);
}
#addGifKeyboards() {
if (!this.#settings.options.gifKeyboardEnabled.getValue()) {
return;
}
const markdownEditors = DOM.getAll(".markdown-editor");
for (const markdownEditor of markdownEditors) {
if (markdownEditor.querySelector(".void-gif-button")) {
continue;
}
const gifKeyboard = GifKeyboard(this.#createKeyboardHeader());
// gifKeyboard
// .querySelector(".void-gif-keyboard-list-container")
// .insertBefore(
// this.#createMediaAddField(gifKeyboard, markdownEditor),
// gifKeyboard.querySelector(".void-gif-keyboard-list")
// );
gifKeyboard.classList.add("void-hidden");
this.#renderMediaList(gifKeyboard, markdownEditor);
this.#renderControls(gifKeyboard, markdownEditor);
markdownEditor.append(
IconButton(
GifIcon(),
() => {
this.#toggleKeyboardVisibility(
gifKeyboard,
markdownEditor
);
},
"gif-button"
)
);
markdownEditor.parentNode.insertBefore(
gifKeyboard,
markdownEditor.nextSibling
);
}
}
#refreshKeyboards() {
const keyboards = DOM.getAll(".void-gif-keyboard-container");
for (const keyboard of keyboards) {
const markdownEditor =
keyboard.parentElement.querySelector(".markdown-editor");
this.#renderMediaList(keyboard, markdownEditor);
this.#renderControls(keyboard, markdownEditor);
}
}
#createKeyboardHeader = () => {
const header = DOM.create("div", "gif-keyboard-header");
const options = Object.values(keyboardTabs).map((option) =>
Option$1(option, option === this.#activeTab, (event) => {
this.#activeTab = option;
const keyboard =
event.target.parentElement.parentElement.parentElement; // oh god
const markdownEditor =
keyboard.parentElement.querySelector(".markdown-editor");
this.#renderMediaList(keyboard, markdownEditor);
event.target.parentElement.parentElement.replaceWith(
this.#createKeyboardHeader()
);
})
);
header.append(Select(options));
header.append(
RangeField(
this.config.gifSize,
(event) => {
this.config.gifSize = event.target.value;
this.config.save();
},
600,
10,
10
)
);
return header;
};
#addOrRemoveMedia(url, mediaType) {
let mediaList =
mediaType === keyboardTabs.gifs
? this.config.gifs
: this.config.images;
if (mediaList.includes(url)) {
mediaList = mediaList.filter((media) => media !== url);
} else {
mediaList.push(url);
}
switch (mediaType) {
case keyboardTabs.gifs:
this.config.gifs = mediaList;
break;
case keyboardTabs.images:
this.config.images = mediaList;
break;
}
}
#toggleKeyboardVisibility(keyboard, markdownEditor) {
if (keyboard.classList.contains("void-hidden")) {
this.#renderMediaList(keyboard, markdownEditor);
keyboard.classList.remove("void-hidden");
} else {
keyboard.classList.add("void-hidden");
}
}
#renderMediaList(keyboard, markdownEditor) {
if (!keyboard || !markdownEditor) {
return;
}
const mediaItems = keyboard.querySelector(".void-gif-keyboard-list");
const columns = [1, 2, 3].map(() => {
return DOM.create("div", "gif-keyboard-list-column");
});
mediaItems.replaceChildren(...columns);
const textarea = markdownEditor.parentElement.querySelector("textarea");
const mediaList =
this.#activeTab === keyboardTabs.gifs
? this.config.gifs
: this.config.images;
if (mediaList.length === 0) {
mediaItems.replaceChildren(
DOM.create(
"div",
"gif-keyboard-list-placeholder",
this.#activeTab === keyboardTabs.gifs
? "It's pronounced GIF."
: "You have no funny memes :c"
)
);
}
for (const [index, media] of mediaList
.slice(
this.#paginationPage * this.#pageSize,
this.#paginationPage * this.#pageSize + this.#pageSize
)
.entries()) {
mediaItems.children.item(index % 3).append(
GifItem(
media,
() => {
textarea.setRangeText(
`img${this.config.gifSize}(${media})`
);
},
() => {
this.#addOrRemoveMedia(media, this.#activeTab);
this.config.save();
},
mediaList
)
);
}
}
#renderControls(keyboard, markdownEditor) {
const container = keyboard.querySelector(
".void-gif-keyboard-control-container"
);
const mediaField = this.#createMediaAddField(keyboard, markdownEditor);
const pagination = this.#createPagination(keyboard, markdownEditor);
container.replaceChildren(mediaField, pagination);
}
#createMediaAddField(keyboard, markdownEditor) {
const actionfield = ActionInputField(
"",
(_, inputField) => {
this.#handleAddMediaField(inputField, keyboard, markdownEditor);
},
AddIcon()
);
actionfield
.querySelector("input")
.setAttribute("placeholder", "Add media...");
return actionfield;
}
#handleAddMediaField(inputField, keyboard, markdownEditor) {
const url = inputField.value;
inputField.value = "";
let format;
if (url.toLowerCase().endsWith(".gif")) {
format = keyboardTabs.gifs;
} else if (
ImageFormats.some((imgFormat) =>
url.toLowerCase().endsWith(imgFormat.toLocaleLowerCase())
)
) {
format = keyboardTabs.images;
}
if (!format) {
Toaster.error("Url was not recognized as image or GIF.");
return;
}
Toaster.success(`Added media to ${format}`);
this.#addOrRemoveMedia(url, format);
this.config.save();
this.#renderMediaList(keyboard, markdownEditor);
}
#createPagination(keyboard, markdownEditor) {
const container = DOM.create(
"div",
"gif-keyboard-pagination-container"
);
const mediaList =
this.#activeTab === keyboardTabs.gifs
? this.config.gifs
: this.config.images;
const maxPages = Math.ceil(mediaList.length / this.#pageSize) - 1;
container.append(
Pagination(this.#paginationPage, maxPages, (page) => {
this.#paginationPage = page;
this.#refreshKeyboards(keyboard, markdownEditor);
})
);
return container;
}
}
class IntervalScriptHandler {
styleHandler;
settingsUi;
activityHandler;
settings;
globalCSS;
quickAccess;
userCSS;
layoutDesigner;
gifKeyboard;
constructor(settings) {
this.settings = settings;
this.styleHandler = new StyleHandler(settings);
this.globalCSS = new GlobalCSS(settings);
this.userCSS = new UserCSS(settings);
this.layoutDesigner = new LayoutDesigner(settings);
this.gifKeyboard = new GifKeyboardHandler(settings);
this.settingsUi = new SettingsUserInterface(
settings,
this.styleHandler,
this.globalCSS,
this.userCSS,
this.layoutDesigner
);
this.activityHandler = new ActivityHandler(settings);
this.quickAccess = new QuickAccess(settings);
}
currentPath = "";
evaluationIntervalInSeconds = 1;
hasPathChanged(path) {
if (path === this.currentPath) {
return false;
}
this.currentPath = path;
return true;
}
handleIntervalScripts(intervalScriptHandler) {
const path = window.location.pathname;
intervalScriptHandler.activityHandler.moveAndDisplaySubscribeButton();
intervalScriptHandler.activityHandler.removeBlankFromAnilistLinks();
intervalScriptHandler.gifKeyboard.handleGifKeyboard();
intervalScriptHandler.globalCSS.clearCssForProfile();
intervalScriptHandler.layoutDesigner.renderLayoutPreview();
if (path === "/home") {
intervalScriptHandler.styleHandler.refreshHomePage();
intervalScriptHandler.quickAccess.renderQuickAccess();
}
if (!path.startsWith("/settings/developer")) {
intervalScriptHandler.settingsUi.removeSettingsUi();
}
if (!intervalScriptHandler.hasPathChanged(path)) {
return;
}
if (path.startsWith("/user/")) {
intervalScriptHandler.userCSS.checkUserCss();
intervalScriptHandler.quickAccess.clearBadge();
intervalScriptHandler.styleHandler.verifyProfile();
} else {
intervalScriptHandler.styleHandler.clearStyles("profile");
}
if (path.startsWith("/activity/")) {
intervalScriptHandler.userCSS.checkActivityCss();
}
if (!path.startsWith("/activity/") && !path.startsWith("/user/")) {
intervalScriptHandler.userCSS.resetCurrentActivity();
intervalScriptHandler.userCSS.resetCurrentUser();
intervalScriptHandler.styleHandler.clearStyles("user-css");
}
intervalScriptHandler.globalCSS.createCss();
if (path.startsWith("/settings/developer")) {
intervalScriptHandler.settingsUi.renderSettingsUi();
}
}
enableScriptIntervalHandling() {
const interval = setInterval(() => {
try {
this.handleIntervalScripts(this);
} catch (error) {
Toaster.critical([
"A critical error has occured running interval script loop. VoidVerified is not working correctly. Please check developer console and contact ",
Link(
"voidnyan",
"https://anilist.co/user/voidnyan/",
"_blank"
),
".",
]);
clearInterval(interval);
console.error(error);
}
}, this.evaluationIntervalInSeconds * 1000);
}
}
class PasteHandler {
settings;
#uploadInProgress = false;
constructor(settings) {
this.settings = settings;
}
setup() {
window.addEventListener("paste", (event) => {
this.#handlePaste(event);
});
}
async #handlePaste(event) {
if (
event.target.tagName !== "TEXTAREA" &&
event.target.tagName !== "INPUT"
) {
return;
}
const clipboard = event.clipboardData.getData("text/plain").trim();
let result = [];
const file = event.clipboardData.items[0]?.getAsFile();
if (file && this.settings.options.pasteImagesToHostService.getValue()) {
event.preventDefault();
result = await this.#handleImages(event);
} else if (this.settings.options.pasteEnabled.getValue()) {
event.preventDefault();
const rows = clipboard.split("\n");
for (let row of rows) {
result.push(this.#handleRow(row, event));
}
} else {
return;
}
const transformedClipboard = result.join("\n\n");
window.document.execCommand("insertText", false, transformedClipboard);
}
async #handleImages(event) {
const _files = event.clipboardData.items;
if (this.#uploadInProgress) {
return;
}
this.#uploadInProgress = true;
document.body.classList.add("void-upload-in-progress");
const imageApi = new ImageApiFactory().getImageHostInstance();
const files = Object.values(_files).map((file) => file.getAsFile());
const images = files.filter((file) => file.type.startsWith("image/"));
try {
const results = await Promise.all(
images.map((image) => imageApi.uploadImage(image))
);
return results
.filter((url) => url !== null)
.map((url) => this.#handleRow(url, event));
} catch (error) {
console.error(error);
return [];
} finally {
this.#uploadInProgress = false;
document.body.classList.remove("void-upload-in-progress");
}
}
#handleRow(row, event) {
if (
event.target.parentElement.classList.contains("void-css-editor") ||
event.target.tagName === "INPUT"
) {
return row;
}
row = row.trim();
if (ImageFormats.some((format) => row.toLowerCase().endsWith(format))) {
return this.#handleImg(row);
} else if (row.toLowerCase().startsWith("http")) {
return `[](${row})`;
} else {
return row;
}
}
#handleImg(row) {
const img = `img${this.settings.options.pasteImageWidth.getValue()}(${row})`;
let result = img;
if (this.settings.options.pasteWrapImagesWithLink.getValue()) {
result = `[ ${img} ](${row})`;
}
return result;
}
}
const styles = /* css */ `
:root {
--void-info: 46, 149, 179;
--void-error: 188, 53, 46;
--void-success: 80, 162, 80;
--void-warning: 232, 180, 2;
}
a[href="/settings/developer" i]::after{content: " & Void"}
.void-settings .void-nav ol {
display: flex;
margin: 8px 0px;
padding: 0;
}
.void-nav {
margin-top: 3rem;
}
.void-settings .void-nav li {
list-style: none;
display: block;
color: rgb(var(--color-text));
padding: 4px 8px;
text-transform: capitalize;
background: rgb(var(--color-foreground-blue));
cursor: pointer;
min-width: 50px;
text-align: center;
font-size: 1.4rem;
}
.void-settings .void-nav li.void-active,
.void-settings .void-nav li:hover {
background: rgb(var(--color-blue));
color: rgb(var(--color-text-bright));
}
.void-settings .void-nav li:first-child {
border-radius: 4px 0px 0px 4px;
}
.void-settings .void-nav li:last-child {
border-radius: 0px 4px 4px 0px;
}
.void-settings .void-settings-header {
margin-top: 30px;
}
.void-settings .void-table table {
border-collapse: collapse;
}
.void-settings .void-table :is(th, td) {
padding: 2px 6px !important;
}
.void-settings .void-table :is(th, td):first-child {
border-radius: 4px 0px 0px 4px;
}
.void-settings .void-table :is(th, td):last-child {
border-radius: 0px 4px 4px 0px;
}
.void-settings .void-table tbody tr:hover {
background-color: rgba(var(--color-foreground-blue), .7);
}
.void-settings .void-table input[type="color"] {
border: 0;
height: 24px;
width: 40px;
padding: 0;
background-color: unset;
cursor: pointer;
}
.void-settings .void-table button {
background: unset;
border: none;
cursor: pointer;
padding: 0;
}
.void-settings .void-table form {
padding: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.void-settings .void-settings-header span {
color: rgb(var(--color-blue));
}
.void-settings .void-settings-list {
display: flex;
flex-direction: column;
gap: 5px;
}
.void-setting-label {
margin-left: 6px;
vertical-align: middle;
cursor: pointer;
}
.void-setting-label-container .void-checkbox {
vertical-align: middle;
}
.void-checkbox {
cursor: pointer;
}
.void-settings .void-settings-list input.void-input {
width: 50px;
text-align: center;
height: 20px;
font-size: 12px;
}
.void-settings .void-settings-list label {
margin-left: 8px;
}
.void-settings .void-css-editor label {
margin-top: 20px;
fontSize: 2rem;
display: inline-block;
}
.void-textarea {
width: 100%;
height: 300px;
min-height: 200px;
resize: vertical;
background: rgb(var(--color-foreground-blue));
color: rgb(var(--color-text));
padding: 4px;
border-radius: 4px;
border: 2px solid transparent;
outline: none !important;
}
.void-textarea:focus {
border: 2px solid rgb(var(--color-blue)) !important;
}
.void-layout-image-container {
padding: 4px;
display: inline-block;
}
.void-layout-image-container:first-child {
width: 35%;
}
.void-layout-image-container:last-child {
width: 65%;
}
.void-layout-header {
text-transform: uppercase;
margin-top: 2.2em;
margin-bottom: .8em;
}
.void-layout-image-display {
height: 140px;
background-repeat: no-repeat;
margin: auto;
margin-bottom: 6px;
border-radius: 4px;
}
.void-layout-image-display.void-banner {
width: 100%;
background-size: cover;
background-position: 50% 50%;
background-size:
}
.void-layout-image-display.void-avatar {
background-size: contain;
width: 140px;
}
.void-layout-image-container input {
width: 100%;
}
.void-layout-color-selection {
margin-top: 10px;
margin-bottom: 10px;
}
.void-layout-color-selection .void-color-button {
width: 50px;
height: 50px;
display: inline-flex;
border-radius: 4px;
margin-right: 10px;
}
.void-layout-color-selection .void-color-button.active {
border: 4px solid rgb(var(--color-text));
}
.void-layout-color-selection .void-color-picker-container.active {
border: 2px solid rgb(var(--color-text));
}
.void-color-picker-container {
display: inline-block;
vertical-align: top;
width: 75px;
height: 50px;
border: 2px solid transparent;
border-radius: 4px;
box-sizing: border-box;
}
.void-color-picker-container:has(:focus) {
border: 2px solid rgb(var(--color-text));
}
.void-color-picker-input {
width: 100%;
height: 20px;
background-color: rgba(var(--color-background), .6);
padding: 1px;
font-size: 11px;
color: rgb(var(--color-text));
outline: none;
appearance: none;
-webkit-appearance: none;
text-align: center;
border: unset;
border-radius: 0px 0px 4px 4px;
}
.void-color-picker {
/* width: 100%;;
height: 50px; */
block-size: 30px;
border-width: 0px;
padding: 0px;
background-color: unset;
inline-size: 100%;
border-radius: 4px;
appearance: none;
vertical-align: top;
padding-block: 0px;
padding-inline: 0px;
outline: none;
}
.void-color-picker::-webkit-color-swatch,
.void-color-picker::-moz-color-swatch {
border: none;
border-radius: 4px;
}
.void-color-picker::-webkit-color-swatch-wrapper,
.void-color-picker::-webkit-color-swatch-wrapper {
padding: 0px;
border-radius: 4px;
}
.void-input {
background-color: rgba(var(--color-background), .6);
padding: 4px 6px;
color: rgb(var(--color-text));
outline: none;
appearance: none;
-webkit-appearance: none;
border: 2px solid transparent;
border-radius: 4px;
box-sizing: border-box;
}
.void-action-container {
display: inline-block;
width: fit-content;
}
.void-action-container .void-icon-button {
padding: 6px 8px;
margin: 0px;
background: rgb(var(--color-foreground-blue-dark));
color: rgb(var(--color-text));
border-radius: 0px 4px 4px 0px;
height: 100%;
display: inline-flex;
flex-direction: column;
justify-content: center;
border: 2px solid transparent;
border-left: 0px !important;
line-height: 1.15;
box-sizing: border-box;
vertical-align: top;
}
.void-action-container .void-icon-button:hover {
color: rgb(var(--color-blue));
}
.void-action-container .void-icon-button svg {
height: 14px;
}
.void-action-container .void-input {
border-radius: 4px 0px 0px 4px;
}
a.void-link {
color: rgb(var(--color-blue)) !important;
}
.void-input.void-sign {
width: 75px;
text-align: center;
height: 20px;
font-size: 14px;
}
.void-input:focus {
border: 2px solid rgb(var(--color-blue));
}
.void-button {
align-items: center;
background: rgb(var(--color-blue));
border-radius: 4px;
color: rgb(var(--color-text-bright));
cursor: pointer;
display: inline-flex;
font-size: 1.3rem;
padding: 10px 15px;
outline: none;
appearance: none;
-webkit-appearance: none;
border: 0px solid rgb(var(--color-background));
vertical-align: top;
margin-top: 15px;
margin-right: 10px;
}
.void-icon-button {
display: inline-block;
cursor: pointer;
margin-left: 4px;
margin-right: 4px;
vertical-align: middle;
}
.void-icon-button svg {
height: 12px;
vertical-align: middle;
display: inline-block;
pointer-events: none;
}
.void-range-container {
display: inline-flex;
}
.void-range-display {
margin-left: 5px;
user-select: none;
font-size: 14px;
font-weight: bold;
display: inline-flex;
justify-content: center;
align-items: center;
min-width: 25px;
}
.void-gif-button svg {
height: 18px;
vertical-align: top;
color: rgb(var(--color-red));
}
.void-gif-button:hover svg {
color: rgb(var(--color-blue));
}
.void-gif-button {
margin: 0px;
}
.markdown-editor[style*="display: none;"] + .void-gif-keyboard-container {
display: none;
}
.void-gif-keyboard-container {
width: 100%;
background: rgb(var(--color-foreground));
margin-bottom: 12px;
border-radius: 4px;
}
.void-gif-keyboard-header {
background: rgb(var(--color-foreground-grey-dark));
padding: 12px 20px;
border-radius: 4px 4px 0px 0px;
display: flex;
justify-content: space-between;
}
.void-gif-keyboard-control-container {
display: flex;
justify-content: space-between;
padding: 12px 12px 0px 12px;
}
.void-gif-keyboard-list-container {
height: 300px;
overflow-y: scroll;
user-select: none;
}
.void-gif-keyboard-list {
padding: 12px 20px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 8px;
}
.void-gif-keyboard-list-column {
width: calc(100% / 3);
display: flex;
flex-direction: column;
gap: 8px;
}
.void-gif-keyboard-list-placeholder {
font-size: 20px;
color: rgb(var(--color-text));
display: flex;
height: 220px;
width: 100%;
justify-content: center;
align-items: center;
user-select: none;
}
.void-gif-keyboard-item img {
width: 100%;
background-size: contain;
background-repeat: no-repeat;
border-radius: 4px;
cursor: pointer;
display: block;
}
.void-gif-like-container {
position: relative;
width: fit-content;
}
.void-gif-like-container .void-gif-like {
position: absolute;
top: 6px;
right: 6px;
height: 20px;
opacity: 0;
transition: 0.2s ease-in all;
color: rgb(var(--color-text-bright));
}
.void-gif-like-container:hover .void-gif-like {
opacity: 1;
}
.void-gif-like-container .void-gif-like svg {
height: 24px;
}
.void-gif-like-container .void-gif-like.void-liked,
.void-liked {
color: rgb(var(--color-red));
}
.void-hidden {
display: none;
}
.void-pagination-container .void-icon-button.void-active,
.void-pagination-container .void-icon-button:hover {
color: rgb(var(--color-blue));
}
.void-pagination-container .void-icon-button.void-pagination-skip {
vertical-align: top;
}
.void-quick-access .void-quick-access-wrap {
background: rgb(var(--color-foreground));
display: grid;
grid-template-columns: repeat(auto-fill, 60px);
grid-template-rows: repeat(auto-fill, 80px);
gap: 15px;
padding: 15px;
margin-bottom: 25px;
}
.void-quick-access .section-header {
display: flex;
justify-content: space-between;
}
.void-quick-access-timer {
font-size: 12px;
color: rgb(var(--color-text));
}
.void-quick-access-item {
display: inline-block;
}
.void-quick-access-pfp {
background-size: contain;
background-repeat: no-repeat;
height: 60px;
width: 60px;
border-radius: 4px;
}
.void-quick-access-username {
display: inline-block;
text-align: center;
bottom: -20px;
width: 100%;
word-break: break-all;
font-size: 1.2rem;
}
.void-quick-access-badge {
position: relative;
}
.void-quick-access-badge::after {
content: "New";
background: rgb(var(--color-blue));
border-radius: 10px;
padding: 2px 4px;
font-size: 9px;
position: absolute;
top: 2px;
right: -10px;
color: white;
}
.void-notice {
font-size: 11px;
margin-top: 5px;
}
.void-select {
display: inline-flex;
flex-wrap: wrap;
}
.void-select .void-option {
padding: 3px 8px;
background: rgb(var(--color-foreground-blue));
font-size: 12px;
cursor: pointer;
user-select: none;
}
.void-select .void-option:hover {
background: rgb(var(--color-foreground-blue-dark));
color: rgb(var(--color-text));
}
.void-select .void-option:first-child {
border-radius: 4px 0px 0px 4px;
}
.void-select .void-option:last-child {
border-radius: 0px 4px 4px 0px;
}
.void-select .void-option.active {
background: rgb(var(--color-blue));
color: rgb(var(--color-text-bright));
}
.void-label-container {
margin-top: 6px;
margin-bottom: 6px;
}
.void-label-span {
margin-right: 10px;
min-width: 200px;
display: inline-block;
}
.void-upload-in-progress {
cursor: wait !important;
}
#void-toast-container {
position: fixed;
display: flex;
flex-direction: column;
gap: 10px;
}
#void-toast-container.void-bottom-left {
bottom: 10px;
left: 10px;
flex-direction: column-reverse;
}
#void-toast-container.void-bottom-right {
bottom: 10px;
right: 10px;
flex-direction: column-reverse;
}
#void-toast-container.void-top-left {
top: 70px;
left: 10px;
}
#void-toast-container.void-top-right {
top: 70px;
right: 10px;
}
.void-toast {
font-size: 14px;
color: rgb(var(--color-text-bright));
min-width: 150px;
max-width: 300px;
min-heigth: 50px;
padding: 10px 8px;
border-radius: 4px;
}
.void-info {
background: rgb(var(--void-info));
}
.void-success {
background: rgb(var(--void-success));
}
.void-error {
background: rgb(var(--void-error));
}
.void-warning {
background: rgb(var(--void-warning));
}
.
`;
const settings = new Settings();
Toaster.initializeToaster(settings);
const styleHandler = new StyleHandler(settings);
styleHandler.refreshStyles();
try {
const intervalScriptHandler = new IntervalScriptHandler(settings);
intervalScriptHandler.enableScriptIntervalHandling();
} catch (error) {
Toaster.critical(
"A critical error has occured setting up intervalScriptHandler. Please check developer console and contact voidnyan."
);
console.error(error);
}
try {
const pasteHandler = new PasteHandler(settings);
pasteHandler.setup();
} catch (error) {
Toaster.critical(
"A critical error has occured setting up pasteHandler. Please check developer console and contact voidnyan."
);
}
styleHandler.createStyleLink(styles, "script");
new ImgurAPI(
new ImageHostService().getImageHostConfiguration(imageHosts.imgur)
).refreshAuthToken();
console.log(`VoidVerified ${settings.version} loaded.`);
})();