Skip to content

Instantly share code, notes, and snippets.

@FreePhoenix888
Created November 27, 2022 17:06
Show Gist options
  • Save FreePhoenix888/867054ea39222a2c8965e982db3434ac to your computer and use it in GitHub Desktop.
Save FreePhoenix888/867054ea39222a2c8965e982db3434ac to your computer and use it in GitHub Desktop.
Regenerate and copy nuget tokens
const regenerateTokens = async ({ manageContainer }) => {
const regenerateTokenElements = [
...manageContainer.querySelectorAll('a'),
].filter((linkElement) => linkElement.textContent.trim() == 'Regenerate');
for (regenerateTokenElement of regenerateTokenElements) {
regenerateTokenElement.click();
}
prompt('Wait until all your keys regenerate to copy them properly');
};
const consoleLogTokens = async ({ manageContainer }) => {
const apiKeyDetailContainers = [
...manageContainer.querySelectorAll('.api-key-details'),
];
const tokensData = {};
for (apiKeyDetailContainer of apiKeyDetailContainers) {
const apiKeyName = apiKeyDetailContainer
.querySelector('h3')
.textContent.trim();
const copyTokenElement = [
...apiKeyDetailContainer.querySelectorAll('a'),
].find((linkElement) => linkElement.textContent.trim() == 'Copy');
copyTokenElement.click();
const apiKeyToken = await navigator.clipboard.readText();
tokensData[apiKeyName] = apiKeyToken;
}
console.log(JSON.stringify(tokensData));
};
const manageContainer = document.querySelector('#manage-container');
const overlayContainer = document.createElement('div');
overlayContainer.style.position = 'fixed';
overlayContainer.style.top = '50%';
overlayContainer.style.left = '50%';
overlayContainer.style.transform = 'translateX(-50%)';
overlayContainer.style.padding = '10px';
overlayContainer.style.background = 'black';
const regenerateTokensButton = document.createElement('button');
regenerateTokensButton.textContent = 'Regenerate tokens';
regenerateTokensButton.addEventListener('click', () =>
regenerateTokens({ manageContainer })
);
overlayContainer.appendChild(regenerateTokensButton);
const consoleAllTokensButton = document.createElement('button');
consoleAllTokensButton.textContent = 'Copy tokens';
consoleAllTokensButton.addEventListener('click', () =>
consoleLogTokens({ manageContainer })
);
overlayContainer.appendChild(consoleAllTokensButton);
const closeOverlayButton = document.createElement('button');
closeOverlayButton.textContent = 'Close overlay';
closeOverlayButton.addEventListener('click', () => {
document.body.removeChild(overlayContainer);
});
overlayContainer.appendChild(closeOverlayButton);
document.body.appendChild(overlayContainer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment