Merge branch 'main' into improved-context-menu
This commit is contained in:
commit
ecfa85c0ac
55 changed files with 1030 additions and 297 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { NitroFetchRequest, NitroFetchOptions } from "nitropack";
|
||||
import type { NitroFetchOptions } from "nitropack";
|
||||
|
||||
export default async <T>(path: string, options: NitroFetchOptions<string> = {}) => {
|
||||
console.log("path received:", path);
|
||||
|
|
38
utils/generateDefaultIcon.ts
Normal file
38
utils/generateDefaultIcon.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
export default (name: string, seed: string): string => {
|
||||
const canvas = document.createElement("canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (canvas && ctx) {
|
||||
canvas.width = 256;
|
||||
canvas.height = 256;
|
||||
|
||||
// get the first char from every word in the guild name
|
||||
let previewName = "";
|
||||
if (name.length > 3) {
|
||||
let guildName: string[] = name.split(' ')
|
||||
for (let i = 0; i < 3; i ++) {
|
||||
if (guildName.length > i) {
|
||||
previewName += guildName[i].charAt(0)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
previewName = name
|
||||
}
|
||||
|
||||
// fill background using seeded colour
|
||||
ctx.fillStyle = generateIrcColor(seed, 50)
|
||||
ctx.fillRect(0, 0, 256, 256)
|
||||
|
||||
ctx.fillStyle = 'white'
|
||||
ctx.textAlign = 'center'
|
||||
ctx.textBaseline = 'middle'
|
||||
ctx.font = `bold 96px Arial, Helvetica, sans-serif`
|
||||
// 136 isn't actually centered, but it *looks* centered
|
||||
ctx.fillText(previewName, 128, 136)
|
||||
|
||||
return canvas.toDataURL("image/png");
|
||||
}
|
||||
|
||||
return "https://tenor.com/view/dame-da-ne-guy-kiryukazuma-kiryu-yakuza-yakuza-0-gif-14355451116903905918"
|
||||
}
|
13
utils/generateIrcColor.ts
Normal file
13
utils/generateIrcColor.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import xxhash from "xxhash-wasm"
|
||||
|
||||
let h64: CallableFunction;
|
||||
(async () => {
|
||||
h64 = (await xxhash()).h64;
|
||||
})();
|
||||
|
||||
export default (seed: string, saturation: number = 100, lightness: number = 50): string => {
|
||||
const idHash = useState(`h64Hash-${seed}`, () => h64(seed))
|
||||
const hashValue: bigint = idHash.value
|
||||
|
||||
return `hsl(${hashValue % 360n}, ${saturation}%, ${lightness}%)`
|
||||
}
|
7
utils/getDisplayName.ts
Normal file
7
utils/getDisplayName.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { GuildMemberResponse, UserResponse } from "~/types/interfaces";
|
||||
|
||||
export default (user: UserResponse, member?: GuildMemberResponse): string => {
|
||||
if (member?.nickname) return member.nickname
|
||||
if (user.display_name) return user.display_name
|
||||
return user.username
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
export async function hashPassword(password: string) {
|
||||
export default async (password: string) => {
|
||||
const encodedPass = new TextEncoder().encode(password);
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-384", encodedPass);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
50
utils/isCanvasBlocked.ts
Normal file
50
utils/isCanvasBlocked.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// Canvas Blocker &
|
||||
// Firefox privacy.resistFingerprinting Detector.
|
||||
// (c) 2018 // JOHN OZBAY // CRYPT.EE
|
||||
// MIT License
|
||||
//
|
||||
export default () => {
|
||||
// create a 1px image data
|
||||
var blocked = false;
|
||||
var canvas = document.createElement("canvas");
|
||||
var ctx = canvas.getContext("2d");
|
||||
|
||||
// some blockers just return an undefined ctx. So let's check that first.
|
||||
if (ctx) {
|
||||
var imageData = ctx.createImageData(1,1);
|
||||
var originalImageData = imageData.data;
|
||||
|
||||
// set pixels to RGB 128
|
||||
originalImageData[0]=128;
|
||||
originalImageData[1]=128;
|
||||
originalImageData[2]=128;
|
||||
originalImageData[3]=255;
|
||||
|
||||
// set this to canvas
|
||||
ctx.putImageData(imageData,1,1);
|
||||
|
||||
try {
|
||||
// now get the data back from canvas.
|
||||
var checkData = ctx.getImageData(1, 1, 1, 1).data;
|
||||
|
||||
// If this is firefox, and privacy.resistFingerprinting is enabled,
|
||||
// OR a browser extension blocking the canvas,
|
||||
// This will return RGB all white (255,255,255) instead of the (128,128,128) we put.
|
||||
|
||||
// so let's check the R and G to see if they're 255 or 128 (matching what we've initially set)
|
||||
if (originalImageData[0] !== checkData[0] && originalImageData[1] !== checkData[1]) {
|
||||
blocked = true;
|
||||
console.log("Canvas is blocked. Will display warning.");
|
||||
}
|
||||
} catch (error) {
|
||||
// some extensions will return getImageData null. this is to account for that.
|
||||
blocked = true;
|
||||
console.log("Canvas is blocked. Will display warning.");
|
||||
}
|
||||
} else {
|
||||
blocked = true;
|
||||
console.log("Canvas is blocked. Will display warning.");
|
||||
}
|
||||
return blocked;
|
||||
}
|
28
utils/loadPreferredTheme.ts
Normal file
28
utils/loadPreferredTheme.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
let themeLinkElement: HTMLLinkElement | null;
|
||||
|
||||
export default function loadPreferredTheme() {
|
||||
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
|
||||
|
||||
if (themeLinkElement) {
|
||||
themeLinkElement.href = getThemeUrl(currentTheme);
|
||||
} else {
|
||||
// create the theme link if one doesn't already exist
|
||||
useHead({
|
||||
link: [{
|
||||
id: "main-theme",
|
||||
rel: "stylesheet",
|
||||
href: getThemeUrl(currentTheme)
|
||||
}]
|
||||
})
|
||||
|
||||
themeLinkElement = document.getElementById('main-theme') as HTMLLinkElement;
|
||||
}
|
||||
}
|
||||
|
||||
function getThemeUrl(id: string): string {
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const baseURL = runtimeConfig.app.baseURL;
|
||||
|
||||
// this should preferrably use version hash, but that's not implemented yet
|
||||
return `${baseURL}themes/${id}.css?v=${runtimeConfig.public.buildTimeString}`
|
||||
}
|
|
@ -7,7 +7,7 @@ export default (element: HTMLDivElement, props: MessageProps) => {
|
|||
const messageBox = document.getElementById("message-box") as HTMLDivElement;
|
||||
if (messageBox) {
|
||||
const div = document.createElement("div");
|
||||
const messageReply = h(MessageReply, { author: props.author?.display_name || props.author!.username, text: props.text || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" });
|
||||
const messageReply = h(MessageReply, { author: getDisplayName(props.author), text: props.text || "", id: props.message.uuid, replyId: props.replyMessage?.uuid || element.dataset.messageId!, maxWidth: "full" });
|
||||
messageBox.prepend(div);
|
||||
render(messageReply, div);
|
||||
}
|
||||
|
|
7
utils/sortMembers.ts
Normal file
7
utils/sortMembers.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { GuildMemberResponse } from "~/types/interfaces";
|
||||
|
||||
export default (members: GuildMemberResponse[]): GuildMemberResponse[] => {
|
||||
return members.sort((a, b) => {
|
||||
return getDisplayName(a.user, a).localeCompare(getDisplayName(b.user, b))
|
||||
})
|
||||
}
|
7
utils/sortUsers.ts
Normal file
7
utils/sortUsers.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { UserResponse } from "~/types/interfaces";
|
||||
|
||||
export default (users: UserResponse[]): UserResponse[] => {
|
||||
return users.sort((a, b) => {
|
||||
return getDisplayName(a).localeCompare(getDisplayName(b))
|
||||
})
|
||||
}
|
3
utils/validateUsername.ts
Normal file
3
utils/validateUsername.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default (username: string) => {
|
||||
return /^[\w.-]+$/.test(username);
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export function validateUsername(username: string) {
|
||||
return /^[\w.-]+$/.test(username);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue