Skip to content

Instantly share code, notes, and snippets.

@TK009
Created October 5, 2014 01:10
Show Gist options
  • Select an option

  • Save TK009/6ea713fdc0c99ccea746 to your computer and use it in GitHub Desktop.

Select an option

Save TK009/6ea713fdc0c99ccea746 to your computer and use it in GitHub Desktop.
login with (firefox) remembered mal account data automatically, also ultimate destination for animelist.
// ==UserScript==
// @name mal_auto_login
// @namespace tkscripts
// @description login with (firefox) remembered mal account data automatically, also ultimate destination for animelist
// @include http://myanimelist.net/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @version 1.1
// @grant none
// ==/UserScript==
// Author: Tuomas Kinnunen
// This is GreaseMonkey UserScript for firefox
//THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
// NOTE: You can't log out when this is on.
this.$ = this.jQuery = jQuery.noConflict(true);
$(function() {
function test(target) {
return typeof target !== "undefined" && target !== null
}
function gotoLogin(loginLink){
if (test(loginLink)) {
console.log('mal autologin: loggin in with link: ' + loginLink);
window.location.href = loginLink;
}
}
function tryLogin() {
var form = $('form[action="http://myanimelist.net/login.php"]');
console.log('mal autologin: try login');
if ($('input[name="username"]').val().length > 0
&& $('input[name="password"]').val().length > 0) {
console.log('mal autologin: submitting');
form.submit();
return true;
} else {
return false;
}
};
var pageurl = window.location.href;
if (pageurl.startsWith("http://myanimelist.net/animelist/")) {
// save ultimate destination
window.sessionStorage.udestination = window.location.href;
// should be ok even if mal makes minor updates
var loginLink = $('a:contains("Login"),a:contains("Log in")').attr('href');
gotoLogin(loginLink);
} else if (pageurl.startsWith("http://myanimelist.net/panel.php")) {
// Login ends up here; execute ultimate destination
if (test(window.sessionStorage.udestination)) {
var dest = window.sessionStorage.udestination;
console.log('mal autologin: go to ultimate destination: ' + dest);
delete window.sessionStorage.udestination;
window.location.href = dest;
}
} else if (pageurl.startsWith("http://myanimelist.net/login.php")) {
if (tryLogin()) return;
// not sure if this is needed; it's for waiting that browser inserts the user and pass.
window.setTimeout(tryLogin, 120);
} else if (pageurl.startsWith("http://myanimelist.net/ajaxtb.php")) {
if (tryLogin()) return;
// not sure if this is needed; it's for waiting that browser inserts the user and pass.
window.setTimeout(tryLogin, 120);
} else {
var loginLink = $('a:contains("Login"),a:contains("Log in")').attr('href');
gotoLogin(loginLink);
}
});
@unknown--
Copy link

Nice script. It should return the user to the page they were on previously though.

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