Thursday, July 30, 2009

MAL h4x

A while back, I wrote a GreaseMonkey script for MyAnimeList.net to allow me to easily search IQDB for any given club picture. This was necessary because MAL resamples club pictures to a smaller size and doesn't keep the full size version (kind of like Facebook). After perfecting the script, I put it up online so that anyone who wanted it could get it, and linked it from both my MAL profile and a thread I made in MAL's forums with a few screenshots.

Today I was bored and said to myself, "Well, the IQDB search is currently hard-coded to happen in a new tab. But what if some random user using the script would rather it happen in the current tab?"

I investigated a solution, and a victory was had. GreaseMonkey's way of handling user script preferences is rather cumbersome (first prompt for what it should be, get new input, validate new input, store new input, and the functions to get and set a variable can't be called from anywhere other than the user script for security reasons), I avoided the issue entirely by integrating it into the site just as smoothly as the original "Look up on IQDB" link was, and storing the preference in a cookie.

That's right, I added a field to the Edit Profile page. It's a dropdown that lets you select your desired behavior. By default it uses the old behavior of searching in a new tab, this works even if you haven't visited your preferences page and set your cookie yet. To set it, you change the dropdown and hit Save Changes at the bottom, just like with any other preferences change. Pretty neat, huh?

To accomplish this, I had to inject a small bit of Javascript into the page. This small bit is simply a remote script load from my subdomain of desudesudesu.org. That script hooks the onload event so that it can hook the "Save Changes" button's onclick event, and takes care of getting the dropdown's value and setting that in the cookie when the button is clicked.

The only real issue with the cookie implementation is that all cookies have an expiration time and date, and some users run extra software to further mess with them. Currently the cookie expires one year after it's set or changed, which I figured was far enough into the future. I was going to try to set it to the end of time, i.e. 3:14:07 AM on Tuesday, January 19th, 2038; but that would take more effort and might trigger any anti-tracking cookie stuff people might have installed. Oddly enough, this is what cookies were meant to be used for.

If you're a MAL user and want the script, you can get it here. Just to remind you, you'll have to install the GreaseMonkey Firefox extension linked above to actually use it. Enjoy.

Holy shit I just found out that, defying all logic, instead of bringing in their backup/test driver Marc Gene, Ferrari is bringing in none other than 7 time world champion Michael Schumacher to replace Felipe Massa. Now, logic has hardly ever applied to Formula 1 or Ferrari, but... Schumi coming out of retirement to sub for Massa? Really? I knew he still worked for Ferrari, but... This ought to make the rest of the season interesting.

No comments:

Post a Comment

I moderate comments because when Blogger originally implemented a spam filter it wouldn't work without comment moderation enabled. So if your comment doesn't show up right away, that would be why.