Last active
May 17, 2025 18:38
-
-
Save andelink/d509b7deba4f4f5168e318936737563f to your computer and use it in GitHub Desktop.
UserScript to modify the Kagi session token copy behavior to only clip the token value
This file contains hidden or 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
// ==UserScript== | |
// @name kagi-token-copy.user.js | |
// @description copy kagi session token only (not full link) | |
// @match https://kagi.com/settings?p=user_details | |
// @version 0.1 | |
// @author andelink | |
// @run-at document-idle | |
// ==/UserScript== | |
function getSessionToken(elem) { | |
const text = elem.closest('.search_token').querySelector('.copyToClipText').value; | |
const token = URL.parse(text).searchParams.get('token'); | |
return token | |
} | |
async function writeClipboardText(text) { | |
try { | |
await navigator.clipboard.writeText(text); | |
} catch (error) { | |
console.error(error.message); | |
} | |
} | |
(function () { | |
const container = document.querySelector('.search_token.clipboardCopy'); | |
const icon = container.querySelector('.copyToClip'); | |
icon.onclick = e => { | |
e.preventDefault(); | |
const token = getSessionToken(e.target); | |
writeClipboardText(token); | |
} | |
icon.querySelector('svg').insertAdjacentHTML( | |
'beforeend', | |
'<text x="14" y="18.5" font-family="system-ui" font-size="12" font-weight="800" text-anchor="middle" fill="currentColor">T</text>' | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment