Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Adminer Tweak
// @description simple dashboard tweak for adminer.php (database management)
// @version 2019.10.16
// @namespace https://gist.github.com/anovsiradj/fb4254d6fb6eb6f8bc08d3686482aaec
// @run-at document-end
// @match http://localhost/adminer.php*
// @match http://localhost/adminer*.php*
// @author anovsiradj (mayendra costanov)
// @iconURL https://www.adminer.org/favicon.ico
// @supportURL https://gist.github.com/anovsiradj/fb4254d6fb6eb6f8bc08d3686482aaec
// @downloadURL https://gist.githubusercontent.com/anovsiradj/fb4254d6fb6eb6f8bc08d3686482aaec/raw/adminer_tweak.user.js
// @updateURL https://gist.githubusercontent.com/anovsiradj/fb4254d6fb6eb6f8bc08d3686482aaec/raw/adminer_tweak.user.js
// ==/UserScript==
(function() {
'use strict';
function dump() {
Array.from(arguments).forEach((arg) => console.debug(arg));
}
var cfg = {
//font_size: 'large',
textarea_font_size: 'x-large',
textarea_resize: 'vertical',
};
var win = window, dox = document;
var html = document.firstElementChild, body = document.body;
var main = document.querySelector('#content');
var side = document.querySelector('#menu');
var form = document.forms['form'] || document.forms[0]; // default | auth //
var z = html.offsetWidth, x = side.offsetWidth, y = z - x;
//body.width = body.style.width = String(z) + 'px';
//body.style['font-size'] = cfg.font_size;
main.style.width = String(y) + 'px';
main.style['margin-left'] = String(x) + 'px';
main.style['padding-right'] = '0px';
main.style['padding-bottom'] = '0px';
if (form) {
// default //
var query = form.elements.query, error_stops = form.elements.error_stops, only_errors = form.elements.only_errors, limit = form.elements.limit;
if (query && query.previousElementSibling) {
query.previousElementSibling.focus();
query.previousElementSibling.width = query.previousElementSibling.style.width = '100%';
query.previousElementSibling.style['font-size'] = cfg.textarea_font_size;
query.previousElementSibling.style.resize = cfg.textarea_resize;
}
if (limit) limit.value = 111;
if (only_errors && error_stops) only_errors.checked = error_stops.checked = true;
// auth //
var cache = null, cache_uuid = 'adminer_auth_cache', driver_uuid = () => `adminer_${driver.value}`;
var ievent = new Event('input'), cevent = new Event('change'), sevent = new Event('submit');
var driver = form.elements['auth[driver]'], server = form.elements['auth[server]'], username = form.elements['auth[username]'], password = form.elements['auth[password]'];
if (driver) {
form.elements['auth[permanent]'].checked = true;
driver.addEventListener('change', function(event) {
if (cache === null) cache = JSON.parse( localStorage.getItem(cache_uuid) ) || {};
if (driver_uuid() in cache) {
server.value = cache[driver_uuid()][server.name] || '';
username.value = cache[driver_uuid()][username.name] || '';
password.value = cache[driver_uuid()][password.name] || '';
} else cache[driver_uuid()] = {};
cache[driver_uuid()][this.name] = this.value;
// dump(cache);
}, false);
driver.dispatchEvent(cevent);
server.addEventListener('input', function(event) {
cache[driver_uuid()][this.name] = this.value;
}, false);
username.addEventListener('input', function(event) {
cache[driver_uuid()][this.name] = this.value;
}, false);
password.addEventListener('input', function(event) {
cache[driver_uuid()][this.name] = this.value;
}, false);
form.addEventListener('submit', event => {
localStorage.setItem(cache_uuid, JSON.stringify(cache));
}, false);
}
}
// dump(z,y,x);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment