Commit 5da0866c authored by Ahmad's avatar Ahmad

inikt

parent 2e1b7867
import clipboardy from 'clipboardy';
// Import required packages
const { exec } = require("child_process");
const otplib = require("otplib");
// Store the last generated token and clipboard content
let lastToken = "";
let previousSecret = "";
// Stores the previous clipboard content to detect changes
let previousContent = "";
// Function to read the clipboard content on Windows
function readClipboard(callback) {
exec("powershell Get-Clipboard", (error, stdout) => {
if (error) {
console.error("Error reading clipboard:", error);
return;
}
// Function to check the clipboard content
const checkClipboard = () => {
const currentContent = clipboardy.readSync();
// Pass the clipboard content to the callback function
callback(stdout.trim());
});
}
// If the content has changed, display it
if (currentContent !== previousContent) {
console.log("Clipboard Content:", currentContent);
previousContent = currentContent;
// Function to generate and display the TOTP code if the secret changes
function checkForNewCode(secret) {
if (secret !== previousSecret) {
console.log(`Detected new secret key from clipboard: ${secret}`);
previousSecret = secret;
}
};
// Check the clipboard every second
setInterval(checkClipboard, 1000);
// Generate TOTP code using the current secret
const currentToken = otplib.authenticator.generate(secret);
// If the current token is different from the last token, log it
if (currentToken !== lastToken) {
console.log(`New 2FA code: ${currentToken}`);
lastToken = currentToken;
}
}
// Run the clipboard read and TOTP generation every second, only on Windows
if (process.platform === "win32") {
setInterval(() => {
// Read the secret from clipboard and generate TOTP code
readClipboard((secret) => {
if (secret) {
checkForNewCode(secret);
}
});
}, 1000);
} else {
console.log("This script only runs on Windows.");
}
{
"name": "aws",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment