Skip to content

Instantly share code, notes, and snippets.

@Erutan409
Last active July 25, 2016 01:59
Show Gist options
  • Save Erutan409/df0041a662d5df72dec809868d11ebb7 to your computer and use it in GitHub Desktop.
Save Erutan409/df0041a662d5df72dec809868d11ebb7 to your computer and use it in GitHub Desktop.
phpMyAdmin - Bookmarklet for quickly selecting database(s) on a search string
/**
* Will not select system databases (greyed out)
* Works with regular expressions:
* '^te' -> matches 'test' database
* '^est' -> will NOT match 'test' database
*
* I created this to easily drop numerous databases
* that are part of a large system, such as 'phabricator.'
*/
// code to save as a bookmark
javascript:(function(){var checkOn=0,checkOff=0,search=prompt("Database(s) to toggle checkbox?").trim();""==search&&(search=".*"),search=eval("/"+search+"/i"),$(".name").each(function(c){if($(this).find("a").text().match(search)){var e=$(this).parent().find(".checkall");if(!e.is(":disabled")){var a=!e.prop("checked");e.prop("checked",a),checkOn+=1==a,checkOff+=0==a}}});var msg="";checkOn&&(msg+="Selected: "+checkOn),checkOff&&(msg+=(msg?"\n":"")+"Unselected: "+checkOff),alert(msg);})();
// un-minified code
var checkOn = 0
,checkOff = 0
,search = (prompt("Database(s) to toggle checkbox?")).trim();
if (search == "") {search = ".*";}
search = eval('/'+search+'/i');
$(".name").each(function(index) {
if ($(this).find("a").text().match(search)) {
var checkbox = $(this).parent().find(".checkall");
if (!checkbox.is(":disabled")) {
var state = !checkbox.prop("checked");
checkbox.prop("checked", state);
checkOn += (true == state);
checkOff += (false == state);
}
}
});
var msg = "";
if (checkOn) {msg += "Selected: "+ checkOn;}
if (checkOff) {msg += (msg?"\n":"")+"Unselected: "+ checkOff;}
alert(msg);
@Erutan409
Copy link
Author

Erutan409 commented Jun 6, 2016

Added alert noting what was selected/unselected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment