Tutorial


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

Tutorial20 Nov 2005 06:33 pm

用 GD 畫圖﹐概念如下:

1) 開一版畫板物件
2.a) 讀取相關的資源﹐如字形、碎圖等等
2.b) 設定畫板的色盤
3) 一般畫圖操作
3.a) 設定底色 / 底圖
4) 把畫板格式化 (即譯為 jpeg , png, gif 之類的格式) ﹐並置入檔案 ( 即 file io )
5) 為了幸福和快樂﹐趕快洗腦

若果直接通過 php 輸出到 web ,則要在額頭上鑿個字號﹐例如:


Header("Content-type: image/gif");

用 GD 可以做到的﹐通常是 加蓋水印 ﹐拼字串、檢字體之類﹐沒甚麼事就不要動態執行﹐做好了的檔案放到過期便算數﹐以免開了網頁招來大量人流﹐傻呼呼地扯系統資源。

php - image 的相關 Docs :
1) http://hk.php.net/manual/en/ref.image.php
2) http://www.boutell.com/gd/manual2.0.33.html#reference

Tutorial23 Jul 2005 04:28 pm

給阿傳:

我相信你學曉以下三項技巧﹐便可以有效地做網頁

a) unix server 操作

a.1 由於會使用 ssh 登入 server ﹐請先到 putty 下載頁 - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html﹐下載 putty 到 Desktop 上。

a.2 Putty 不用額外 install ﹐請儲存到 Desktop ﹐( 亦即如 C:\Documents and Settings\yourname\Desktop\ 的目錄 ) ﹐這樣子比較方便。

a.3 Double Click 開動 Putty ﹐在 Host Name 一欄上填上 server 名﹐比如是 01power.net

a.3.1 為了方便日後工作﹐你可以在 Saved Sessions 下邊的空格﹐填入一個 profile 名﹐比如是 01power ﹐然後按右邊的 Save 按鈕。那樣﹐中間的大方框中﹐應會有該 profile 的欄目。以後﹐只要 Double Click 這個欄目﹐便可以登入

a.4 Click 右下角的 Open ﹐就會打開一個黑底的畫面﹐我們稱之為 console 。

a.5 輸入你的 id ﹐以及 password 。如果 password 錯了﹐可以再輸入﹐但如果 id 入錯了﹐請關了 putty ﹐由 a.3 開始重新。

a.6 相關的指令﹐我會慢慢教﹐先玩熟 man lscd exit 再算吧。

b) ftp 操作

我建議直接學 sftp ﹐倒是 Henry 說 ftp 習慣了再說﹐我不反對。介面上﹐兩者分別不大。

b.1 Henry 建議用的軟件是 CoreFTP ﹐可以在這個 link 直接下載 http://www.coreftp.com/dl/coreftplite1.3.exe

b.2 詳細的使用方便﹐請教 Henry 吧。我相信你也會摸明白﹐不贅。

c) 修改技巧

c.1 下載樣板

目前你已知道想用甚麼網站做樣版﹐去改成甚麼內容﹐那第一步就是把整樣版下載下來。

為了方便以後的工作﹐我只告訴你怎在 unix server 上大量下載﹐再用 ftp 把內容搬到私人電腦。如果你懂得更直接的方法﹐那也做一下練習吧。

c.1.1 用 ssh 連上 unix account

c.1.2 下指令把整個網站相關的檔案都下載回來:
wget -r http://your.target.name/path/

wget 指令的用法﹐請參考 man wget 。your.target.name 只是個隨便安的 url 代名﹐並沒有意思。

c.1.3 如無意外﹐該會抓到很多檔案﹐存了在 your.target.name 目錄裏。你可以直接進去修改﹐但是﹐目前你還是把整個目錄﹐用 ftp 下載回 local 電腦再改吧。

c.2 在 local 修改

c.2.1 首頁的設定﹐通常是 index.* ﹐你可以用 frontpage / dreamweaver 去改。可惜我只是 notepad 熟手﹐這方面不能給你多少援助。

用 notepad 去開﹐有助認識 html 語法和格局﹐但通常不方便工作。

c.2.2 圖片格式﹐通常是 *.jpg *.gif *.png ﹐修改完了﹐最好不要另存作別的格式。還有﹐請注意檔名大小寫﹐網頁上指定的﹐要跟圖檔的檔名一模一樣。

c.2.3 都修好了﹐請用 browser 開啟 index ﹐確定東西都能看。

c.3 上載

c.3.1 用 ftp 工具﹐把修好的東西﹐整個目錄上載到你的 unix account 的 www 目錄之內。

c.3.2 在 console 檢查一下﹐有沒有正確的讀寫權限。

相關的指令是 ls -l 和 chmod ﹐請用 man 查閱指令內容 。

c.3.3 如何意外﹐你可以在經互聯網﹐在網頁上直接看到修好的東西。

chuen@01power 的網頁就在 http://01power.net/~chuen/


Listed on BlogShares