Created
February 14, 2017 23:46
-
-
Save samtay/4fb8e78513395971dbefb69ee6583b63 to your computer and use it in GitHub Desktop.
Tamper Monkey script to automatically log into Magento2 admin panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Local Login - M2 | |
// @namespace http://your.homepage/ | |
// @version 0.1 | |
// @description enter something useful | |
// @author Sam Tay | |
// @match *.dev/*admin* | |
// ==/UserScript== | |
// Credentials | |
var username = 'admin', | |
password = 'pass4admin'; | |
// On load, wait for jQuery to come on board, then login | |
timer(); | |
function timer() { | |
if (typeof jQuery === "function") { | |
login(jQuery); | |
} else { | |
setTimeout(timer, 200); | |
} | |
} | |
// Pass login credentials and submit form | |
function login($) { | |
if ($('body.adminhtml-auth-login').length) { | |
try { | |
showPopup($); | |
} catch(err) { | |
console.log(err); | |
} | |
$('#username').val('admin'); | |
$('#login').val('pass4admin'); | |
$('#login-form').submit(); | |
} | |
} | |
// Pop up for tamper monkey, not very important | |
function showPopup($){ | |
var docHeight = $(window).width(); | |
$("body").append("<div id='overlay'></div><div id='login-message'>Logging in with Tampermonkey...</div>"); | |
$("#overlay") | |
.css({ | |
'height' : docHeight + 'px', | |
'opacity' : 0.4, | |
'position': 'absolute', | |
'top': 0, | |
'left': 0, | |
'backgroundColor': 'black', | |
'width': '100%', | |
'zIndex': 5000 | |
}); | |
$("#login-message") | |
.css({ | |
'height' : '80px', | |
'position': 'absolute', | |
'backgroundColor': 'white', | |
'width': '200px', | |
'zIndex': 5001, | |
'padding': '20px', | |
'border': '5px solid black' | |
}); | |
var vpWidth = $(window).width(); | |
var width = $("#login-message").width(); | |
var avLeft = (vpWidth / 2) - (width / 2) + 'px'; | |
var vpHeight = $(window).height(); | |
var height = $("#login-message").height(); | |
var scrollTop = $(window).scrollTop(); | |
var avTop = (vpHeight / 2) - (height / 2) + scrollTop + 'px'; | |
$("#login-message") | |
.css({ | |
'top': avTop, | |
'left': avLeft | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great in Magento 2.2.3, thanks Sam!