GitHub Passkey Redirector

Redirects GitHub login page so that Passkey logon is enabled.

  1. // ==UserScript==
  2. // @name GitHub Passkey Redirector
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description Redirects GitHub login page so that Passkey logon is enabled.
  6. // @author DanTheMan827
  7. // @license MIT
  8. // @match https://github.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  10. // @grant none
  11. // ==/UserScript==
  12. // Special thanks to ChatGPT.
  13. (function() {
  14. 'use strict';
  15. function checkPage() {
  16. const currentURL = window.location.href;
  17.  
  18. if (currentURL.startsWith("https://github.com/login?") || currentURL == "https://github.com/login") {
  19. const urlSearchParams = new URLSearchParams(currentURL.split('?')[1]);
  20.  
  21. if (!urlSearchParams.has('passkey') || urlSearchParams.get('passkey') !== 'true') {
  22. urlSearchParams.set('passkey', 'true');
  23. history.replaceState(null, null, `https://github.com/login?${urlSearchParams.toString()}`);
  24. location.reload();
  25. }
  26. }
  27. }
  28.  
  29. var _wr = function(type) {
  30. var orig = history[type];
  31. return function() {
  32. var rv = orig.apply(this, arguments);
  33. var e = new Event(type);
  34. e.arguments = arguments;
  35. window.dispatchEvent(e);
  36. return rv;
  37. };
  38. };
  39.  
  40. history.replaceState = _wr('replaceState');
  41.  
  42. // Use it like this:
  43. window.addEventListener('replaceState', () => checkPage());
  44. })();