Last active
June 22, 2023 06:49
-
-
Save nanxstats/2e307097b7dd0171bcfae2be8edebdfd to your computer and use it in GitHub Desktop.
Update unpacked extension with RobotJS
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
// Automate browser extension updates with RobotJS | |
const robot = require("robotjs"); | |
const { execSync } = require("child_process"); | |
const updateExtension = (coordRemove) => { | |
// Open in extensions page in browser | |
execSync('open -a "Google Chrome" chrome://extensions'); | |
// Move to and click "Remove" button of the extension | |
robot.setMouseDelay(1000); | |
robot.moveMouseSmooth(coordRemove[0], coordRemove[1]); | |
robot.mouseClick(); | |
// Click "Remove" button in the confirm dialog | |
robot.keyTap("enter"); | |
// Open iTerm (new tab) and do git pull | |
execSync("open -a iTerm ."); | |
robot.typeStringDelayed("cd bpc && git pull", 800); | |
robot.keyTap("enter"); | |
// Open Finder and highlight the directory | |
execSync("open -a Finder"); | |
robot.typeStringDelayed("bpc", 1000); | |
// Get selected directory position by its highlighted color | |
let screen = robot.getScreenSize(); | |
let img = robot.screen.capture(0, 0, screen.width, screen.height); | |
// Support for higher density screens | |
let multiplier = img.width / screen.width; | |
// Find the x coordinate: likely covers the center of the screen | |
let coordFinderX = screen.width / 2; | |
// Find the y coordinate | |
let colors = []; | |
for (let i = 0; i < screen.height; i++) { | |
colors[i] = img.colorAt(coordFinderX * multiplier, i * multiplier); | |
} | |
let bluepixel = colors.indexOf("2961d9"); | |
robot.moveMouseSmooth(coordFinderX, bluepixel + 10); | |
robot.mouseToggle("down"); | |
// Drag and drop into extensions tab | |
robot.dragMouse(30, bluepixel + 50); | |
setTimeout(() => { | |
robot.mouseToggle("up"); | |
}, 500); | |
// Close the popup options tabs, extension tab, Finder, and iTerm tabs | |
setTimeout(() => { | |
robot.keyTap("w", "command"); | |
}, 5000); | |
setTimeout(() => { | |
robot.keyTap("w", "command"); | |
}, 6000); | |
setTimeout(() => { | |
robot.keyTap("w", "command"); | |
}, 7000); | |
setTimeout(() => { | |
execSync("open -a Finder"); | |
robot.keyTap("w", "command"); | |
}, 8000); | |
setTimeout(() => { | |
execSync("open -a iTerm"); | |
robot.keyTap("w", "command"); | |
robot.keyTap("w", "command"); | |
}, 9000); | |
}; | |
updateExtension([235, 425]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment