mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-27 12:55:55 +00:00
* Added: Setting for customizing how tab-completion matches emote names. * Added: Clips pages now have support for opening emote cards when clicking an emote in the chat replay. * Fixed: Issue where chat was not rendering as intended on clips pages. * Fixed: Issue where the FFZ Control Center link was not added to clips pages. * Fixed: The chat actions module being instantiated in memory twice. * Fixed: Blank badges appearing in chat, most notably in historic messages, when a chat message has invalid badge data associated with it. * Fixed: Use a mutation observer for detecting the drops Claim button, rather than a simple timeout, for better consistency. * Fixed: Issue when using the webpack public path variable that may lead to URL generation with extra `/` characters, breaking some behavior in Firefox when packaged as a local extension. * API Added: Support for displaying an emote's original name, if an emote has been given a collection-specific name, using an `original_name` field.
138 lines
2.7 KiB
JavaScript
138 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
export function isValidBlob(blob) {
|
|
return blob instanceof Blob || blob instanceof File || blob instanceof ArrayBuffer || blob instanceof Uint8Array;
|
|
}
|
|
|
|
export async function serializeBlob(blob) {
|
|
if ( ! blob )
|
|
return null;
|
|
|
|
if ( blob instanceof Blob )
|
|
return {
|
|
type: 'blob',
|
|
mime: blob.type,
|
|
buffer: await blob.arrayBuffer(),
|
|
}
|
|
|
|
if ( blob instanceof File )
|
|
return {
|
|
type: 'file',
|
|
mime: blob.type,
|
|
name: blob.name,
|
|
modified: blob.lastModified,
|
|
buffer: await blob.arrayBuffer()
|
|
}
|
|
|
|
if ( blob instanceof ArrayBuffer )
|
|
return {
|
|
type: 'ab',
|
|
buffer: blob
|
|
}
|
|
|
|
if ( blob instanceof Uint8Array )
|
|
return {
|
|
type: 'u8',
|
|
buffer: blob.buffer
|
|
}
|
|
|
|
throw new TypeError('Invalid type');
|
|
}
|
|
|
|
export function deserializeBlob(data) {
|
|
if ( ! data || ! data.type )
|
|
return null;
|
|
|
|
if ( data.type === 'blob' )
|
|
return new Blob([data.buffer], {type: data.mime});
|
|
|
|
if ( data.type === 'file' )
|
|
return new File([data.buffer], data.name, {type: data.mime, lastModified: data.modified});
|
|
|
|
if ( data.type === 'ab' )
|
|
return data.buffer;
|
|
|
|
if ( data.type === 'u8' )
|
|
return new Uint8Array(data.buffer);
|
|
|
|
throw new TypeError('Invalid type');
|
|
}
|
|
|
|
export function serializeBlobUrl(blob) {
|
|
return new Promise((s,f) => {
|
|
const reader = new FileReader();
|
|
reader.onabort = f;
|
|
reader.onerror = f;
|
|
reader.onload = e => {
|
|
s(e.target.result);
|
|
}
|
|
reader.readAsDataURL(blob);
|
|
});
|
|
}
|
|
|
|
export function deserializeBlobUrl(url) {
|
|
return fetch(blob).then(res => res.blob())
|
|
}
|
|
|
|
export function deserializeABUrl(url) {
|
|
return fetch(blob).then(res => res.arrayBuffer())
|
|
}
|
|
|
|
export async function serializeBlobForExt(blob) {
|
|
if ( ! blob )
|
|
return null;
|
|
|
|
if ( blob instanceof Blob )
|
|
return {
|
|
type: 'blob',
|
|
mime: blob.type,
|
|
url: await serializeBlobUrl(blob)
|
|
}
|
|
|
|
if ( blob instanceof File )
|
|
return {
|
|
type: 'file',
|
|
mime: blob.type,
|
|
name: blob.name,
|
|
modified: blob.lastModified,
|
|
url: await serializeBlobUrl(blob)
|
|
}
|
|
|
|
if ( blob instanceof ArrayBuffer )
|
|
return {
|
|
type: 'ab',
|
|
url: await serializeBlobUrl(new Blob([blob]))
|
|
}
|
|
|
|
if ( blob instanceof Uint8Array )
|
|
return {
|
|
type: 'u8',
|
|
url: await serializeBlobUrl(new Blob([blob]))
|
|
}
|
|
|
|
throw new TypeError('Invalid type');
|
|
|
|
}
|
|
|
|
export async function deserializeBlobForExt(data) {
|
|
if ( ! data || ! data.type )
|
|
return null;
|
|
|
|
if ( data.type === 'blob' )
|
|
return await deserializeBlobUrl(data.url);
|
|
|
|
if ( data.type === 'file' )
|
|
return new File(
|
|
[await deserializeBlobUrl(data.url)],
|
|
data.name,
|
|
{type: data.mime, lastModified: data.modified}
|
|
);
|
|
|
|
if ( data.type === 'ab' )
|
|
return await deserializeABUrl(data.url);
|
|
|
|
if ( data.type === 'u8' )
|
|
return new Uint8Array(await deserializeABUrl(data.url));
|
|
|
|
throw new TypeError('Invalid type');
|
|
}
|