Search Results for 'ajax'


System & Nethood10 Jun 2009 11:11 pm

If you don’t care about the story, here is the file, eat your own dog food to install. ( some screen shots here TwitterFox + gTranslate)

—-

After attending Barcamp Bangkok #3 , I have added some new twitter friends all over South East Asia.

In order to read their tweet, which may be in Thai, Vietnamese or whatsoever language I don’t know or that I am not quite familiar with ( such as Japanese … ) , I use the build-in translation function in Tweetdeck / Nambu in MacOS.

Problem arise when I switch to a PC, in which I am used to tweet with Twitterfox. Twitterfox does not yet have embedded translation function. Although Tweetdeck can be installed into Windows, windows itself sucks enough. I don’t what to open one more app and kick start the AIR runtime. Another reason is that Twitterfox is a firefox plug-in, I can use it in Windows, MacOS, Linux and even BSD desktop and keep similar ( err…. ) working experience.

So I decided to h… Hey! I decided to look at the change-log first .

Don’t reinvent the wheel before you hack things, that sucks.

But what I had found is the Naan Studio guys in behind, are shifting their focus on TwitterFon, another piece of software, or an iPhone App, that I use a lot. Peer comments also reveals that TwitterFox is not to be made complicated.

OK, time to hack.

First, most firefox plug-ins are just javascript and XUL files in a zipped archive. Just find out the directory path and unzip files in chrome, most likely you can read and edit the source. For my TwitterFon, the file path is somewhat like:

W:\Document and Settings\%USER%\Application Data\Mozilla\Firefox\Profiles\%your.default%\extensions\twitternotifier@naan.net\chrome

I just use Windows search to find TwitterFox.jar , and that is it.

If you have installed firefox and twitterfox, just want and dare to test my crap hack, just download my file and replace the original one. Needless to say, you don’t back up, you bare your own blame.

For me, I unzip it with 7zip , and check out what can I do.

Obviously, “content\twitternotifier.js” should be the main file for fun.

What I want to do is to

1. Add a new item to the context menu ( right click ) , like the retweet stuff.
2. Use Google translate API ( RESTful part ) to do the job.
3. make the translated result usable for retweet
4. auto detect original language ( google api takes care about it ) and user preferred language ( as set in browser )

It turns out more files are involved, including i18n thingies, for point 1, which I spend most of the time to clean up tonight.

For point 2, just read Google’s document. It is by far easier than what I used to work with ( babelfish… ) 6 years ago. I add this follow code within 30 minutes, most time are wasted for my many many bugs and typos and thus firefox restarts.

( this is added just after the retweet function )

translate: function(target) {
var tweet = target.parentNode.node;
/*I don't care what "target" is, the code in above tells me how to get the "tweet". */
var req = new XMLHttpRequest;
/* Ajax translation kind of stuff */
req.open('GET', GTranslateAPI + tweet.getAttribute('text') ,true);
/* constants have be defined in the header */
req.onreadystatechange = function(){
if(req.readyState == 1)
req.setRequestHeader('Referer', Referrer);
/* google requires developers to state the referrer, although the function would work without it*/
if(req.readyState != 4) return;
result=eval('('+req.responseText+')');
/* json stuff */
r=result.responseData.translatedText;
/* fixit: yeah I am super lazy, even there are some available functions to normalize the result, I do nothing */
t=document.createTextNode(r);
p=document.createElement('description');
p.className = "twitternotifier-message-translate";
/* add some styling, thus the CSS file is also changed */
p.appendChild(t);
tweet.appendChild(p);
/* fixit: this part is definitely sick, may be CSS problem exists */
tweet.setAttribute('text',r);
/* How DIRTY ! :DDD , translate and retweet result is that easy (3) */
};
req.send('');
},

For point 4, just read the setting of the browser is not enough. Google translate does not know ALL languages.
Even worse, it takes only first two letter in locale for most langauge. Chinese is the only exception. The worst thing ture out to be zh-HK, which I am suppose to support even though I don’t like to use, is not supported by Google Translate. Thus this is the REAL Hack, if anything in this post means to be a hack :

( in the header )

var tolang;
switch(navigator.language) {
case 'zh-TW':
case 'zh-HK':
tolang='zh-tw';
break;
default:
tolang=navigator.language.substr(0,2);
}
const GTranslateAPI = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=%7C'
+ tolang + '&q=';
const Referrer = 'http://twitterfox.net/';

And that’s it .

Wait, I have also changed the behavior of Retweet , from
RT: @someone:
to
RT @someone

What is the point for adding two colons ? Funny ? Waste two more precious digit space ?

Moreover, I add a “zh-HK” locale.
Otherwise, HK users ( not me ) will be depreciated to be broken Chinese (破體中文) readers.

