Greasy Fork is available in English.

五线二定pp668

'一排--乘2', '一排二排相加', '一排四排相加', '一排十排相加', '一排四排相同隔两口', '一排六排相加', '一排九排相加', '横加-12-24-13-34-45', '横乘-12-23-34-45-51'

// ==UserScript==
// @name         五线二定pp668
// @namespace    http://tampermonkey.net/
// @version      0.9
// @description  '一排--乘2', '一排二排相加', '一排四排相加', '一排十排相加', '一排四排相同隔两口', '一排六排相加', '一排九排相加', '横加-12-24-13-34-45', '横乘-12-23-34-45-51'
// @author       han2ee
// @include     http*://hy*.pp668.net/*
// @grant   GM_xmlhttpRequest
// @grant   GM.getTab
// @grant   GM.saveTab
// @grant   GM.setValue
// @grant   GM.getValue
// @run-at document-body
// ==/UserScript==

(function() {
    'use strict';
    const LEAST_END_TIME = 30; // 最后30秒不要下单
    // 1配4,2配5,3配5,4配2,5配1
    const BET_STYLE = ['aXXbX', 'XaXXb', 'XXaXb', 'XbXaX', 'bXXXa'];
    const LEN = BET_STYLE.length; // 5条道
    var gameData; // global var
    var gameResult; // global var
    var gameOdds; // global var
    var gameType = 3;
    var lastOpenedGameID = 0;

   // 一排--排除乘2, 如为0则排除3
    const POOL0 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num = gameResult[0].nums[idx];
        let filterNum = (num === 0) ? 3 : (num * 2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排除乘2隔一, 如为0则排除3
    const POOL0a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num = gameResult[1].nums[idx];
        let filterNum = (num === 0) ? 3 : (num * 2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };
    // 一排二排, 排除两数相加, 如都为0则排除3
    const POOL_1_2 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[1].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排二排隔一, 排除两数相加, 如都为0则排除3
    const POOL_1_2a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[2].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

        // 一排三排, 排除两数相加, 如都为0则排除3
    const POOL_1_3 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[2].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排三排隔一, 排除两数相加, 如都为0则排除3
    const POOL_1_3a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[3].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排四排 , 排除两数相加, 如都为0则排除3
    const POOL_1_4 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[3].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排四排 + , 排除两数相加, 如都为0则排除3
    const POOL_1_4a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[4].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排十排, 排除两数相加, 如都为0则排除3
    const POOL_1_10 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[9].nums[idx];
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排十排 + , 排除两数相加, 如都为0则排除3
    const POOL_1_10a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[10].nums[idx];
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排四排相同隔两口, 排除相同
    const POOL_1_4s = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[2].nums[idx];
        let num2 = gameResult[5].nums[idx];
        if (num1 === num2) {
            let filterNum = num1;
            [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
                [...Array(10).keys()].forEach(b => {
                    pools.push(holder.replace('a', a).replace('b', b));
                });
            });
            pools = pools.sort();
            return pools;
        } else {
            return [];
        }
    };

    // 一排六排, 排除两数相加, 如都为0则排除3
    const POOL_1_6 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[5].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排六排 + , 排除两数相加, 如都为0则排除3
    const POOL_1_6a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[6].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };
    // 一排九排 , 排除两数相加, 如都为0则排除3
    const POOL_1_9 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[0].nums[idx];
        let num2 = gameResult[8].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排九排 , 排除两数相加, 如都为0则排除3
    const POOL_1_9a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[9].nums[idx]
        let filterNum = (num1 === 0 && num2 === 0) ? 3 : (num1 + num2) % 10;
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 横加-12-24-13-34-45
    const POOL_ADD = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let numIdx1 = [0, 1, 0, 2, 3][idx];
        let numIdx2 = [1, 3, 2, 3, 4][idx];
        let num1 = gameResult[0].nums[numIdx1];
        let num2 = gameResult[0].nums[numIdx2];
        let pools = [];

        let filterNum = (num1 + num2) % 10;
        if (num1 === 0) {
            filterNum = num2;
        } else if (num2 === 0) {
            filterNum = num1;
        }
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

        // 横加-12-24-13-34-45
    const POOL_ADD_a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let numIdx1 = [0, 1, 0, 2, 3][idx];
        let numIdx2 = [1, 3, 2, 3, 4][idx];
        let num1 = gameResult[1].nums[numIdx1];
        let num2 = gameResult[1].nums[numIdx2];
        let pools = [];

        let filterNum = (num1 + num2) % 10;
        if (num1 === 0) {
            filterNum = num2;
        } else if (num2 === 0) {
            filterNum = num1;
        }
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };
    // 横乘-12-23-34-45-51
    const POOL_MUL = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let numIdx1 = [0, 1, 2, 3, 4][idx];
        let numIdx2 = [1, 2, 3, 4, 0][idx];
        let num1 = gameResult[0].nums[numIdx1];
        let num2 = gameResult[0].nums[numIdx2];
        let pools = [];

        let filterNum = (num1 * num2) % 10;
        if (num1 === 0) {
            filterNum = num2;
        } else if (num2 === 0) {
            filterNum = num1;
        }

        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 横乘-12-23-34-45-51
    const POOL_MUL_a = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let numIdx1 = [0, 1, 2, 3, 4][idx];
        let numIdx2 = [1, 2, 3, 4, 0][idx];
        let num1 = gameResult[1].nums[numIdx1];
        let num2 = gameResult[1].nums[numIdx2];
        let pools = [];

        let filterNum = (num1 * num2) % 10;
        if (num1 === 0) {
            filterNum = num2;
        } else if (num2 === 0) {
            filterNum = num1;
        }

        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 0 7 5 9
    const POOL_0759 = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num = gameResult[0].nums[idx];
        let filterNum = FILTER_NUM_MAP[num];
        [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
            [...Array(10).keys()].forEach(b => {
                pools.push(holder.replace('a', a).replace('b', b));
            });
        });
        pools = pools.sort();
        return pools;
    };

    // 一排三排相同隔一口, 排除相同
    const POOL_1_3s = (gameResult, idx) => {
        let holder = BET_STYLE[idx];
        let pools = [];
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[3].nums[idx];
        if (num1 === num2) {
            let filterNum = num1;
            [...Array(10).keys()].filter(a => a !== filterNum).forEach(a => {
                [...Array(10).keys()].forEach(b => {
                    pools.push(holder.replace('a', a).replace('b', b));
                });
            });
            pools = pools.sort();
            return pools;
        } else {
            return [];
        }
    };

    function signalA(gameResult, idx) {
        return isPreviousOpened(gameData);
    }
    // 一四相同隔二, %3 === 0
    function signalB0(gameResult, idx) {
        if (gameResult[2].gameId % 3 !== 0) {
            return false
        }
        let num1 = gameResult[2].nums[idx];
        let num2 = gameResult[5].nums[idx];
        return num1 === num2;
    }
    // 一四相同隔二, %3 === 1
    function signalB1(gameResult, idx) {
        if (gameResult[2].gameId % 3 !== 1) {
            return false
        }
        let num1 = gameResult[2].nums[idx];
        let num2 = gameResult[5].nums[idx];
        return num1 === num2;
    }
    // 一四相同隔二, %3 === 2
    function signalB2(gameResult, idx) {
        if (gameResult[2].gameId % 3 !== 2) {
            return false
        }
        let num1 = gameResult[2].nums[idx];
        let num2 = gameResult[5].nums[idx];
        return num1 === num2;
    }
    // 0759
    function signalC(gameResult, idx) {
        let num = gameResult[0].nums[idx];
        return FILTER_NUM_MAP[num] !== undefined;
    }
    // 一三相同隔一, %2 === 0
    function signalD0(gameResult, idx) {
        if (gameResult[2].gameId % 2 !== 0) {
            return false
        }
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[3].nums[idx];
        return num1 === num2;
    }
    // 一三相同隔一, %2 === 1
    function signalD1(gameResult, idx) {
        if (gameResult[2].gameId % 2 !== 1) {
            return false
        }
        let num1 = gameResult[1].nums[idx];
        let num2 = gameResult[3].nums[idx];
        return num1 === num2;
    }
    const SIGNALS = [signalA, signalA, signalA, signalA, signalA, signalA, signalA, signalA, signalA, signalC,
                     signalA, signalA, signalA, signalA, signalA, signalA, signalA, signalA, signalA,
                     signalD0, signalD1, signalB0, signalB1, signalB2];
    const POOLS = [POOL0, POOL_1_3, POOL_1_4, POOL_1_6, POOL_1_9, POOL_1_10, POOL_1_2, POOL_ADD, POOL_MUL, POOL_0759,
                   POOL0a, POOL_1_3a, POOL_1_4a, POOL_1_6a, POOL_1_9a, POOL_1_10a, POOL_1_2a, POOL_ADD_a, POOL_MUL_a,
                   POOL_1_3s, POOL_1_3s, POOL_1_4s, POOL_1_4s, POOL_1_4s];
    const OPTIONS_DESC = ['1248', '1+3', '1 + 4', '1 + 6', '1 + 9', '1 + 10', '加法', '横加', '横乘', '0759',
                          '1248=', '1+3 =', '1 + 4=', '1 + 6=', '1 + 9=', '1 + 10=', '加法=', '横加=', '横乘=',
                          '一三相同=', '1-3-hide-1', '一四相同=', '1-4-hide-1', '1-4-hide-2',];



    var wait = ms => new Promise(resolve => setTimeout(resolve, ms));
    function isPromise(obj) {
        return !!obj && ((typeof obj === 'object' && typeof obj.then === 'function') || (typeof obj === 'function' && typeof obj().then === 'function'));
    }
    /**
     * Wait Resource.
     *
     * @param {Function} resourceFn pred function to check resource
     * @param {Object} options
     * @returns Promise
     */
    function waitResource(resourceFn, options) {
        var optionsRes = Object.assign(
            {
                interval: 2000,
                max: 10
            },
            options
        );
        var current = 0;
        return new Promise((resolve, reject) => {
            var timer = setInterval(() => {
                if (isPromise(resourceFn)) {
                    resourceFn().then(res => {
                        if(res) {
                            clearInterval(timer);
                            resolve();
                        }
                    });
                } else if (resourceFn()) {
                    clearInterval(timer);
                    resolve();
                }
                current++;
                if (current >= optionsRes.max) {
                    clearInterval(timer);
                    reject('Time out');
                }
            }, optionsRes.interval);
        });
    }


    function decimal(num, v) {
        var vv = Math.pow(10, v);
        return Math.round(num * vv) / vv;
    }

    function randomNum(max, min) {
        return parseFloat(Math.random() * (max - min) + min);
    }

    function ajaxAsync(url, data, method = 'post', dataType = 'json') {
         return new Promise((resolve, reject) => {
             $.ajax({
                 type: method,
                 url: url,
                 cache: false,
                 timeout: 1000 * 30,
                 dataType: dataType,
                 data: data,
                 success: function (msg) {
                     if (!msg || msg.error) {
                         reject(`Request ${url} => Error ${msg.error}`);
                     } else {
                         resolve(msg);
                     }
                 },
                 error: function () {
                     reject(`Fail to request ${url} with data ${data}`);
                 }
             });
         });
    }

    function resToMask(res, idx) {
        let a = BET_STYLE[idx];
        let mask = 'XXXXX'.split('');
        for(let i = 0; i < BET_STYLE.length; i++) {
            if (a[i] !== 'X') {
                mask[i] = res[i];
            }
        }
        return mask.join('');
    }

    function isPreviousOpened(gameData) {
        if (!gameData || !gameData.openDateList|| !gameResult || gameResult.length < 1) {
            return false;
        }
        return (gameResult[0].gameId + 1 ) % 10 === gameData.openDateList.number % 10;
    }

    async function requestGameData(gameType) {
        // "NewQiShu"
        let html = await ajaxAsync('AZKuaiXuan2.aspx', {
            uid: window.top.uid
        }, 'get', 'html');
        let newNumberMatch = /id="NewQiShu".*?>(\d+)</.exec(html);

        if (!newNumberMatch) {
            return null;
        }
        let endTimeMatch = /id="clockTime".*?>((\d+)分)?(\d+)秒</.exec(html);
        let endTime = 0;

        let openedNumRes = await ajaxAsync('AZQiXingCaiW2F.aspx', {
            uid: window.top.uid,
            GetResType: 'GetResult',
            Time: Date()
        }, 'get', 'json');
        if (endTimeMatch && endTimeMatch[2]) {
            endTime += 60 * endTimeMatch[2];
        }
        if (endTimeMatch && endTimeMatch[3]) {
            endTime += 1 * endTimeMatch[3];
        }
        return {
            openDateList: {
                number: parseInt(newNumberMatch[1]),
                endTime: endTime
            },
            openNumList: {
                newnumber: openedNumRes ? parseInt(openedNumRes.QiShu) : 0,
                nums: openedNumRes ? [parseInt(openedNumRes.No1), parseInt(openedNumRes.No2), parseInt(openedNumRes.No3), parseInt(openedNumRes.No4), parseInt(openedNumRes.No5)] : null
            }
        };
    }

    async function requestOdds() {
        let json = await ajaxAsync("Ajax/Ajax_QXUpMoneysOdds_Type.aspx?uid=" + top.window.uid, {
            Type: 2,
        });
        return json;
    }
    async function requestGameResult(gameType) {
        let html = await ajaxAsync('LotteryResults.aspx', {
            uid: window.top.uid
        }, 'get', 'html');
        let resList = [];
        let lastGameId = null;
        let lastNums = [];
        // let numRegx = /class="td-hd">(\d{8})<|class="icon_1 ball_aozhou5">(\d)</mg
        let numRegx = /class="td-hd">(\d{8})<|class="icon_.*? ball_.*?">(\d)</mg
        let match;
        while((match = numRegx.exec(html)) !== null) {
            if (match[1] !== undefined && match[1] !== null) {
                lastGameId = parseInt(match[1]);
            }
            if (match[2] !== undefined && match[2] !== null) {
                lastNums.push(parseInt(match[2]));
            }
            if (lastNums.length === 5) {
                if (lastGameId) {
                    resList.push({
                        gameId: lastGameId,
                        nums: lastNums
                    });
                }
                lastNums = [];
                lastGameId = null;
            }
        }
        return resList;
    }

    function parseResult(gameResult) {
        return gameResult.table.map(a => {
            let gameIdMatch = /\d+/.exec(a);
            let numRegx = /SSCNo_(\d)/mg;
            let nums = [];
            let match;
            while((match = numRegx.exec(a)) !== null) {
                nums.push(parseInt(match[1]));
            }
            return {
                gameId: parseInt(gameIdMatch[0]),
                nums: nums
            }
        });
    }

    function parseAmounts(amountStr) {
        if (!amountStr) {
            return [];
        }
        let amounts = amountStr.split('-').map(a => parseInt(a)).map(a => (a >= 0) ? a : 0);
        if (amounts.some(a => !(a >= 0))) {
            amounts = [];
        }
        return amounts;
    }
    async function bet(pools, amount) {
        let count = pools.length;
        // pools = pools.map(a => `${getDWTypeByName(a)}:${amount}`);
        let maxUpOdds = (gameOdds && gameOdds.MaxUpOdds) ? gameOdds.MaxUpOdds : 1;
        let minUpOdds = (gameOdds && gameOdds.MinUpOdds) ? gameOdds.MinUpOdds : 0.5;
        let OrderList = [];
        for (let i = 0; i < pools.length; i++) {
            OrderList[i] = new Object();
            let FangXiang = pools[i];

            let Mones = amount.toString(); // money

            let Type = 2; // 二定 为 2

            let LeiXing = "二字定位" + FangXiang.replace(/\d/g, "口");

            let RdupOdds = decimal(randomNum(decimal(maxUpOdds, 4), decimal(minUpOdds, 4)), 2);// $(Nums[i]).attr("data-rdupOdds");  // 0.62

            let RdMoneyProb = decimal(randomNum(1, 0), 2); //$(Nums[i]).attr("data-rdprob"); // 0.02


            OrderList[i].id = "0";
            OrderList[i].Money = Mones;
            OrderList[i].XiangMu = "6";
            OrderList[i].FangXiang = FangXiang;
            OrderList[i].LeiXing = LeiXing;
            OrderList[i].Odds = "1";
            OrderList[i].Type = Type;
            OrderList[i].XiaBiao = i;
            OrderList[i].RdupOdds = RdupOdds.toString();;
            OrderList[i].RdMoneyProb = RdMoneyProb.toString();  // MoneyRdProb
        }
        const REQ_DATA = {
            List: JSON.stringify(OrderList)
        };
        console.log(REQ_DATA);
        // return {};
        return await ajaxAsync("/Ajax/PostHandler.aspx?uid=" + top.window.uid, REQ_DATA);
    }

    function addUI() {
        let divAll=document.createElement("div");
        divAll.setAttribute("style", "float:left;z-index:100000;position:absolute;background-color: #229ACB");
        let controlBtn = document.createElement("BUTTON");
        controlBtn.innerText = "隐藏";
        controlBtn.onclick = (event) => {
            if (event.target.innerText === "隐藏") {
                event.target.innerText = "打开";
                document.querySelector('#betAssitInfos').style.display = 'none';
            } else {
                event.target.innerText = "隐藏";
                document.querySelector('#betAssitInfos').style.display = 'block';
            }
        }
        divAll.appendChild(controlBtn);

        let divList=document.createElement("div");
        divList.setAttribute("id", "betAssitInfos");
        divAll.appendChild(divList);
        for(let i = 0; i < OPTIONS_DESC.length; i++) {
            let div=document.createElement("div");
            div.setAttribute("style", "width:280px");
            let btn=document.createElement("BUTTON");
            btn.setAttribute("id", `betBtn${i}`);
            btn.setAttribute("style", "width:130px");
            div.appendChild(btn);
            let select = document.createElement("INPUT");
            //select.setAttribute("id", `strategy`);
            if(OPTIONS_DESC[i].includes('hide')) {
                select.value = "";
            } else {
                select.value = OPTIONS_DESC[i];//OPTIONS_DESC.map(a => `<option value =0>${a}</option>`).join('');
            }
            select.setAttribute("type", "text");
            select.setAttribute("style", "width:55px");
            select.setAttribute('readonly','');
            div.appendChild(select);
            let amount = document.createElement("INPUT");
            amount.setAttribute("id", `betAmount${i}`);
            amount.setAttribute("style", "width:65px");
            amount.setAttribute("placeholder", "金额:1-2-4-8");
            amount.setAttribute("type", "text");
            div.appendChild(amount);
            divList.appendChild(div);
        }
        let node = document.querySelector('.accountInfo');
        let parentNode = node.parentNode;
        parentNode.insertBefore(divAll, node);
    }

    async function updateUI(tabObj, idx) {
        if (!tabObj[idx]) {
            tabObj[idx] = {};
        }
        let btnId = `#betBtn${idx}`;
        if (tabObj[idx].started) {
            if(OPTIONS_DESC[idx].includes('hide')) {
                let lenInfo = tabObj[idx].betInfos ? tabObj[idx].betInfos.map(a => a.length).join(',') : '';
                document.querySelector(btnId).innerText = `____(${lenInfo})`;
            } else if (OPTIONS_DESC[idx] === '一四相同='){
                let lenInfo = tabObj[idx].betInfos ? tabObj[idx].betInfos.map(a => a.length).join(',') : '';
                document.querySelector(btnId).innerText = `结束(${lenInfo})`;
                // document.querySelector("#strategy").selectedIndex = tabObj.selectedIndex;
                let val = tabObj[idx].amounts.join('-');
                document.querySelector(`#betAmount${idx}`).value = val;
                document.querySelector(`#betAmount${idx + 1}`).value = val;
                document.querySelector(`#betAmount${idx + 2}`).value = val;
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = false;
                    tabObj[idx + 1].started = false;
                    tabObj[idx + 2].started = false;
                    // tabObj.betInfos = null;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            } else if (OPTIONS_DESC[idx] === '一三相同='){
                let lenInfo = tabObj[idx].betInfos ? tabObj[idx].betInfos.map(a => a.length).join(',') : '';
                document.querySelector(btnId).innerText = `结束(${lenInfo})`;
                // document.querySelector("#strategy").selectedIndex = tabObj.selectedIndex;
                let val = tabObj[idx].amounts.join('-');
                document.querySelector(`#betAmount${idx}`).value = val;
                document.querySelector(`#betAmount${idx + 1}`).value = val;
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = false;
                    tabObj[idx + 1].started = false;
                    // tabObj.betInfos = null;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            } else {
                let lenInfo = tabObj[idx].betInfos ? tabObj[idx].betInfos.map(a => a.length).join(',') : '';
                document.querySelector(btnId).innerText = `结束(${lenInfo})`;
                // document.querySelector("#strategy").selectedIndex = tabObj.selectedIndex;
                document.querySelector(`#betAmount${idx}`).value = tabObj[idx].amounts.join('-');
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = false;
                    // tabObj.betInfos = null;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            }
        } else {
            if(OPTIONS_DESC[idx].includes('hide')) {
                document.querySelector(btnId).innerText = "____";
            } else if (OPTIONS_DESC[idx] === '一四相同='){
                document.querySelector(btnId).innerText = "开始";
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = true;
                    tabObj[idx].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx].betInfos = Array(LEN).fill([]);
                    tabObj[idx].betPools = Array(LEN).fill([]);
                    tabObj[idx].lastGameID = 0;
                    tabObj[idx].lastOpenedGameID = 0;

                    tabObj[idx + 1].started = true;
                    tabObj[idx + 1].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx + 1].betInfos = Array(LEN).fill([]);
                    tabObj[idx + 1].betPools = Array(LEN).fill([]);
                    tabObj[idx + 1].lastGameID = 0;
                    tabObj[idx + 1].lastOpenedGameID = 0;

                    tabObj[idx + 2].started = true;
                    tabObj[idx + 2].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx + 2].betInfos = Array(LEN).fill([]);
                    tabObj[idx + 2].betPools = Array(LEN).fill([]);
                    tabObj[idx + 2].lastGameID = 0;
                    tabObj[idx + 2].lastOpenedGameID = 0;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            } else if (OPTIONS_DESC[idx] === '一三相同='){
                document.querySelector(btnId).innerText = "开始";
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = true;
                    tabObj[idx].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx].betInfos = Array(LEN).fill([]);
                    tabObj[idx].betPools = Array(LEN).fill([]);
                    tabObj[idx].lastGameID = 0;
                    tabObj[idx].lastOpenedGameID = 0;

                    tabObj[idx + 1].started = true;
                    tabObj[idx + 1].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx + 1].betInfos = Array(LEN).fill([]);
                    tabObj[idx + 1].betPools = Array(LEN).fill([]);
                    tabObj[idx + 1].lastGameID = 0;
                    tabObj[idx + 1].lastOpenedGameID = 0;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            } else {
                document.querySelector(btnId).innerText = "开始";
                document.querySelector(btnId).onclick = async () => {
                    tabObj[idx].started = true;
                    // tabObj.selectedIndex = document.querySelector("#strategy").selectedIndex;
                    tabObj[idx].amounts = parseAmounts(document.querySelector(`#betAmount${idx}`).value);
                    tabObj[idx].betInfos = Array(LEN).fill([]);
                    tabObj[idx].betPools = Array(LEN).fill([]);
                    // tabObj.gameType = document.querySelector('#menuText').getAttribute('data-index'); // 澳五的gameType是3
                    tabObj[idx].lastGameID = 0;
                    tabObj[idx].lastOpenedGameID = 0;
                    await GM.saveTab(tabObj);
                    document.querySelector(btnId).innerText = "...";
                }
            }
        }
    }

    async function work(tabObj, idx) {
        // work
        if(!tabObj[idx].started) {
            return;
        }
        for (let i = 0; i < LEN; i++) {
            let pool = POOLS[idx](tabObj.result, i);
            if (!!tabObj[idx].betInfos[i] && tabObj[idx].betInfos[i].length === 0) { // 初始下单
                if (SIGNALS[idx](tabObj.result, i) && tabObj[idx].amounts.length > 0) {
                    if (tabObj[idx].amounts[0] > 0) {
                        let res = await bet(pool, tabObj[idx].amounts[0]);
                        console.log(res);
                        // Result: "投注失败 ,余额不足"}
                        if (res.Result !== "投注成功" && res.Result !== "投注失败 ,余额不足") {
                            throw(res);
                        }
                    }
                    tabObj[idx].betInfos[i] = [gameData.openDateList.number];
                    tabObj[idx].betPools[i] = [pool];
                    updateUI(tabObj, idx);
                    await GM.saveTab(tabObj);
                    continue;
                }
            }

            let betMaxIdx = tabObj[idx].betInfos[i].length - 1;
            if (tabObj[idx].betInfos[i][betMaxIdx] > tabObj.result[0].gameId) { // 还没有开奖
                continue;
            }
            if (!!tabObj[idx].betInfos[i] && tabObj[idx].betInfos[i].length > 0) { // 加码
                let resultedLen = tabObj.result.length;
                let resIdx = -1; // 防止跳期
                for (let gameIdx = resultedLen - 1; gameIdx >= 0; gameIdx--) {
                    if (tabObj[idx].betInfos[i][betMaxIdx] === tabObj.result[gameIdx].gameId) {
                        resIdx = gameIdx;
                        break;
                    }
                }
                let betRes = [-1, -1, -1, -1, -1];
                if (resIdx !== -1) {
                    betRes = tabObj.result[resIdx].nums;
                }
                let betMaskRes = resToMask(betRes, i);
                console.log(`方案${idx}开奖结果:`, i, betMaskRes, `resIdx:${resIdx}`);
                let poolMaxIdx = tabObj[idx].betPools[i].length - 1;
                if (tabObj[idx].betPools[i][poolMaxIdx].includes(betMaskRes)) { // 中奖
                    console.log("中奖", i, betRes);
                    tabObj[idx].betInfos[i] = [];
                    tabObj[idx].betPools[i] = [];
                    updateUI(tabObj, idx);
                    await GM.saveTab(tabObj);
                } else { // 不中奖
                    if (tabObj[idx].betInfos[i].length < tabObj[idx].amounts.length && SIGNALS[idx](tabObj.result, i)) { // 加码
                        let betInfosLen = tabObj[idx].betInfos[i].length;
                        if (tabObj[idx].amounts[betInfosLen] > 0) {
                            let res = await bet(pool, tabObj[idx].amounts[betInfosLen]);
                            console.log(res);
                            if (res.Result !== "投注成功" && res.Result !== "投注失败 ,余额不足") {
                                throw(res);
                            }
                        }
                        tabObj[idx].betInfos[i].push(gameData.openDateList.number);
                        tabObj[idx].betPools[i].push(pool);
                        await GM.saveTab(tabObj);
                    } else if (tabObj[idx].betInfos[i].length >= tabObj[idx].amounts.length) { // 已经加到最大 重新开始
                        tabObj[idx].betInfos[i] = [];
                        tabObj[idx].betPools[i] = [];
                        updateUI(tabObj, idx);
                        await GM.saveTab(tabObj);
                    }
                }
            }
        }
        // end work
    }
    async function main() {
        if (window !== top) {
            console.log("NOT THE TOP");
            // return;
        }
        console.log("START...", window.location.pathname, new Date());
        if (window.location.pathname === '/Login.aspx') { // login
            let user = await GM.getTab();
            console.log("DEBUG LOGIN", user);
            if (document.querySelector('#btnSearch')) {
                document.querySelector('#search').value = 'aaa999';
                document.querySelector('#btnSearch').click();
                return;
            }
            if (!!user && !!user.name) {
                await wait(1000);
                document.querySelector('#user_name').value = user.name;
                await wait(500);
                document.querySelector('#password').value = user.password;
                await wait(500);
                document.querySelector('#btn_login').click();
            } else {
                document.querySelector('#btn_login').onclick = async () => {
                    user.name = document.querySelector('#user_name').value;
                    user.password = document.querySelector('#password').value;
                    await GM.saveTab(user);
                    aLeftForm1Sub();
                }
            }
            return;
        }
        if (window.location.pathname === "/Consent.aspx") {
            console.log("AGREE");
            await wait(500);
            agreeFrm();
            // document.querySelector('.hotBtn').click();
            return;
        }
        if (window.location.pathname === "/Menu.aspx") {
            console.log("TOP WINDOW");
            await waitResource(async () => {
                let userNameEle = document.querySelector('#UserName');
                console.log(userNameEle);
                return userNameEle && userNameEle.innerText.length > 0;
            });

            // update game Data and odds data
            setInterval(async () => {
                try {
                    gameData = await requestGameData(gameType);
                    console.log('DEBUG:', gameData);

                    let oddsRes = await requestOdds();
                    if (oddsRes && oddsRes.NewOdds.length > 0) {
                        gameOdds = oddsRes.NewOdds[0];
                        console.log('DEBUG odds:', gameOdds)
                    }
                } catch (err) {
                    console.log(err);
                    // ignore err
                }
            }, 10000);

            // update game history result
            setInterval(async () => {
                try {
                    if (!!gameData && lastOpenedGameID < gameData.openNumList.newnumber) {
                        gameResult = await requestGameResult();
                        if (gameResult.length > 0) {
                            lastOpenedGameID = gameResult[0].gameId;
                        }
                        console.log('DEBUG:', gameResult)
                    }
                } catch (err) {
                    console.log(err);
                }
            }, 5000);

            addUI();


            while (true) {
                if (document.querySelector('.myLayerOk') && document.querySelector('.myLayerTitle').innerText === '通知') { // clear 通知
                    document.querySelector('.myLayerOk').click()
                }

                let tabObj = await GM.getTab();
                // console.log('tabObj: ', tabObj);

                for (let i = 0; i < OPTIONS_DESC.length; i++) {
                    await updateUI(tabObj, i);
                }

                if (!gameData || !gameResult) {
                    await wait(1000);
                    continue;
                }

                if (gameData.openDateList.endTime < LEAST_END_TIME || !isPreviousOpened(gameData)) {
                    await wait(1000);
                    continue;
                }

                // update result
                let tabResult = tabObj.result ? tabObj.result : [];
                if (tabResult.length === 0 || tabResult[0].gameId < gameResult[0].gameId) {
                    for (let i = gameResult.length - 1; i >= 0; i--) {
                        if (tabResult.length === 0 || tabResult[0].gameId < gameResult[i].gameId) {
                            tabResult.unshift(gameResult[i]);
                        }
                    }
                    tabObj.result = tabResult.slice(0,120);
                    console.log("Results:", tabObj.result);
                    await GM.saveTab(tabObj);
                }
                if (tabObj.result.length >= 10) {
                    for (let i = 0; i < OPTIONS_DESC.length; i++) {
                        await work(tabObj, i);
                    }
                }
                await wait(1000);
            }
        }
    }

    main()
        .then(() => console.log("Main Done"))
        .catch((err) => {
        console.error(err, "Restart in 6 secs ...");
        setTimeout(() => top.location.reload(), 6 * 1000);
    });
})();