This is an extremely stupid and simple script, using GreaseMonkey and jQuery, to auto login in hkej.com ( 信報財經新聞網站 )

I am very annoyed by the site’s super duper session handler that

1. expire very soon
2. non working redirection
3. separated session handler for its forum and newspaper content
4. no ssl ( OK, I cannot help, but this means leaving credentials in GreaseMonkey will only degrade security slightly. )

Here we go :


// ==UserScript==
// @name Hacks on HKEJ
// @namespace hkej
// @description Make life easier with hkej.com
// @include http://*.hkej.com/*
// @exclude http://*.hkej.com/*/adv/*
// ==/UserScript==

// ! Private Credentials, BEWARE !
var LOGIN_EMAIL = 'nonsense@hkej.com';
var LOGIN_PASS = 'kickmyasshere';
// ! Please fill in for your own sake !

// Note : 2 FIXME
// by : lxb [at] hkday [dot] net
// ver : 0.1.003 [ 2008 Jul 25 19:08:00 ]
// ! Change Log !
// 0.1.000 [ 2008 Jul 25 18:01:12 ] : base GM + jQ ref htt://www.joanpiedra.com/jquery/greasemonkey
// 0.1.001 [ 2008 Jul 25 18:06:56 ] : add checkLogin() , use Google hosted jQuery
// 0.1.002 [ 2008 Jul 25 18:13:02 ] : checkLogin() add fail handling
// 0.1.003 [ 2008 Jul 25 19:08:00 ] : add @exclude
// - Change Log -

// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();

// Check login
function checkLogin() {

// FIXME : it may not work if hkej update itself
var login_ok = $('img#Reg_Log').attr('src').indexOf('logout') + 1;
if (!login_ok) {
// fail handling : it will show the bold message when login failed. FIXME : same as above
$('#wrapper table:first td:eq(1)')
.load('/template/registration/jsp/_login_prg.jsp #regWrap b',
{login:LOGIN_EMAIL,password:LOGIN_PASS});
}
}

// All your GM code must be inside this function
function letsJQuery() {
checkLogin();
}