( Doh!)

By the way, I know there are many many bugs as you can see in the above code snippets ( at least look at the Fixits ).
I don’t care too much, but I may update if have time.

Hope that the Naan studio guys will read this post, throw away my crap, and implement something really works.

Before that, my dog food might be good enough for you darn lazy geeks.
You can always hack it better. I hope you will notice me after tasting your own shit.

The above code is a damned deviate (dd). Never attribute me if you copy and distribute. Yet I don’t care if you make it even more horrible and throw me some tipjoy to fix it. I will NOT fix it for you. I will fix it perhaps for my own pleasure.

If your firefox is corrupted by my file, please feel free to shout out your foul words to @bencrox.

System & Nethood29 Jul 2008 09:34 pm

Last time I have shown a very simple/stupid user script to auto login hkej.com ( 信報財經新聞網站 )

In fact, what it does is not auto log in, but check if you are checked out and try to log-in once. It does not safe you ( me ) from cookie expires. Although it does re-log and so user can go back and click on the link to escape.

I find no way to manipulate cookie with GreaseMonkey directly. This is not too bad in terms of security. I don’t have to steal cookies. I just want to revive them.

1) The simplist trick is to reload the page:

window.setTimeout(window.location.reload,29min_later);

It works. But what if the user left some valuable words in forms ?
All such data will be vanished.

2) Do some minimal ajax load
I cannot sure why, but it does not work. It seems the ajax load within Greasemonkey is bounded by some shields.

3) Load some data into an iframe, and reload the iframe from time to time.
It works. Rather than expected, I can hide those iframe without anyharm.

So I rewrite the code a little bit. This time, I have also taken reference from a famous user script to handle username and password.

Wondering if I shall submit it to userscripts.org ….
Would do so if anyone interested.


// ==UserScript==
// @name Hacks on HKEJ
// @namespace info.bencrox
// @description Make life easier with hkej.com
// @include http://*.hkej.com/*
// @exclude http://*.hkej.com/*/adv/*
// @exclude http://*.hkej.com/*/login.jsp
// ==/UserScript==
	
// ! Private Credentials, BEWARE !
LOGIN_EMAIL = GM_getValue('ejregem','');
LOGIN_PASS = GM_getValue('ejregpw','');
	
// Note : lots FIXME
// by : lxb [at] hkday [dot] net
// ver : 0.1.013 [ 2008 Jul 25 20:00:04 ]
// ! 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:13:02 ] : add checkLogin() , use Google hosted jQuery
// 0.1.002 [ 2008 Jul 25 18:13:02 ] : checkLogin() add fail handling
// 0.1.003 [ 2008 Jul 27 19:02:13 ] : add excludes
// 0.1.004 [ 2008 Jul 27 22:04:20] : test window.location.reload  and GM Menu
// 0.1.005 [ 2008 Jul 27 22:07:56] : test with partial ajax reload, failed
// 0.1.006 [ 2008 Jul 27 22:13:28] : test with iframes, worked
// 0.1.007 [ 2008 Jul 28 17:35:44] : reload iframes in hidden div by setTimeout
// 0.1.008 [ 2008 Jul 29 21:50:13] : test with GM_setValue / getValue
// 0.1.009 [ 2008 Jul 30 16:02:32] : fixed GM_setValue by not using jQuery
// 0.1.010 [ 2008 Jul 30 16:04:58] : allow manual reset un/pw , blank pw  , ref : http://userscripts.org/scripts/review/16341
// 0.1.011 [ 2008 Jul 30 16:56:16]: fix re-bake loop by adding excludes and choosing better dummy pages
// 0.1.012 [ 2008 Jul 30 17:15:21]: test with extra styling / manual items
// 0.1.013 [ 2008 Jul 30 20:00:04]: clean up test codes
	
// - 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();
	
//renewCookie by fetch the smallest pieces.
//FIXME: they are not quite small... seems idiot method...
    function renewCookie() {
	$('#webifm').attr('src','http://web.hkej.com/template/registration/jsp/login.jsp');
	$('#wwwifm').attr('src','http://www.hkej.com/template/registration/jsp/login.jsp');
    }
	
//call renew cookies every 25mins
    function cookieTimeout() {
	renewCookie();
	window.setTimeout(cookieTimeout,1500000);
    }
	
//provide some way to reset Creds stored in firefox
//FIXME: tell me if I can encrypt things ... -_-
    function resetCredentials(){
		if ((LOGIN_EMAIL = prompt('Registered Email:')) != null){
			GM_setValue('ejregem',LOGIN_EMAIL);
		} else return;
		if ((LOGIN_PASS = prompt('Password (leave blank to prompt every time):')) != null){
			GM_setValue('ejregpw',LOGIN_PASS);
		}
    }
	
