-
Notifications
You must be signed in to change notification settings - Fork 0
/
hetzner-mysql-tableplus.js
60 lines (47 loc) · 1.87 KB
/
hetzner-mysql-tableplus.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// ==UserScript==
// @name Hetzner TablePlus Connection
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Created a button that copies an URL for importing MySQL connections into TablePlus
// @author Arne Stulp
// @match https://konsoleh.hetzner.com/database.php?type=mysql&action=settings*
// @icon https://www.google.com/s2/favicons?sz=64&domain=hetzner.com
// @grant GM_setClipboard
// ==/UserScript==
'use strict';
// Inject button
document.querySelector('#content .contentpart')
.insertAdjacentHTML('afterbegin','<div class="contentmenu"><a id="generateConnection">Create TablePlus URL</a></div>');
// Add event listener
document.getElementById('generateConnection').addEventListener ("click", function() {
// Grab credentials
const connection = document.getElementById('connection_string').innerHTML.split(' ');
const db = connection[10];
const user = connection[12];
const password = connection[13].split('-p')[1];
const hostname = connection[15];
let statusColor = '007F3D'; // green
let environment = 'local';
if (db.indexOf('staging') > -1) {
statusColor = 'AA7941'; // orange
environment = 'staging';
}
if (db.indexOf('prod') > -1) {
statusColor = '6D0000'; // red
environment = 'production';
}
// Ask name for fav
const name = prompt('Choose name for connection', db + ' [hetzner]');
if (name.length === 0) {
alert('Invalid name');
return false;
}
// Create shell command string
const str = 'mysql://'+user
+':'+password+'@'+hostname+'/'
+db+'?statusColor='+statusColor
+'&enviroment='+environment+'&name='+encodeURIComponent(name)
+'&tLSMode=0&usePrivateKey=false&safeModeLevel=0&advancedSafeModeLevel=0&driverVersion=0';
// Save to clipboard
GM_setClipboard (str);
} , false);