Greasy Fork is available in English.

巴哈姆特公會、首頁自動簽到

巴哈姆特公會、首頁自動簽到 by.moontai0724

Från och med 2018-02-03. Se den senaste versionen.

// ==UserScript==
// @name         巴哈姆特公會、首頁自動簽到
// @namespace    https://greasyfork.org/users/165315
// @version      1.6
// @description  巴哈姆特公會、首頁自動簽到 by.moontai0724
// @author       moontai0724
// @match        https://www.gamer.com.tw/*
// @match        https://guild.gamer.com.tw/*
// @grant        none
// @supportURL   https://forum.gamer.com.tw/C.php?bsn=60076&snA=4363091
// ==/UserScript==

(function () {
    'use strict';
    /* (Chrome)
    如果要開啟自動簽到,請在「設定 -> 起始畫面」中新增 https://www.gamer.com.tw/index2.php#check
    如果要開啟自動簽到,請在「設定 -> 起始畫面」中新增 https://www.gamer.com.tw/index2.php#check
    如果要開啟自動簽到,請在「設定 -> 起始畫面」中新增 https://www.gamer.com.tw/index2.php#check

    網址錯誤將無法正常運行。

    意思為在開啟瀏覽器時,都會打開 https://www.gamer.com.tw/index2.php#check
    當打開 https://www.gamer.com.tw/index2.php#check 的時候,自動簽到就會開始。

    如不需要自動簽到公會,請將下方 signguild 變數 true 改為 false
    */

    var signguild = true;

    /*
    作者的話:本人僅於 Chrome 上測試,照理說應能通用,但如有錯誤,將不提供其他瀏覽器的完全支援與改動。
             (如果有錯誤還是可以回報,也許某天會改動。)
    ----------------------------------------------------------------------------------------------------*/



    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。
    // 下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。下方為程式內容,請勿更動。

    function getNowTime() {
        var time = new Date(), time_ms = time.getMilliseconds(), time_sec = time.getSeconds(), time_min = time.getMinutes(), time_hr = time.getHours(), time_day = time.getDate(), time_month = time.getMonth() + 1, time_year = time.getFullYear();
        if (time_ms < 10) { time_ms = "00" + time_ms; } else if (time_ms < 100) { time_ms = "0" + time_ms; } if (time_sec < 10) { time_sec = "0" + time_sec; } if (time_min < 10) { time_min = "0" + time_min; } if (time_hr < 10) { time_hr = "0" + time_hr; } if (time_day < 10) { time_day = "0" + time_day; } if (time_month < 10) { time_month = "0" + time_month; }
        return time_year + '/' + time_month + '/' + time_day + ' ' + time_hr + ':' + time_min + ':' + time_sec + ':' + time_ms + '-> ';
    }

    if (BAHAID) {
        if (location.hash == "#check") {
            window.alert = function (str) {
                return;
            };
        }

        if (location.hostname == "www.gamer.com.tw" && location.hash == "#check") {
            Signin.start(this);
            if (signguild === true) {
                window.open("https://guild.gamer.com.tw/#check");
            }
        } else if (location.hostname == "guild.gamer.com.tw" && location.hash == "#check" && signguild === true) {
            TOPBAR_show('guild', '');
            TOPBAR_show('guild', '');
            new Promise(function (resolve, reject) {
                function keep() {
                    if (document.getElementById("topBarMsg_guild").getElementsByClassName("TOP-msgpic")[0]) {
                        var guild_list_temp = document.getElementById("topBarMsg_guild").getElementsByClassName("TOP-msgpic");
                        var guild_list = [];
                        for (var i = 0; i < guild_list_temp.length; i++) {
                            guild_list[i] = guild_list_temp[i].href.split("=")[1];
                        }
                        if (guild_list.length > 0) {
                            console.log(getNowTime(), '讀取公會列表成功,開始簽到。');
                            resolve(guild_list);
                        } else {
                            console.log(getNowTime(), '讀取公會列表失敗,重新讀取中');
                            window.setTimeout(function () { keep(); }, 200);
                        }
                    } else {
                        console.log(getNowTime(), '讀取公會列表失敗,重新讀取中');
                        window.setTimeout(function () { keep(); }, 200);
                    }
                }
                keep();
            }).then(function (guild_list) {
                console.log(getNowTime(), guild_list, "length: " + guild_list.length);
                for (var x = 0; x < guild_list.length; x++) {
                    guild_sign(guild_list[x]);
                    console.log(getNowTime(), "signed: ", guild_list[x]);
                    if (x == guild_list.length - 1) {
                        console.log(getNowTime(), "exit");
                        window.setTimeout(function () { window.close(this); }, 1000);
                    }
                }
            });
        }
    } else if (location.hash == "#check") {
        var _creatediv_01 = document.createElement("div");
        _creatediv_01.id = "notloggedin_out";
        _creatediv_01.setAttribute("align", "center");
        _creatediv_01.setAttribute("vertical-align", "middle");
        _creatediv_01.setAttribute("style", "width: 600px; height: 300px; position: absolute; top: 50%; left: 50%; margin: -150px 0 0 -300px; background: red;");
        document.body.appendChild(_creatediv_01);
        var _creatediv_02 = document.createElement("div");
        _creatediv_02.id = "notloggedin_in";
        _creatediv_02.setAttribute("align", "center");
        _creatediv_02.setAttribute("onclick", "window.location.replace(\"https://user.gamer.com.tw/login.php\");");
        _creatediv_02.setAttribute("style", "width: 580px; height: 280px; margin-top: 10px; background: #000000; display: flex; flex-wrap: wrap; align-items: center;");
        document.getElementById("notloggedin_out").appendChild(_creatediv_02);
        var _creatediv_03 = document.createElement("div");
        _creatediv_03.setAttribute("style", "width: 560px; font-size: 80px; margin: 0 auto; color: #ff99cc; font-family: 微軟正黑體;line-height: 80px;");
        _creatediv_03.innerHTML = "您尚未登入!";
        document.getElementById("notloggedin_in").appendChild(_creatediv_03);
        var _creatediv_04 = document.createElement("div");
        _creatediv_04.setAttribute("style", "width: 560px; font-size: 40px; margin: 0 auto; color: #ff3366; font-family: 微軟正黑體;line-height: 40px;");
        _creatediv_04.innerHTML = "簽到腳本無法進行簽到作業。\n請登入後重新打開瀏覽器。\n(或gamer.com.tw/#check)";
        document.getElementById("notloggedin_in").appendChild(_creatediv_04);
        alert("您尚未登入!");
    }
})();