// Provide a button to reset Creds if login failed
    function checkLogOK(){
// FIXME: Yes, this must lead to faults afterwards
	ts = document.getElementsByTagName('b')
      if(ts.len){
// FIXME: Cannot use jQuery (GM_setValue within unsafeWindow ) here,
	resetp = document.createElement('button');
	resetp.innerHTML='Reset';
	resetp.addEventListener('click',resetCredentials,true);
	ts[0].appendChild(resetp);
      }
    }
	
// Extract the Log in Operation for manual use
    function AutoLog() {
	if (LOGIN_EMAIL == '') resetCredentials;
	if (LOGIN_PASS == '') LOGIN_PASS = prompt('Password :');
	
// FIXME : this must fail afterward, yes, yes...
	$('#wrapper table:first td:eq(1)')
	  .load('/template/registration/jsp/_login_prg.jsp #regWrap b',
		{login:LOGIN_EMAIL,password:LOGIN_PASS},checkLogOK);
	
    }
	
// Check login
function checkLogin() {
// FIXME : it may not work if hkej update itself
	var login = $('img#Reg_Log').attr('src').indexOf('logout') + 1;
	if (!login) AutoLog();
	cookieTimeout();
}
	
// Hide the cookie ovens
    function Addiframe(){
	$('<div id= "hid"></div>').appendTo('body');
	$('<iframe name="webifm" id="webifm"></iframe>').appendTo('#hid');
	$('<iframe name="wwwifm" id="wwwifm"></iframe>').appendTo('#hid');
	$('#hid').hide();
    }
	
// All your GM code must be inside this function
function letsJQuery() {
	Addiframe();
	checkLogin();
}
	
GM_registerMenuCommand('Login', AutoLog);
GM_registerMenuCommand('Reset ID',resetCredentials);
	

Have fun!

System & Nethood29 Jul 2008 03:30 pm

The ’session expires’ problem kicks me ass again. Thus I open firebug to check how can I extend life.

Adding Firecookie save my time for this task. Yet, up to version 0.6 firecookie shows expire time in GMT only.
I think not much people lives / syncs with GMT. Adding options for proper localized timezone would be nice.

Thus, I filed an issue for the developer.

For those who don’t want to wait, please locate your own ‘firecookie.js’ and s/toGMTString/toLocateString/g .
I don’t think this is a considerate hack. Bear your own risk if you are as lazy as I am.


Notes:
XPI can be upzipped… Tell you, I have not hack things for a long time. I googled decompile xpi … how stupid am i …

Notes 2:
Is that GreaseMonkey does not touch cookies anymore ?
I find that extracting content with jQuery ajax load into a div does not help, but adding a visible iframe does.

Tutorial25 Jul 2008 06:41 pm

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();
}

Uncategorized14 Nov 2007 09:10 pm

Embedded SVG

SVG as an Object

SVG in an iframe

Uncategorized& Mobile27 Oct 2007 11:46 pm

Never…
Even mounting a 16G ramdrive on my favourite server could not help leaking desire…

Now the EEEpc is my mobile object. I just want it to get things done, not necessary almighty, as long as my pocket money is limited.

I have plan to turn it into a mobile SIP phone.
( that I have access to a POTS gateway… )

EEEpc uses Atheros wifi module, that makes me to think about hostapd…. With HSDPA / 3G connection via USB, the EEEpc would be yet another 3G to Wifi AP …. ( and that is what I keep working on…. )

Before touching any setting, I want to check how many resources I have…

free and df

Hmm, as you may see, I have added a Transcend 8G SDHC, with class 6 i/o speed. That cost 500 HKD in addition….. But never mind, money is to be burnt…. At lease someone has proved SDHC can boot, what else can be better?

As I have keep reading on Gmail and Facebook, I can sure Firefox would not leave me a free mind. Around 7 ~ 9 MB is left for fun. Adding more memory will cost me the 1 yr warranty. Should I ever care about that ???

A brief scan on the memory assigned uncover SCIM. Huhhh ? I am still out of the advantage it provides… It is tempting to have it be killed…. as long as I am working on ajaxime ….

Scripting on EEEpc ? That’s fine, I just want to add “irb” to the existing ruby-1.8.5 … errr , may be 1.8.6+ tomorrow. GCC 4.1 is not my choice, yet an upgrade to 4.2 is not necessary as well. Perl 5.8.8 , that’s OK, except that I may not have time to play with perl. Nawk/awk ? nice. lisp/clisp is not there.

I am not greedy at all… to sum it up:

