jnaskali / GitHub Full Public SSH Keys

// ==UserScript==
// @name        GitHub Full Public SSH Keys
// @author      jnaskali
// @copyright   2020, Juhani Naskali (www.naskali.fi)
// @license     MIT
// @version     1.5
// @namespace   https://www.naskali.fi
// @downloadURL https://openuserjs.org/install/jnaskali/GitHub_Full_Public_SSH_Keys.user.js
//
// @match       https://github.com/settings/keys
// @grant       none
// @run-at      document-start
//
// @description Shows your own public SSH keys under key titles in GitHub's SSH key settings (https://github.com/settings/keys) for easy copy-pasting.
// ==/UserScript==

/* jshint esversion: 8 */

const start = async function() {

  var username = document.querySelector('meta[name=user-login]').content;
  var keys = await fetch('https://github.com/' + username + '.keys')
    .then(response =>
      response.text().then(text => text.split(/\r|\n/))
    );

  var keySpans = document.querySelectorAll('code');

  for (var i = 0; i < keys.length - 1; i++) {
    var newCode = document.createElement('code');
    newCode.innerHTML = keys[i] + '\n';
    newCode.style = 'display: block; font-weight: bold;'
    let parent = keySpans[i].parentElement
    parent.parentElement.insertBefore(newCode, parent);
  }
}

start();