Skip to content

Instantly share code, notes, and snippets.

@PSingletary
Last active December 21, 2024 13:02
Show Gist options
  • Save PSingletary/1b95b448784aa0527bb1964b0a37ad00 to your computer and use it in GitHub Desktop.
Save PSingletary/1b95b448784aa0527bb1964b0a37ad00 to your computer and use it in GitHub Desktop.
expand account switcher
// ==UserScript==
// @name Bluesky Account Switcher
// @namespace http://tampermonkey.net/
// @version 2024-11-20
// @description Automatically expands account switcher on Bluesky settings page
// @author https://github.com/aliceisjustplaying
// @match https://bsky.app/*
// @run-at document-start
// @icon https://www.google.com/s2/favicons?sz=64&domain=bsky.app
// @grant none
// @license MIT
// @downloadURL https://gist.githubusercontent.com/PSingletary/1b95b448784aa0527bb1964b0a37ad00/raw/f65e7adeffa3285cb77d11a05035e940b032b756/expand.js
// @updateURL https://gist.githubusercontent.com/PSingletary/1b95b448784aa0527bb1964b0a37ad00/raw/f65e7adeffa3285cb77d11a05035e940b032b756/expand.js
// @match https://bsky.app/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bsky.app
// @grant GM.xmlHttpRequest
// ==/UserScript==
(function() {
'use strict';
function simulateClick(element) {
const rect = element.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const events = [
new PointerEvent('pointerover', { clientX: centerX, clientY: centerY, bubbles: true }),
new PointerEvent('pointerdown', { clientX: centerX, clientY: centerY, bubbles: true }),
new PointerEvent('pointerup', { clientX: centerX, clientY: centerY, bubbles: true }),
new MouseEvent('click', { clientX: centerX, clientY: centerY, bubbles: true })
];
events.forEach(event => element.dispatchEvent(event));
}
const observer = new MutationObserver((mutations, obs) => {
const button = document.querySelector('button[aria-label="Switch account"]');
if (button && !button.dataset.clicked) {
button.dataset.clicked = 'true';
simulateClick(button);
}
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment