Skip to content

Commit

Permalink
some fixups to the pr
Browse files Browse the repository at this point in the history
  • Loading branch information
KraXen72 committed Jan 3, 2025
1 parent be34e30 commit f217f08
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion assets/settingCss.css
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ input:checked+.advancedSlider:hover {
/* Match Result Copy Button Styles */
.matchResultButton {
position: absolute;
bottom: 28%;
bottom: 3rem;
left: 50%;
color: white;
font-size: 1.5em;
Expand Down
99 changes: 55 additions & 44 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,61 @@ export const styleSettingsCSS = {

ipcRenderer.on('main_did-finish-load', (event, _userPrefs) => {
patchSettings(_userPrefs);
if (_userPrefs.saveMatchResultJSONButton) {
const copyStr = 'Copy';
const copiedStr = 'Copied to Clipboard!';
const failedToCopy = 'Failed to get data. Make sure you are on the Leaderboard tab.';
const buttonElement = createElement('div', { text: copyStr, class: ['matchResultButton'] });
let lastCopied = 0;
const copyCooldownMS = 2000;
function copyScoreboardToClipboard() {
if (Date.now() - lastCopied < copyCooldownMS) return;
lastCopied = Date.now();
const lbElement = document.querySelector('#endTable');
if (!lbElement) return setButtonText(failedToCopy);
const hardpoint = document.querySelector('#endTable').children[0].children[0].children[5].textContent === 'Obj';
const output = [...lbElement.children[0].children].slice(2).map(leaderboardRow => {
// @ts-ignore I have no idea but I hate the red squiggly
const children: HTMLElement[] = [...leaderboardRow.children];
let returnObject = {
position: children[0].innerText.replace('.', ''),
name: children[1].innerText,
score: children[2].innerText,
kills: children[3].innerText,
deaths: children[4].innerText
}
if (hardpoint) {
Object.assign(returnObject, {
objective: children[5].innerText,
damage: children[6].innerText
})
}
return returnObject;
});
strippedConsole.log(output);
navigator.clipboard.writeText(JSON.stringify(output, null, 2));
setButtonText(copiedStr);
}
buttonElement.onclick = copyScoreboardToClipboard;
function setButtonText(text: string) {
buttonElement.textContent = text;
setTimeout(() => {
buttonElement.textContent = copyStr;
}, copyCooldownMS);
}
document.getElementById('endMidHolder').appendChild(buttonElement);
};

if (!_userPrefs.saveMatchResultJSONButton) return;
const copyStr = 'Copy';
const copiedStr = 'Copied to Clipboard!';
const failedToCopy = 'Failed to get data. Make sure you are on the Leaderboard tab.';
const buttonElement = createElement('div', { text: copyStr, class: ['matchResultButton'] });
let lastCopied = 0;
const copyCooldownMS = 2000;

function copyScoreboardToClipboard() {
if (Date.now() - lastCopied < copyCooldownMS) return;
lastCopied = Date.now();
const lbElement = document.querySelector('#endTable');
if (!lbElement) return setButtonText(failedToCopy);

const isHardpoint = document.querySelector('#endTable')
.children?.[0]
.children?.[0]
.children?.[5]
.textContent === 'Obj';

const output = [...lbElement.children?.[0]?.children].slice(2).map(leaderboardRow => {
const rowChildren = [...leaderboardRow.children] as HTMLElement[];
const returnObj = {
position: rowChildren[0].innerText.replace('.', ''),
name: rowChildren[1].innerText,
score: rowChildren[2].innerText,
kills: rowChildren[3].innerText,
deaths: rowChildren[4].innerText
}
if (isHardpoint) {
Object.assign(returnObj, {
objective: rowChildren[5].innerText,
damage: rowChildren[6].innerText
})
}
return returnObj;
});

strippedConsole.log(output);
navigator.clipboard.writeText(JSON.stringify(output, null, 2));
setButtonText(copiedStr);
}

buttonElement.onclick = copyScoreboardToClipboard;

function setButtonText(text: string) {
buttonElement.textContent = text;
setTimeout(() => {
buttonElement.textContent = copyStr;
}, copyCooldownMS);
}

document.getElementById('endMidHolder').appendChild(buttonElement);

});

ipcRenderer.on('checkForUpdates', async(event, currentVersion) => {
Expand Down
2 changes: 1 addition & 1 deletion src/settingsui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const settingsDesc: SettingsDesc = {
extendedRPC: { title: 'Extended Discord RPC', type: 'bool', desc: 'Adds Github + Discord buttons to RPC. No effect if RPC is off.', safety: 0, cat: 0, instant: true },
hideAds: { title: 'Hide/Block Ads', type: 'sel', desc: 'With \'hide\' you can still claim free KR. Using \'block\' also blocks trackers.', safety: 0, cat: 0, refreshOnly: true, opts: ['block', 'hide', 'off'] },
customFilters: { title: 'Custom Filters', type: 'bool', desc: 'Enable custom network filters. ', safety: 0, cat: 0, refreshOnly: true },
saveMatchResultJSONButton: { title: 'Match Result To Clipboard', type: 'bool', desc: 'Adds a button to the end of match screen that allows you to copy the match JSON to clipboard.', safety: 0, cat: 0, refreshOnly: true },
saveMatchResultJSONButton: { title: 'Match Result To Clipboard', type: 'bool', desc: 'New button on match end which copies the match results JSON.', safety: 0, cat: 0, refreshOnly: true },
userscripts: { title: 'Userscript support', type: 'bool', desc: `Enable userscript support. read <a href="https://github.com/${repoID}/blob/master/USERSCRIPTS.md" target="_blank">USERSCRIPTS.md</a> for more info.`, safety: 1, cat: 0 },

menuTimer: { title: 'Menu Timer', type: 'bool', safety: 0, cat: 1, instant: true },
Expand Down

0 comments on commit f217f08

Please sign in to comment.