Skip to content

Commit

Permalink
Update presence.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
PiggyPlex authored Mar 17, 2021
1 parent 7e1500a commit 1f739d9
Showing 1 changed file with 57 additions and 50 deletions.
107 changes: 57 additions & 50 deletions websites/K/keybr.com/presence.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const presence: Presence = new Presence({
clientId: '812689086435164251'
});
}), startTime: number = new Date().getTime();

const startTime: number = new Date().getTime();
let presenceData: PresenceData = {
startTimestamp: startTime,
largeImageKey: 'logo'
Expand All @@ -16,61 +15,57 @@ presence.on('UpdateData', async (): Promise<void> => {
details: await presence.getSetting('changedetails'),
state: await presence.getSetting('changestate')
};
const _log = console.log;
console.log = () => {};
console.log(settings);
console.log = _log;
const _format = async (a: string): Promise<string> => {
let g: any;
let g;
type f = { [ key: string ]: string };
type d = string | false;
const _helper = (b: string): d => {
if (typeof b !== 'string') return false;
const c = document.querySelector(`span[title="${b}"]`);
if (!c || typeof c != 'object' || !c?.children?.length) return false;
return (c?.children?.[1] as HTMLElement)?.innerText || false;
};
const _helper2 = (b: string): f => {
const c: HTMLCollection = document.querySelector(b)?.children?.[1]?.children;
const e: f = {};
},
_helper2 = (b: string): f => {
const c: HTMLCollection = document.querySelector(b)?.children?.[1]?.children,
e: f = {};
g = c?.[0] as HTMLElement;
if (g && g?.innerText) e.value = g.innerText;
g = c?.[1] as HTMLElement;
if (g) e.increase = g?.innerText.replace(/(↑|↓)/g, '');
return e;
};
const getSpeed = (): f => {
const wpm: d = _helper('Average typing speed.');
const best: d = _helper('Best typing speed.');
},
getSpeed = (): f => {
const wpm: d = ((_helper('Typing speed in the last lesson.') ?? _helper('Average typing speed.')) || '').replace(/ ?\(.+\)/g, ''),
best: d = _helper('Best typing speed.'),
e: f = {};
g = _helper2('span.Practice-speed');
let current, increase;
if (g && typeof g === 'object') {
current = g.value;
increase = g.increase;
};
const e: f = {};
if (wpm) e.wpm = wpm;
if (best) e.best = best;
if (current) e.current = current;
if (increase) e.increase = increase;
return e;
};
const confidence: d = _helper('Confidence level.');
const learningRate: d = _helper('Learning rate.');
let learningKeys: (string)[] = [];
const learningKeysElements: NodeList = document.querySelectorAll('.LessonKey.LessonKey--included');
},
confidence: d = _helper('Confidence level.'),
learningRate: d = _helper('Learning rate.'),
learningKeys: (string)[] = [],
learningKeysElements: NodeList = document.querySelectorAll('.LessonKey.LessonKey--included');
if (learningKeysElements && typeof learningKeysElements === 'object')
learningKeysElements.forEach((learningKey): void => {
let g = (learningKey as HTMLElement).innerText;
const g = (learningKey as HTMLElement).innerText;
if (!g || typeof g !== 'string') return;
learningKeys.push(g);
});
const learningKeyData: HTMLCollection = (
document.querySelector('[title="The current key details."]') as HTMLElement
)?.children?.[1]?.children;
const learningKey: string = (learningKeyData[0] as HTMLElement)?.innerText || 'Unknown';
const speedData: f = getSpeed();
const __pageData = await presence.getPageletiable('__pageData');
)?.children?.[1]?.children,
learningKey: string = (learningKeyData[0] as HTMLElement)?.innerText || 'Unknown',
speedData: f = getSpeed(),
__pageData = await presence.getPageletiable('__pageData');
g = _helper2('span.Practice-errors');
let errors, errorIncrease;
if (g && typeof g === 'object') {
Expand All @@ -83,33 +78,45 @@ presence.on('UpdateData', async (): Promise<void> => {
score = g.value;
scoreIncrease = g.increase;
};
console.log({
speedData,
errors,
errorIncrease,
score,
scoreIncrease,
confidence,
learningRate,
learningKey,
learningKeys,
__pageData
});
// yes...much performance
return a
.replace(/^{/g, 'ඞsusඞ') // Escaping {
.replace(/{speed}/gi, speedData.current)
.replace(/{speed.best}/gi, speedData.best)
.replace(/{speed.increase}/gi, speedData.increase)
.replace(/{speed.wpm}/gi, speedData.wpm)
.replace(/{errors}/gi, errors)
.replace(/{errors.increase}/gi, errorIncrease)
.replace(/{score}/gi, score)
.replace(/{score.increase}/gi, scoreIncrease)
.replace(/{confidence}/gi, confidence || 'Unknown')
.replace(/{learningrate}/gi, learningRate || 'Unknown')
.replace(/{currentkey}/gi, learningKey)
.replace(/{currentkeys}/gi, [...new Set(learningKeys)].join(''))
.replace(/{theme}/gi, __pageData.prefs.themeName)
.replace(/{textsize}/gi, __pageData.prefs.textSize)
.replace(/{username}/gi, (__pageData?.publicUser?.id && __pageData?.publicUser?.name) || 'Unknown')
.replace(/ඞsusඞ/g, '{') // Escaping {
.replace(/^%/g, 'ඞsusඞ')
.replace(/%speed%/gi, speedData.current)
.replace(/%speed.best%/gi, speedData.best)
.replace(/%speed.increase%/gi, speedData.increase)
.replace(/%speed.wpm%/gi, speedData.wpm)
.replace(/%errors%/gi, errors)
.replace(/%errors.increase%/gi, errorIncrease)
.replace(/%score%/gi, score)
.replace(/%score.increase%/gi, scoreIncrease)
.replace(/%confidence%/gi, confidence || 'Unknown')
.replace(/%learningrate%/gi, learningRate || 'Unknown')
.replace(/%currentkey%/gi, learningKey)
.replace(/%currentkeys%/gi, [...new Set(learningKeys)].join(''))
.replace(/%theme%/gi, __pageData.prefs.themeName)
.replace(/%textsize%/gi, __pageData.prefs.textSize)
.replace(/%username%/gi, (__pageData?.publicUser?.id && __pageData?.publicUser?.name) || 'Unknown')
.replace(/ඞsusඞ/g, '%');
};
presenceData = {
...presenceData,
details: await _format(' ' + settings.details || `Current Key: {currentkey}`),
state: await _format(' ' + settings.state || `WPM: {speed.wpm} | Score: {score}`)
details: await _format(' ' + settings.details || `Current Key: %currentkey%`),
state: await _format(' ' + settings.state || `WPM: %speed.wpm% | Score: %score%`)
};
} else if (window.location.pathname?.toLowerCase() === '/multiplayer') {
let g: any = document.querySelector('.Player--me')?.children?.[2]?.children?.[0]?.children?.[1];
let g: (string | HTMLElement| Element) = document.querySelector('.Player--me')?.children?.[2]?.children?.[0]?.children?.[1];
const idle: PresenceData = {
...presenceData,
details: 'Multiplayer Race',
Expand All @@ -120,12 +127,12 @@ presence.on('UpdateData', async (): Promise<void> => {
return;
};
if (!g) {
presenceData = idle
presenceData = idle;
return;
};
g = (g as HTMLElement)?.innerText;
const position = g || undefined;
const states: {
const position = g || undefined,
states: {
[ key: string ]: string
} = {
'Zzz... Wait for the next race': 'Idle',
Expand All @@ -152,7 +159,7 @@ presence.on('UpdateData', async (): Promise<void> => {
layouts: 'Layouts',
'text-tools': 'Text Tools',
'terms-of-service': 'Terms of Service',
'privacy-policy': 'Privacy Policy',
'privacy-policy': 'Privacy Policy'
};
presenceData = {
...presenceData,
Expand Down

0 comments on commit 1f739d9

Please sign in to comment.