Skip to content

Commit

Permalink
Implement keybr.com
Browse files Browse the repository at this point in the history
  • Loading branch information
PiggyPlex committed Apr 24, 2021
1 parent 1f739d9 commit 0aa1e55
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 62 deletions.
10 changes: 5 additions & 5 deletions websites/K/keybr.com/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"en": "Teaching the world to type at the speed of thought! Typing lessons that work."
},
"service": "keybr.com",
"version": "1.0.1",
"version": "1.0.0",
"logo": "https://i.imgur.com/5ZUdx7o.png",
"thumbnail": "https://i.imgur.com/D6gTvpU.png",
"color": "#F5F0F0",
Expand All @@ -24,15 +24,15 @@
"id": "changedetails",
"title": "Change top line",
"icon": "fas fa-trophy",
"value": "Current Key: %currentkey%",
"placeholder": "Current Key: %currentkey%"
"value": "Current Key: {currentkey}",
"placeholder": "Current Key: {currentkey}"
},
{
"id": "changestate",
"title": "Change second line",
"icon": "fas fa-info",
"value": "WPM: %speed.wpm% | Score: %score%",
"placeholder": "WPM: %speed.wpm% | Score: %score%"
"value": "WPM: {speed.wpm} | Score: {score}",
"placeholder": "WPM: {speed.wpm} | Score: {score}"
}
]
}
107 changes: 50 additions & 57 deletions websites/K/keybr.com/presence.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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 @@ -15,57 +16,61 @@ 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;
let g: any;
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;
},
_helper2 = (b: string): f => {
const c: HTMLCollection = document.querySelector(b)?.children?.[1]?.children,
e: f = {};
};
const _helper2 = (b: string): f => {
const c: HTMLCollection = document.querySelector(b)?.children?.[1]?.children;
const 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;
},
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 = {};
};
const getSpeed = (): f => {
const wpm: d = _helper('Average typing speed.');
const best: d = _helper('Best typing speed.');
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;
},
confidence: d = _helper('Confidence level.'),
learningRate: d = _helper('Learning rate.'),
learningKeys: (string)[] = [],
learningKeysElements: NodeList = document.querySelectorAll('.LessonKey.LessonKey--included');
};
const confidence: d = _helper('Confidence level.');
const learningRate: d = _helper('Learning rate.');
let learningKeys: (string)[] = [];
const learningKeysElements: NodeList = document.querySelectorAll('.LessonKey.LessonKey--included');
if (learningKeysElements && typeof learningKeysElements === 'object')
learningKeysElements.forEach((learningKey): void => {
const g = (learningKey as HTMLElement).innerText;
let 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,
learningKey: string = (learningKeyData[0] as HTMLElement)?.innerText || 'Unknown',
speedData: f = getSpeed(),
__pageData = await presence.getPageletiable('__pageData');
)?.children?.[1]?.children;
const learningKey: string = (learningKeyData[0] as HTMLElement)?.innerText || 'Unknown';
const speedData: f = getSpeed();
const __pageData = await presence.getPageletiable('__pageData');
g = _helper2('span.Practice-errors');
let errors, errorIncrease;
if (g && typeof g === 'object') {
Expand All @@ -78,45 +83,33 @@ 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ඞ')
.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, '%');
.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 {
};
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: (string | HTMLElement| Element) = document.querySelector('.Player--me')?.children?.[2]?.children?.[0]?.children?.[1];
let g: any = document.querySelector('.Player--me')?.children?.[2]?.children?.[0]?.children?.[1];
const idle: PresenceData = {
...presenceData,
details: 'Multiplayer Race',
Expand All @@ -127,12 +120,12 @@ presence.on('UpdateData', async (): Promise<void> => {
return;
};
if (!g) {
presenceData = idle;
presenceData = idle
return;
};
g = (g as HTMLElement)?.innerText;
const position = g || undefined,
states: {
const position = g || undefined;
const states: {
[ key: string ]: string
} = {
'Zzz... Wait for the next race': 'Idle',
Expand All @@ -159,7 +152,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 0aa1e55

Please sign in to comment.