-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhetzner-ssh-favorite.js
43 lines (32 loc) · 1.51 KB
/
hetzner-ssh-favorite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ==UserScript==
// @name Hetzner SSH Favorite
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://konsoleh.hetzner.com/logindata.php
// @icon https://www.google.com/s2/favicons?sz=64&domain=hetzner.com
// @grant GM_setClipboard
// ==/UserScript==
'use strict';
// Inject button
document.querySelector('#content>div').insertAdjacentHTML('afterbegin', '<div class="contentmenu"><a id="generatefav">Create Favorite</a></div>');
// Add event listener
document.getElementById('generatefav').addEventListener ("click", function() {
// Grab credentials
const password = document.querySelector('#sshpass+a').getAttribute('onclick').split("innerHTML='")[1].split("'")[0];
const username = document.getElementById('logindata_domain_login').innerHTML;
const hostname = document.getElementById('logindata_server_name').innerHTML;
const port = document.getElementById('logindata_ssh_port').innerHTML;
// Ask name for fav
const fav = prompt('Choose name for favorite', username);
if (!fav) {
alert('Invalid name');
return false;
}
// Create shell command string
const str = 'echo "\\nHost '+fav+'\\n\\tHostName '+hostname+'\\n\\tUser '+username+'\\n\\tPort '+port+'" >> ~/.ssh/config && ssh-copy-id '+fav;
// Save to clipboard
GM_setClipboard (str);
prompt('Command is copied to clipboard. Use password below for confirmation', password);
} , false);