mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 04:27:15 +03:00
Get username for warning chat
This commit is contained in:
@@ -31,8 +31,12 @@ export function openChat(config: ChatConfig): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openWarningChat(warningMessage: string): Promise<void> {
|
export async function openWarningChat(warningMessage: string): Promise<void> {
|
||||||
|
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
||||||
|
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
||||||
|
const publicUserID = await utils.getHash(Config.config.userID);
|
||||||
|
|
||||||
openChat({
|
openChat({
|
||||||
displayName: await utils.getHash(Config.config.userID),
|
displayName: `${userName ? `${userName} | `: ``}${userName !== publicUserID ? publicUserID : ``}`,
|
||||||
composerInitialValue: `I got a warning and want to know what I need to do to improve. ` +
|
composerInitialValue: `I got a warning and want to know what I need to do to improve. ` +
|
||||||
`Warning reason: ${warningMessage.match(/Warning reason: '(.+)'/)[1]}`,
|
`Warning reason: ${warningMessage.match(/Warning reason: '(.+)'/)[1]}`,
|
||||||
customDescription: chrome.i18n.getMessage("warningChatInfo")
|
customDescription: chrome.i18n.getMessage("warningChatInfo")
|
||||||
|
|||||||
11
src/utils.ts
11
src/utils.ts
@@ -492,14 +492,13 @@ export default class Utils {
|
|||||||
async getHash(value: string, times = 5000): Promise<string> {
|
async getHash(value: string, times = 5000): Promise<string> {
|
||||||
if (times <= 0) return "";
|
if (times <= 0) return "";
|
||||||
|
|
||||||
let hashBuffer = new TextEncoder().encode(value).buffer;
|
let hashHex = value;
|
||||||
|
|
||||||
for (let i = 0; i < times; i++) {
|
for (let i = 0; i < times; i++) {
|
||||||
hashBuffer = await crypto.subtle.digest('SHA-256', hashBuffer);
|
const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(hashHex).buffer);
|
||||||
}
|
|
||||||
|
|
||||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||||
|
}
|
||||||
|
|
||||||
return hashHex;
|
return hashHex;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user