Skip to content

Instantly share code, notes, and snippets.

@ntkrnl32
Created December 11, 2025 17:03
Show Gist options
  • Select an option

  • Save ntkrnl32/778140602a664c9ca0e64a0b4393e0e3 to your computer and use it in GitHub Desktop.

Select an option

Save ntkrnl32/778140602a664c9ca0e64a0b4393e0e3 to your computer and use it in GitHub Desktop.
github account switcher
// ==UserScript==
// @name GitHub Switch Account Button
// @icon https://github.com/favicon.ico
// @version 1.0
// @description Adds a sticky 'Switch Account' button to the bottom right of GitHub pages.
// @author NtKrnl32
// @match https://github.com/*
// @exclude https://github.com/switch_account*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
if (window.location.pathname.startsWith('/switch_account')) {
return;
}
const switchButton = document.createElement('a');
const currentUrl = encodeURIComponent(window.location.href);
switchButton.href = `https://github.com/switch_account?return_to=${currentUrl}`;
switchButton.innerHTML = `
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-sign-in">
<path d="M2 2.75C2 2.336 2.336 2 2.75 2h5.5c.414 0 .75.336.75.75v1.5a.75.75 0 0 1-1.5 0v-1.5H2.75A.25.25 0 0 0 2.5 2.75v10.5c0 .138.112.25.25.25h5.5a.75.75 0 0 1 0 1.5h-5.5A1.75 1.75 0 0 1 1 13.25V2.75ZM8.75 8a.75.75 0 0 1 .75-.75h5a.75.75 0 0 1 0 1.5h-5A.75.75 0 0 1 8.75 8ZM14 11.25a.75.75 0 0 0 0-1.5h-5a.75.75 0 0 0 0 1.5h5ZM14 5.5a.75.75 0 0 0 0-1.5h-5a.75.75 0 0 0 0 1.5h5Z"></path>
</svg>
Switch Account
`;
switchButton.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
display: flex;
align-items: center;
gap: 6px;
padding: 8px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
text-align: center;
cursor: pointer;
border-radius: 6px;
text-decoration: none;
color: var(--color-btn-primary-text, #ffffff); /* 文本颜色 */
background-color: var(--color-btn-primary-bg, #2da44e); /* 背景色 */
border: 1px solid var(--color-btn-primary-border, rgba(27, 31, 35, 0.15));
box-shadow: var(--color-btn-primary-shadow, rgba(27, 31, 35, 0.1));
transition: background-color 0.1s ease-in-out;
`;
switchButton.onmouseover = function() {
this.style.backgroundColor = 'var(--color-btn-primary-hover-bg, #2c974b)';
};
switchButton.onmouseout = function() {
this.style.backgroundColor = 'var(--color-btn-primary-bg, #2da44e)';
};
document.body.appendChild(switchButton);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment