-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor and add token expires check
- Loading branch information
Showing
8 changed files
with
144 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,11 @@ | ||
import { plugin } from "@/constants"; | ||
|
||
import { copyToClipboard, getUsageInfo, init, isLoggedIn } from "./plugin"; | ||
import { init } from "./plugin"; | ||
|
||
const loginButtonSelector = `[data-testid="header--button-login"]`; | ||
const logoutButtonSelector = `[data-testid="logOutDialogIcon"]`; | ||
const tabSelector = `[data-testid="tab-content"]`; | ||
|
||
const attrKey = `${plugin.name}-replaced`; | ||
const attrValue = "1"; | ||
|
||
function updateUsageInfo(): void { | ||
const loggedIn = isLoggedIn(); | ||
|
||
const tabs = document.querySelectorAll(tabSelector); | ||
if (!tabs) return; | ||
|
||
const usageInfoLines = getUsageInfo(loggedIn).split("\n").reverse(); | ||
|
||
for (const tab of tabs) { | ||
const alreadyReplaced = tab.getAttribute(attrKey) === attrValue; | ||
if (alreadyReplaced) continue; | ||
|
||
const commands = [...tab.querySelectorAll("button")] | ||
.map((node) => node.parentElement!) | ||
.filter((node) => !!/^(npm|pnpm|yarn)/.test(node.textContent || "")); | ||
|
||
if (commands.length === 0) continue; | ||
|
||
for (const info of usageInfoLines) { | ||
const cloned = commands[0].cloneNode(true) as HTMLElement; | ||
|
||
const textEl = cloned.querySelector("span")!; | ||
textEl.textContent = info; | ||
|
||
const copyEl = cloned.querySelector("button")!; | ||
|
||
copyEl.style.visibility = loggedIn ? "visible" : "hidden"; | ||
copyEl.addEventListener("click", (e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
copyToClipboard(info); | ||
}); | ||
|
||
commands[0].parentElement!.append(cloned); | ||
tab.setAttribute(attrKey, attrValue); | ||
} | ||
|
||
// Remove commands that don't work with oauth | ||
for (const node of commands) { | ||
if (node.textContent?.includes("adduser") || node.textContent?.includes("set password")) { | ||
node.remove(); | ||
tab.setAttribute(attrKey, attrValue); | ||
} | ||
} | ||
} | ||
} | ||
const logoutButtonSelector = `[data-testid="header--button-logout"],[data-testid="logOutDialogIcon"]`; | ||
const usageTabsSelector = `[data-testid="tab-content"]`; | ||
|
||
init({ | ||
loginButton: loginButtonSelector, | ||
logoutButton: logoutButtonSelector, | ||
updateUsageInfo, | ||
usageTabs: usageTabsSelector, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters