FDZ Title Find

// ==UserScript==
// @name           FDZ Title Find
// @description    自動搜尋指定文章標題並上色
// @include        http://forum.fdzone.org/forumdisplay.php?fid=99*
// @include        http://forum.*.fdzone.org/forumdisplay.php?fid=99*
// ==/UserScript==
//v1.0    初步架構完成

function JustDoIt() {
    //指定字串
    var searchTitleStrs = ["SMG", "MU", "MEGAUPLOAD", "MULTIUPLOAD", "XUITE", "FB", "多免空", "JDOWNLOADER", "1080"];
    var titles = document.getElementsByTagName('span');
    var i, j, titleSt, catchStart, tmpCopy;

    //找出全部文章標題
    for (i = 0; i < titles.length; i++) {
        if (titles[i].id.indexOf('thread_') != -1) {
            //取出文章標題超連結文字
            titleStr = titles[i].children[0].innerHTML.toUpperCase();
            //比對指定字串
            for (j = 0; j < searchTitleStrs.length; j++) {
                if (titleStr.indexOf(searchTitleStrs[j]) != -1) {
                    //抓出起始位置
                    catchStart = titleStr.indexOf(searchTitleStrs[j]);
                    //複製標題後半部字串(從關鍵字串開始)
                    tmpCopy = titleStr.substring(catchStart);
                    //取代清空後半部字串
                    titles[i].children[0].innerHTML = titleStr.replace(tmpCopy, '');
                    //插入上色關鍵字
                    var h = document.createElement('span');
                    h.style.color = '#000';
                    h.style.backgroundColor = '#FBED73';
                    h.appendChild(document.createTextNode(searchTitleStrs[j]));
                    titles[i].children[0].appendChild(h);
                    //補上後半部字串(扣掉關鍵字)
                    titles[i].children[0].appendChild(document.createTextNode(tmpCopy.substring(searchTitleStrs[j].length)));
                    break;
                }
            }
        }
    }
}
JustDoIt();