steven80 / HKGoldenEmoji

// ==UserScript==
// @name         HKGoldenEmoji
// @namespace    http://hkgolden.com/
// @version      0.5
// @description  Insert alternative emojis in hkgolden.com
// @author       steven80
// @match        http*://*.hkgolden.com/*
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    var suffix = String(Math.floor((Math.random() * 100000) + 1));
    var queryString = {};
    location.search.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) { queryString[decodeURIComponent($1)] = decodeURIComponent($3); });
    var isMobile = /^m[0-9]+\.hkgolden\.com$/.test(location.hostname);

    if (typeof (jQuery) === 'undefined' && !document.getElementById('j'+suffix)) {
        var scriptTag = document.createElement('script');
        scriptTag.setAttribute('type', 'text/javascript');
        scriptTag.setAttribute('id', 'j'+suffix);
        scriptTag.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js');
        document.body.append(scriptTag);
    }
    var init = function(){
        if (typeof (jQuery) === 'undefined') {
            return setTimeout(init, 500);
        }
        if ($('#p'+suffix).length) {
            return;
        }
        (function($){
            if (typeof insertemoji !== 'undefined') {
                var imgList = {};
                var tbl = $('<div data-p'+suffix+'="default" style="padding-bottom:5px;border-top:1px dashed #ccc;">');
                var aList = $('a[href^="javascript:insertemoji("]>img[src^="faces/"],a[href^="javascript:insertemoji("]>img[src^="/faces/"]').each(function(){
                    var img = $(this), imgSrc = ( /^(?:|\/)faces\/(?:|.+\/)([^/]+\.gif)$/.exec(img.attr('src')) || [] )[1];
                    var a = img.parent(), imgCode = ( /^javascript:insertemoji\('([^']+)'(?:|,false)\)$/.exec(a.attr('href')) || [] )[1];
                    if (!imgSrc || !imgCode || imgList[imgSrc]) return;
                    imgList[imgSrc] = imgCode;
                }).parent();
                tbl.insertBefore(aList.first());
                aList.appendTo(tbl);
                if (!aList.length) return;
                /*var txt = [];
            $.each(imgList,function(src,code){
                var a1 = 'a'.charCodeAt(0), a2 = 'z'.charCodeAt(0);
                for (var i = a1; i <= a2; i++) {
                    for (var j = a1; j <= a2; j++) {
                        var altCode = code+String.fromCharCode(i)+String.fromCharCode(j);
                        txt.push(altCode.split('').join(' ')+' '+altCode);
                    }
                }
            });
            insertemoji(txt.join('\n'),false);*/
                var html = [], btnHtml = [], iconSet = {
                    al: 'alpaca',
                    dw: 'draw',
                    fr: 'frozen',
                    g: 'ghost',
                    lm: 'lomore',
                    px: 'pixel'
                };
                btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#69f;border-top-left-radius:5px;border-top-right-radius:5px;overflow:hidden;background:linear-gradient(#def,#69f);" data-t',suffix,'="default"><img src="/faces/cry.gif" style="border:none;height:20px;"></a>'].join(''));
                $.each(iconSet,function(alt,altPath){
                    var altHtml = [];
                    for (var src in imgList) {
                        var code = imgList[src];
                        var newSrc = 'faces/'+altPath+'/'+src;
                        if ($('img[src="'+newSrc+'"]:visible,img[src="/'+newSrc+'"]:visible').length) return;
                        altHtml.push(['<a href="javascript:insertemoji(\'',(code+alt).replace('\'','\\\''),'\',false)">',
                                      '<img style="border:none;margin-right:5px;margin-bottom:5px;" src="/',newSrc,'" alt="',code,alt,
                                      '" onerror="$(this).parent().remove()"></a>'].join(''));
                    }
                    html.push(['<div data-p',suffix,'="',alt,'" style="display:none;padding-bottom:5px;border-top:1px dashed #ccc;">',altHtml.join(''),'</div>'].join(''));
                    btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#def;border-top-left-radius:5px;border-top-right-radius:5px;overflow:hidden;background:linear-gradient(#fff,#def);" data-t',suffix,'="',alt,'"><img src="/faces/',altPath,'/cry.gif" style="border:none;height:20px;"></a>'].join(''));
                });
                var others = {
                    threed: ['http://vignette2.wikia.nocookie.net/evchk/images/6/62/Clown-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/0/08/Gunfire-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/c/ca/Chickenrun2.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/8/8d/369-ani-B1.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/a/a3/Clownhaha-ani1a.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/9/9b/Clown-cry-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/b9/Chickenfly-aniA2.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/3/3e/Clownlei-ani-a2.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/eb/Clown-sosad-ani2.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/5/5f/Hehehe1a.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/65/Op-ani1a.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/c/c0/Censor1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/d/d7/Yeah-ani-b2.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/f/f7/MrX1a.gif/revision/latest/scale-to-height-down/40'],
                    large: ['http://vignette3.wikia.nocookie.net/evchk/images/7/7d/G-icon01_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/3/3d/G-icon02_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/0/0a/G-icon03_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/0/09/G-icon04_resize.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/0/00/G-icon05_resize.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/7/73/G-icon06_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/5/55/G-icon07_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/6/6a/G-icon08_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/4/44/G-icon09_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/1/1b/G-icon10_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/a/ae/G-icon11_resize.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/2/21/G-icon12_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/1/19/G-icon13_resize.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/8/85/G-icon14_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/c/ce/G-icon15_resize.gif/revision/latest/scale-to-height-down/40'],
                    xmas: ['http://vignette4.wikia.nocookie.net/evchk/images/c/c1/Frown_xmas.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/e/e4/Clown_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/7/70/369_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/b5/%40_%40_xmas.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/f/f2/Grin_xmas.png/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/e/ed/Kiss_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/35/Love_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/9/96/Oh_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/8a/Smile_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/e8/Wink_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/9/97/Wonder_xmas.png/revision/latest/scale-to-height-down/40'],
                    greenmod: ['http://vignette1.wikia.nocookie.net/evchk/images/a/a4/Hohopaperfigure.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/5/57/Bouncer_vampire.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/6/6a/Bloodya.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/0/08/61990123_edited.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/83/Ohpaperfigure.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/bc/Lmgagree.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/61/Ghostnomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/2/29/Skelenomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/a/ab/Blockarmnomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/a/a9/Byeghost.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/b0/Goodo.png/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/8/8a/Mummynomore.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/be/N40115HELLj87.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/3b/Skele2nomore.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/3/36/Surpriseeye.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/86/Tongue2.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/5/5b/Tongue2.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/d/d9/Vampnomore.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/4/4a/K377191o130.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/b/b7/TaoistLM-1-.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/c/c0/Th_78eb9b27ac07cd1c5dd48bfbd613df5e.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a8/Footandnomore.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/4/46/Brain.jpg/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/bb/NomoreP.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/9/9c/Soinchlm.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/1/12/Lmxrayicon.gif/revision/latest/scale-to-height-down/40'],
                    handmade: ['http://vignette2.wikia.nocookie.net/evchk/images/5/55/Sosad-369.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/b9/2010818205939156567860.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/35/369face.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/2/27/Ass3.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/65/AssC.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/b/bc/Bounsad.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a9/Hahaha.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/9/98/Sogood.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a5/Soft_plastic.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/eb/Clownbouncer.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/e/e9/369bye.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/5/55/CBye.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/3/39/Sosading.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/1/18/Yup.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/2/23/Peannis.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/1/12/Scary4.gif/revision/latest/scale-to-height-down/40'],
                    whanwhan: ['http://vignette2.wikia.nocookie.net/evchk/images/d/dd/Ww_ai.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/b/b5/Ww_angry.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/d/d7/Ww_beat.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/2/20/Ww_bye.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/7/7e/Ww_chicken.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/1/12/Ww_clown.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/5/51/Ww_crash.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/c/cf/Ww_cry.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/0/08/Ww_dam.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/7/78/Ww_dead.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/a/a8/Ww_good.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/6/63/Ww_happy.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/7/77/Ww_hot.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/c/c8/Ww_laugh.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/9/97/Ww_man.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/4/40/Ww_moster.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/f/fb/Ww_oh.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/0/03/Ww_photo.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/e/e0/Ww_pity.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/1/18/Ww_plastic.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/7/79/Ww_shock.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/8/82/Ww_shocking.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/9/97/Ww_yee.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/d/d7/Ww_yo.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/d/dc/Ww_what.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/3/33/Zkl6kj.gif/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/0/08/1132814493_copy.jpg/revision/latest/scale-to-height-down/80'],
                    bugs: ['http://vignette2.wikia.nocookie.net/evchk/images/2/2c/Locust_bye.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/b/ba/Locust_sleep.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/3/30/Locust_fear.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/6/68/Locust_adore.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/7/77/Locust_no.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/2/29/Locust_wonder2.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/5/53/Locust_fxxk.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/2/22/Locust_banghead.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/0/00/Locust_bouncer.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/d/d3/Locust_bouncy.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/d/d5/Locust_censored.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/6/62/Locust_flowerface.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/7/75/Locust_offtopic.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/f/f6/Locust_shocking.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/2/24/Locust_photo.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/5/54/Bee_sosad.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/6/64/Locust_yipes.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/e/e2/Locust_369.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/2/2e/Locust_bomb.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/a/a2/Locust_slick.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/c/cd/Locust_thumbUp.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/3/30/Locust_thumbDown.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/1/12/Locust_offtopic_chinaflag.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/e/e2/Locust_birth.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/3/3f/Nomorelick.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/a/ab/Nomoreo.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/4/46/Nomorecry.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/a/a9/QdlyD.gif/revision/latest/scale-to-height-down/30'],
                    bittersmile: ['http://i.imgur.com/Oh4QGVs.gif']
                };
                $.each(others,function(alt,altList){
                    var altHtml = [];
                    $.each(altList,function(i,newSrc){
                        altHtml.push(['<a href="javascript:insertemoji(\'[img]',newSrc,'[/img]\')">',
                                      '<img style="border:none;margin-right:5px;margin-bottom:5px;" src="',newSrc,'" onerror="$(this).parent().remove()"></a>'].join(''));
                    });
                    html.push(['<div data-p',suffix,'="',alt,'" style="display:none;padding-bottom:5px;border-top:1px dashed #ccc;">',altHtml.join(''),'</div>'].join(''));
                    btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#def;border-top-left-radius:5px;border-top-right-radius:5px;overflow:hidden;background:linear-gradient(#fff,#def);" data-t',suffix,'="',alt,'"><img src="',altList[0],'" style="border:none;height:20px;"></a>'].join(''));
                });
                $(btnHtml.join('')).insertBefore(tbl);
                $(html.join('')).insertAfter(tbl);
                $(document).on('click','[data-t'+suffix+']',function(){
                    var trg = $(this).attr('data-t'+suffix);
                    $('[data-t'+suffix+']').each(function(){
                        var button = $(this);
                        button.css('background',button.attr('data-t'+suffix) == trg ? '#69f' : '#def');
                    });
                    $('[data-p'+suffix+']').each(function(){
                        var panel = $(this);
                        panel.toggle(panel.attr('data-p'+suffix) == trg);
                    });
                });
            }
            else if (typeof InsertText !== 'undefined') {
                var imgList = {};
                var tbl = $('a[href^="javascript:InsertText("]>img[src^="faces/"],a[href^="javascript:InsertText("]>img[src^="/faces/"]').each(function(){
                    var img = $(this), imgSrc = ( /^(?:|\/)faces\/(?:|.+\/)([^/]+\.gif)$/.exec(img.attr('src')) || [] )[1];
                    var a = img.parent(), imgCode = ( /^javascript:InsertText\('([^']+)'(?:|,false)\)$/.exec(a.attr('href')) || [] )[1];
                    if (!imgSrc || !imgCode || imgList[imgSrc]) return;
                    imgList[imgSrc] = imgCode;
                }).first().closest('table').wrap('<div data-p'+suffix+'="default" style="padding-bottom:5px;border-top:1px dashed #ccc;">').parent();
                if (!tbl.length) return;
                /*var txt = [];
            $.each(imgList,function(src,code){
                var a1 = 'a'.charCodeAt(0), a2 = 'z'.charCodeAt(0);
                for (var i = a1; i <= a2; i++) {
                    for (var j = a1; j <= a2; j++) {
                        var altCode = code+String.fromCharCode(i)+String.fromCharCode(j);
                        txt.push(altCode.split('').join(' ')+' '+altCode);
                    }
                }
            });
            InsertText(txt.join('\n'),false);*/
                var html = [], btnHtml = [], iconSet = {
                    al: 'alpaca',
                    dw: 'draw',
                    fr: 'frozen',
                    g: 'ghost',
                    lm: 'lomore',
                    px: 'pixel'
                };
                btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#69f;border-top-left-radius:5px;border-top-right-radius:5px;background:linear-gradient(#def,#69f);" data-t',suffix,'="default"><img src="/faces/cry.gif" style="border:none;height:20px;"></a>'].join(''));
                $.each(iconSet,function(alt,altPath){
                    var altHtml = [];
                    for (var src in imgList) {
                        var code = imgList[src];
                        var newSrc = 'faces/'+altPath+'/'+src;
                        if ($('img[src="'+newSrc+'"]:visible,img[src="/'+newSrc+'"]:visible').length) return;
                        altHtml.push(['<a href="javascript:InsertText(\'',(code+alt).replace('\'','\\\''),'\')">',
                                      '<img style="border:none;margin-right:5px;margin-bottom:5px;" src="/',newSrc,'" alt="',code,alt,'" onerror="$(this).parent().remove()"></a>'].join(''));
                    }
                    html.push(['<div data-p',suffix,'="',alt,'" style="display:none;padding-bottom:5px;border-top:1px dashed #ccc;">',altHtml.join(''),'</div>'].join(''));
                    btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#def;border-top-left-radius:5px;border-top-right-radius:5px;background:linear-gradient(#fff,#def);" data-t',suffix,'="',alt,'"><img src="/faces/',altPath,'/cry.gif" style="border:none;height:20px;"></a>'].join(''));
                });
                var others = {
                    threed: ['http://vignette2.wikia.nocookie.net/evchk/images/6/62/Clown-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/0/08/Gunfire-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/c/ca/Chickenrun2.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/8/8d/369-ani-B1.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/a/a3/Clownhaha-ani1a.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/9/9b/Clown-cry-ani-A1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/b9/Chickenfly-aniA2.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/3/3e/Clownlei-ani-a2.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/eb/Clown-sosad-ani2.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/5/5f/Hehehe1a.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/65/Op-ani1a.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/c/c0/Censor1a.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/d/d7/Yeah-ani-b2.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/f/f7/MrX1a.gif/revision/latest/scale-to-height-down/40'],
                    large: ['http://vignette3.wikia.nocookie.net/evchk/images/7/7d/G-icon01_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/3/3d/G-icon02_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/0/0a/G-icon03_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/0/09/G-icon04_resize.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/0/00/G-icon05_resize.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/7/73/G-icon06_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/5/55/G-icon07_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/6/6a/G-icon08_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/4/44/G-icon09_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/1/1b/G-icon10_resize.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/a/ae/G-icon11_resize.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/2/21/G-icon12_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/1/19/G-icon13_resize.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/8/85/G-icon14_resize.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/c/ce/G-icon15_resize.gif/revision/latest/scale-to-height-down/40'],
                    xmas: ['http://vignette4.wikia.nocookie.net/evchk/images/c/c1/Frown_xmas.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/e/e4/Clown_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/7/70/369_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/b5/%40_%40_xmas.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/f/f2/Grin_xmas.png/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/e/ed/Kiss_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/35/Love_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/9/96/Oh_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/8a/Smile_xmas.png/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/e8/Wink_xmas.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/9/97/Wonder_xmas.png/revision/latest/scale-to-height-down/40'],
                    greenmod: ['http://vignette1.wikia.nocookie.net/evchk/images/a/a4/Hohopaperfigure.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/5/57/Bouncer_vampire.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/6/6a/Bloodya.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/0/08/61990123_edited.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/83/Ohpaperfigure.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/bc/Lmgagree.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/61/Ghostnomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/2/29/Skelenomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/a/ab/Blockarmnomore.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/a/a9/Byeghost.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/b0/Goodo.png/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/8/8a/Mummynomore.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/b/be/N40115HELLj87.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/3b/Skele2nomore.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/3/36/Surpriseeye.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/8/86/Tongue2.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/5/5b/Tongue2.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/d/d9/Vampnomore.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/4/4a/K377191o130.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/b/b7/TaoistLM-1-.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/c/c0/Th_78eb9b27ac07cd1c5dd48bfbd613df5e.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a8/Footandnomore.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/4/46/Brain.jpg/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/bb/NomoreP.png/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/9/9c/Soinchlm.png/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/1/12/Lmxrayicon.gif/revision/latest/scale-to-height-down/40'],
                    handmade: ['http://vignette2.wikia.nocookie.net/evchk/images/5/55/Sosad-369.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/b/b9/2010818205939156567860.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/3/35/369face.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/2/27/Ass3.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/6/65/AssC.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/b/bc/Bounsad.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a9/Hahaha.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/9/98/Sogood.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/a/a5/Soft_plastic.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/e/eb/Clownbouncer.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/e/e9/369bye.gif/revision/latest/scale-to-height-down/40','http://vignette4.wikia.nocookie.net/evchk/images/5/55/CBye.gif/revision/latest/scale-to-height-down/40','http://vignette1.wikia.nocookie.net/evchk/images/3/39/Sosading.gif/revision/latest/scale-to-height-down/40','http://vignette3.wikia.nocookie.net/evchk/images/1/18/Yup.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/2/23/Peannis.gif/revision/latest/scale-to-height-down/40','http://vignette2.wikia.nocookie.net/evchk/images/1/12/Scary4.gif/revision/latest/scale-to-height-down/40'],
                    whanwhan: ['http://vignette2.wikia.nocookie.net/evchk/images/d/dd/Ww_ai.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/b/b5/Ww_angry.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/d/d7/Ww_beat.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/2/20/Ww_bye.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/7/7e/Ww_chicken.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/1/12/Ww_clown.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/5/51/Ww_crash.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/c/cf/Ww_cry.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/0/08/Ww_dam.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/7/78/Ww_dead.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/a/a8/Ww_good.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/6/63/Ww_happy.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/7/77/Ww_hot.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/c/c8/Ww_laugh.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/9/97/Ww_man.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/4/40/Ww_moster.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/f/fb/Ww_oh.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/0/03/Ww_photo.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/e/e0/Ww_pity.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/1/18/Ww_plastic.jpg/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/7/79/Ww_shock.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/8/82/Ww_shocking.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/9/97/Ww_yee.jpg/revision/latest/scale-to-height-down/80','http://vignette4.wikia.nocookie.net/evchk/images/d/d7/Ww_yo.jpg/revision/latest/scale-to-height-down/80','http://vignette3.wikia.nocookie.net/evchk/images/d/dc/Ww_what.jpg/revision/latest/scale-to-height-down/80','http://vignette1.wikia.nocookie.net/evchk/images/3/33/Zkl6kj.gif/revision/latest/scale-to-height-down/80','http://vignette2.wikia.nocookie.net/evchk/images/0/08/1132814493_copy.jpg/revision/latest/scale-to-height-down/80'],
                    bugs: ['http://vignette2.wikia.nocookie.net/evchk/images/2/2c/Locust_bye.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/b/ba/Locust_sleep.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/3/30/Locust_fear.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/6/68/Locust_adore.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/7/77/Locust_no.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/2/29/Locust_wonder2.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/5/53/Locust_fxxk.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/2/22/Locust_banghead.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/0/00/Locust_bouncer.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/d/d3/Locust_bouncy.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/d/d5/Locust_censored.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/6/62/Locust_flowerface.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/7/75/Locust_offtopic.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/f/f6/Locust_shocking.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/2/24/Locust_photo.gif/revision/latest/scale-to-height-down/30','http://vignette2.wikia.nocookie.net/evchk/images/5/54/Bee_sosad.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/6/64/Locust_yipes.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/e/e2/Locust_369.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/2/2e/Locust_bomb.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/a/a2/Locust_slick.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/c/cd/Locust_thumbUp.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/3/30/Locust_thumbDown.gif/revision/latest/scale-to-height-down/30','http://vignette4.wikia.nocookie.net/evchk/images/1/12/Locust_offtopic_chinaflag.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/e/e2/Locust_birth.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/3/3f/Nomorelick.gif/revision/latest/scale-to-height-down/30','http://vignette3.wikia.nocookie.net/evchk/images/a/ab/Nomoreo.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/4/46/Nomorecry.gif/revision/latest/scale-to-height-down/30','http://vignette1.wikia.nocookie.net/evchk/images/a/a9/QdlyD.gif/revision/latest/scale-to-height-down/30'],
                    bittersmile: ['http://i.imgur.com/Oh4QGVs.gif']
                };
                $.each(others,function(alt,altList){
                    var altHtml = [];
                    $.each(altList,function(i,newSrc){
                        altHtml.push(['<a href="javascript:InsertText(\'[img]',newSrc,'[/img]\')">',
                                      '<img style="border:none;margin-right:5px;margin-bottom:5px;" src="',newSrc,'" onerror="$(this).parent().remove()"></a>'].join(''));
                    });
                    html.push(['<div data-p',suffix,'="',alt,'" style="display:none;padding-bottom:5px;border-top:1px dashed #ccc;">',altHtml.join(''),'</div>'].join(''));
                    btnHtml.push(['<a href="javascript:void(0)" onclick="" style="display:inline-block;height:20px;border:1px dashed #ccc;vertical-align:middle;background:#def;border-top-left-radius:5px;border-top-right-radius:5px;background:linear-gradient(#fff,#def);" data-t',suffix,'="',alt,'"><img src="',altList[0],'" style="border:none;height:20px;"></a>'].join(''));
                });
                $(btnHtml.join('')).insertBefore(tbl);
                $(html.join('')).insertAfter(tbl);
                $(document).on('click','[data-t'+suffix+']',function(){
                    var trg = $(this).attr('data-t'+suffix);
                    $('[data-t'+suffix+']').each(function(){
                        var button = $(this);
                        button.css('background',button.attr('data-t'+suffix) == trg ? '#69f' : '#def');
                    });
                    $('[data-p'+suffix+']').each(function(){
                        var panel = $(this);
                        panel.toggle(panel.attr('data-p'+suffix) == trg);
                    });
                });
            }

            if (isMobile) {
                var done = false, idx = 16;
                var fetch = function(){
                    if (--idx < 1) return;
                    var desktop = 'http://forum'+idx+'.hkgolden.com';
                    GM_xmlhttpRequest({
                        method: 'GET',
                        url: desktop+location.pathname+location.search,
                        onload: function(rpn) {
                            if (done) {
                                return;
                            }
                            var d = $('<div>').html(rpn.responseText.replace(/<body[^>]*>([\s\S]+)<\/body>/g,'$1'));
                            if (!d || !d.find('#ctl00_ContentPlaceHolder1_changeLink1').length) {
                                return fetch();
                            }
                            var searchInput = d.find('#getSerachType');
                            if (searchInput.length) {
                                $('<div>').html([
                                    '<form action="',desktop,'/search.aspx" method="GET" onsubmit="',
                                    '$(this.elements.getSerachType).prop(\'disabled\',true); ',
                                    '$(this.elements.x).val($(this.elements.q).val()); ',
                                    'location.href = $(this).attr(\'action\')+\'?\'+$(this).serialize()+\'#!=\'+location.hostname; ',
                                    'return false; ',
                                    '" style="display: inline-block; margin: 0 10px; ">',
                                    searchInput[0].outerHTML,
                                    '<input type="text" name="q"/>',
                                    '<input type="hidden" name="x"/>',
                                    '<button type="submit" style="padding: 0; border: none; "><img src="/images/btn-search.gif" border="0" alt="Search" style="vertical-align: middle; "/></button>',
                                    '</form>',
                                    '<form action="http://search.hkgolden.com/Search24.aspx" method="GET" onsubmit="',
                                    'if ($(this.elements.st).val() == \'tag\') { ',
                                    '$(this).attr(\'action\', \'http://search.hkgolden.com/tags.aspx\'); ',
                                    '$(this.elements.searchstring).attr(\'name\', \'tagword\'); ',
                                    '$(this.elements.st).prop(\'disabled\', true); ',
                                    '} ',
                                    'location.href = $(this).attr(\'action\')+\'?\'+$(this).serialize()+\'#!=\'+location.hostname; ',
                                    'return false; ',
                                    '" style="display: inline-block; margin: 0 10px; ">',
                                    d.find('#monthST').attr('name','st')[0].outerHTML,
                                    '<input type="text" name="searchstring"/>',
                                    '<button type="submit" style="padding: 0; border: none; "><img src="/images/btn-search.gif" border="0" alt="Search" style="vertical-align: middle; "/></button>',
                                    '</form>',
                                    d.find('.HitSearchText:first').attr('style', 'display: inline-block; ')[0].outerHTML
                                ].join('')).insertAfter('.MobileTopPanel:first');
                            }

                            var profile = d.find('#ctl00_ContentPlaceHolder1_lb_UserName>a:first');
                            if (profile.length) {
                                profile.text('個人資料').attr('style', 'margin: 0 10px; ').attr('href', desktop+'/'+profile.attr('href'));
                                $('<span style="display: inline-block; ">').html(profile[0].outerHTML).insertBefore('a[href="ViewBookmark.aspx"]:first');
                            }
                            var hotpeople = d.find('#ctl00_ContentPlaceHolder1_HotPeoples');
                            if (hotpeople.length) {
                                hotpeople.find('a').each(function(ai,a){
                                    var el = $(a), href = el.attr('href');
                                    if (!/^http/i.test(href)) el.attr('href', desktop+'/'+href);
                                });
                                $('<div>').html(hotpeople[0].outerHTML).insertAfter('#FuncPanel');
                            }

                            $('.ViewNameFemale,.ViewNameMale').each(function(ni,n){
                                var thread = d.find('div[id^="ThreadUser"]:eq('+ni+')')
                                .find('a[href]').each(function(si,s){ $(s).attr('href', desktop+$(s).attr('href')); }).end()
                                .find('img[src]').each(function(si,s){ $(s).attr('src', desktop+'/'+$(s).attr('src')).attr('style','vertical-align: middle; margin: 0 5px; '); }).end()
                                .find('br').remove().end();
                                var tr = thread.closest('tr'), userid = tr.attr('userid');
                                $('<span style="display: inline-block; ">').html(thread.html())
                                    .insertAfter($(n).wrap('<a href="'+desktop+'/ProfilePage.aspx?userid='+encodeURIComponent(userid)+'">').parent());
                                if (ni === 0) {
                                    var mark = d.find('#DivMarkThread');
                                    if (mark.length) {
                                        $(n).closest('.ReplyBox').append($('<div>').html(mark.attr({style:'background-color: #fff; border: 1px solid #aaa; border-radius: 5px; padding: 5px; display: inline-block; '})[0].outerHTML));
                                    }
                                    var taglabel = d.find('span.forum_taglabel');
                                    if (taglabel.length) {
                                        taglabel.find('a').each(function(ai,a){
                                            var el = $(a), href = el.attr('href');
                                            if (!/^http/i.test(href)) el.attr('href', desktop+'/'+href);
                                        });
                                        $(n).closest('.ReplyBox').append($('<div>').html(taglabel.attr({style:'background-color: #fff; border: 1px solid #aaa; border-radius: 5px; padding: 5px; display: inline-block; '})[0].outerHTML));
                                    }
                                }
                            });
                            done = true;
                        },
                        onerror: function(rpn) {
                            fetch();
                        }
                    });
                };
                fetch();
                $('a[href="ViewBookmark.aspx"]:first').text('名已留');
                $('.TopicBox_PageSelect').each(function(ni,n){
                    var select = $(n), opts = select.children('option'), opt1 = opts.eq(0);
                    opt1.text('頁...'+(opts.length-1));
                });
                if (typeof unsafeWindow.ToMobile !== 'undefined') {
                    var _ToMobile = top.ToMobile;
                    top.ToMobile = function() {
                        location.href = 'http://forum15.hkgolden.com' + location.pathname + location.search;
                        return false;
                    };
                }
                if (typeof unsafeWindow.MarkingThread === 'undefined') {
                    unsafeWindow.MarkingThread = function(idx){
                        window.open('http://forum15.hkgolden.com' + location.pathname + location.search + '#markingthread('+idx+')');
                    };
                }
                $(document).on('mouseup','a[href]',function(evt){
                    var el = $(this), href = el.attr('href');
                    if (/^http/.test(href)) {
                        el.attr('href', href.replace(/#.*/g,'')+'#!='+location.hostname);
                    }
                });
                $(window).on('message',function(evt){
                    var data = evt.originalEvent.data;
                    if (/^#DivMarkThread=/.test(data)) {
                        var div = $(data.replace(/^#DivMarkThread=/,''))
                        .attr({style:'background-color: #fff; border: 1px solid #aaa; border-radius: 5px; padding: 5px; display: inline-block; '});
                        $('#DivMarkThread').replaceWith(div);
                    }
                });
            } else {
                var mtEx = /^#markingthread\(([0-9]+)\)$/.exec(location.hash);
                if (mtEx && parseInt(mtEx[1])) {
                    MarkingThread(parseInt(mtEx[1]));
                    var checkMark = function() {
                        var div = $('#DivMarkThread');
                        if (!div.find('a').length) {
                            opener.postMessage('#DivMarkThread='+div[0].outerHTML,'*');
                            window.close();
                            return;
                        }
                        setTimeout(checkMark,100);
                    };
                    setTimeout(checkMark,100);
                }
                $(document).on('mouseup','a[href]',function(evt){
                    var el = $(this), href = el.attr('href');
                    if (/^#!=/.test(location.hash)) {
                        if (/^view\.aspx/.test(href) || /^topics.aspx/.test(href))
                            el.attr('href', 'http://'+location.hash.replace(/^#!=/,'').replace(/#.*/g,'')+'/'+href);
                        else
                            el.attr('href', href.replace(/#.*/g,'')+location.hash);
                    }
                });
            }
        })(jQuery);
    };
    init();
})();