1. I want to try out the Atheros Wifi module… in additional, add 3G router functionality that I often have to use.

2. I want to have a ruby playground. A term with bigger fonts and having irb installed, will be go enough.

System & Nethood12 Oct 2007 06:13 pm

/*@cc_on _d=document;eval(’var document=_d’)@*/

剛才逛 BBS 時﹐看到 DarkKiller 提到這個 Link :

http://d.hatena.ne.jp/amachang/20071010/1192012056

啥屁?改一改 dom 根元﹐可以讓 IE 大大提升 javascript 的效率?

我把 test script 抄到這裏(請用 IE 打開)﹐實地測試一下﹐發覺真有其事!

一次測試算不了甚麼﹐我跑 script 做了五百次﹐並做了一點點 control test ﹐看到結果﹐無話可說:真有其事耶……

( Control test 超級簡單﹐方法一﹐是把那個 one liner 去掉﹐看看是否 cache 效率。方法二是把 one liner 改為較次要的東西﹐或用 document 底下的子元來做實驗。結論是……真有其事。)

我測的是 IE6 ﹐由於不想安裝 IE7 ﹐請各位自行測試了。

如果覺得太神奇﹐可以試試把這個 link 拉做 bookmarklet ﹐長伴 ie 左右。( 要是有 memory leak 之類的副作用﹐恕不負責)

IE 跑 Editgrid 向來慢如龜﹐如果誰有空閒﹐可以試試這一招能否助以加速。

hkday& System & Nethood09 Aug 2007 12:51 pm

李小龍打功夫,有他的哲學,所以他敢於把截拳提升到「道」的層次。

我們掛著「功夫」這個招牌,去開發輸入法,雖然一切尚待發展和摸索,但也不能缺了一套指導邏輯。

與其外求,倒不如就在中國功夫裡找邏輯。

我曾聽聞過詠春拳、蔡李佛以及八極拳當中的一些道理,有些東西是很值得參考的。

就以截拳道的源頭,詠春拳為例,他們把武術思想精粹,去蕪存菁,歸為三個要點:尋橋、標指、小念頭。

尋橋是最容易理解的,就是找尋自身和對手之間,最直最快的接觸點,若巡這個向方發力攻擊,就會比對方快。

而我們搞輸入法,腦裏的念頭和電腦接收顯示得了的字,中間就有一個輸入和處理的過程。處於不同的環境,尤其是現代人們到處流動,到處工作,我們就要有個方法,總是把念頭到輸出間的距離,有效地接駁起來。

是故使用 Ajax 只是一種招式,而不是一套武學。要達成一套武學,就要有凌架、掌管招式運用的武學思想。現在我們在練基本功,使每一招都變得紮實可用(好比詠春拳首先要處理好「小念頭」)。長遠而言,我們要掌握多些招式,以及使招式可以連貫到每一個環境的套路,以及可以靈活運用套路,總是得以「尋橋」的發揮空間。

Robotics, A.I. , N.N.19 Jul 2007 01:29 am

Crazy ideas are non stoppable.

Thanks to Angus of 852signal.com , now there are some blogs talking about our GownFull project.

I have to salute to all friendly peers, at that same time to drive to more advanced stages.

Having traditional IME anywhere is convenient, then how about leaping to a cyber world?

We are not sticking to the keyboard. The development team and people in our google groups are most likely impressed by Taku’s stroke recognition method. We have planned to extend it.

Moreover, I have shown an example of completing phase by Google suggest. That’s not cyber enough. Why are we bond to start input by hand?

To make input as a collaboration, we have to link minds together. Yeah, that’s it, directly accessing people’s mind. Mind scanning cannot be done without super equipment, but we can have some fuzzy logic to mimic people’s mind. With some data input, we can work out an augmented mind processor.

We have many input component in our PC, not all working with your hand. With some crypto tricks, these input can be reform to help the remote side to understand what are there. The remote side computer will do the complicated processing and translation, and finally feed back something, such as a list of guesses. That might be what you really want to input.

I was once planning to make an interpretor for web based video conferencing. But people think that I am just too crazy. Fine, now I can work with simple IME. But the ideas are still sparkling in my mind. There shall be one day all guys giving up traditional input methods. It is because input methods are redundant. You already have all the words in your mind, you already show it off in a dialog. Track back to the ancient times, people don’t even know about writing. Yet they can communicate with each other!

You know it, IME shall evolve !

System & Nethood17 Jul 2007 07:29 pm

Oh yes, our team have started to work on this crazy idea. It works, as you can see in below. But we have to do more fine tuning!

GFsuggest

By mashing up GownFull with Google Suggest, we hereby shows why Ajaxime have more fun than traditional Input Methods.


Listed on BlogShares