CFAccountsManager

try to take over the world!

Stan na 18-03-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         CFAccountsManager
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       bakapiano
// @match        *://codeforces.com/*
// @grant        none
// ==/UserScript==

(function() {
    var BACKENDURL = "https://cf.bakapiano.site";
    function login() {
        localStorage["work"] = "login";
        if (document.querySelector("#header > div.lang-chooser > div:nth-child(2) > a:nth-child(2)").innerText == "Logout") {
            document.querySelector("#header > div.lang-chooser > div:nth-child(2) > a:nth-child(2)").click();
        }
        if (localStorage["step"] == null) {
            localStorage["step"] = 0;
        }
        var step = Number(localStorage["step"]);
        if (step == 0) {
            localStorage["step"] = 1;
            document.querySelector("#header > div.lang-chooser > div:nth-child(2) > a:nth-child(1)").click();
        }
        else if (step == 1){
            localStorage["step"] = 0;
            localStorage["work"] = ""
            document.querySelector("#handleOrEmail").value = "";
            document.querySelector("#password").value = "";
            document.querySelector("#enterForm > table > tbody > tr:nth-child(4) > td > div:nth-child(1) > input").click();
            //alert("done");

        }
    }

    function check_current_work() {
        if (localStorage["work"] == "login") {
            login();
        } else if (1==1) {
        }
    }

    function get_friend() {
        var list = $("#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr").find("td");
        //console.log(list);
        for(var i=0; i<list.length; i++) {
            if (i%3 == 1) {
                console.log(list[i]);
            }
        }
    }

    function process_accounts_info() {
        var data = [];
        var lines = localStorage['accounts'].split('\n');
        for(var i=0; i<lines.length; i++) {
            var temp = lines[i].trim().split(' ');
            console.log(temp);
            if(temp.length>=2) {
                var username = temp[0].trim();
                var password = temp[temp.length-1].trim();
                if(username!="" && password!="") {
                    data.push([username,password])
                }
            }
        }
        localStorage['data'] = JSON.stringify(data);
    }

    function refresh_msg() {
        if(localStorage['data'] == null){
            return;
        }
        var data = jQuery.parseJSON(localStorage['data']);
        var ele = [];
        for(var i=0; i<data.length; i++) {
            var p = document.createElement("p");
            var username = data[i][0];

            console.log(username);
            var t = document.createTextNode(username);
            p.appendChild(t);
/*
            var success = document.createElement("div");
            success.style = 'display:inline;';
            success.className = 'success';
            p.appendChild(success);
*/
            var info = document.createElement("div");
            info.style = 'display:inline;';
            info.className = 'info';
            p.appendChild(info);

            ele.push(p);
        }
        $('#msg').children().remove();
        for(i=0; i<ele.length; i++) {
            $('#msg')[0].appendChild(ele[i]);
            console.log(ele[i]);
            ele[i].id = "user_" + data[i][0];
        }
        //$('#msg').append('<br>');
    }

    function check_unread_msg() {
        if(localStorage['data'] == null){
            return;
        }
        var data = jQuery.parseJSON(localStorage['data']);
        console.log(data);
        //console.log()
        $.ajax({
            type: "POST",
            url: BACKENDURL + "/check_unread",
            //contentType: "application/json; charset=utf-8",
            data: "data="+JSON.stringify(data),
            dataType: "json",
            success : function (data) {
                unread = data[0];
                fail   = data[1];
                var i = 0;
                all = $('#msg').find('.info');
                //for(i=0; i<all.length; i++) {
                //    all[i].innerText = " No info. "
                //}
                for(i=0; i<unread.length; i++) {
                    $('#msg').find('#user_'+unread[i]).find('.info')[0].innerText = " New message! ";
                }
                for(i=0; i<fail.length; i++) {
                    $('#msg').find('#user_'+fail[i]).find('.info')[0].innerText = " Fail to login! ";
                }
                console.log(data);
            }
        });
    }

    function sync_friend() {
        if(localStorage['data'] == null){
            return;
        }
        var data = jQuery.parseJSON(localStorage['data']);
        console.log(data);
        //console.log()
        $.ajax({
            type: "POST",
            url: BACKENDURL + "/sync_friend",
            //contentType: "application/json; charset=utf-8",
            data: "data="+JSON.stringify(data),
            dataType: "json",
            success : function (data) {
                fail = data;
                var i = 0;
                all = $('#msg').find('.info');
                for(i=0; i<all.length; i++) {
                    all[i].innerText = " Sync done. "
                }
                for(i=0; i<fail.length; i++) {
                    $('#msg').find('#user_'+fail[i]).find('.info')[0].innerText = " Fail to login! ";
                }
                console.log(data);
            }
        });
    }

    setTimeout(function(){
        check_current_work();

        $("body").append(" <div id='cfmain' style='left: 10px;bottom: 10px;background: #C0C0C0;overflow: hidden;z-index: 9999;position: fixed;padding:5px;text-align:center;width:220px;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;'></div>");

        $('#cfmain').append("<div id='msg'></div>");
        refresh_msg()

        $('#cfmain').append('<div id="input"> </div>');
        $("#input").append('<textarea id="data" rows="8" cols="29"></textarea>')
        $('#input').append('<br>');

        if(localStorage['hideen'] != null) {
            localStorage['hideen'] = true;
        }
        $('#input')[0].hidden = localStorage['hideen'];

        if(localStorage['accounts'] != null) {
            $('#data')[0].value = localStorage['accounts'];
        }

        $('#cfmain').append('<button type="button" id="sync"  >同步好友</button>');
        $('#cfmain').append('<button type="button" id="edit"  >编辑账号</button>');
        $('#cfmain').append('<button type="button" id="exit"  >关闭窗口</button>');
        $('#cfmain').append('<br>');

        $('#data')[0].onblur = function() {
            localStorage['accounts'] = $('#data')[0].value;
            process_accounts_info();
            refresh_msg();
            check_unread_msg();
        }

        $('#sync').click(function(){
            //localStorage["preURL"] = document.URL;
            //login();

            sync_friend()
        });

        $('#edit').click(function(){
            var input = $('#input')[0];
            if(input.hidden) {
                check_unread_msg();
            }
            input.hidden = !input.hidden;
            localStorage['hideen'] = input.hidden;
        });

        $('#exit').click(function(){
            $('#cfmain').remove();
        });

        setInterval(check_unread_msg, 1000*30);

        //$('#cfmain').append('<input type="text" name="" id="TIME" style="width: 50" oninput="value=value.replace(/[^\\d]/g,\'\')">');

        if (localStorage["preURL"] != "") {
            var temp = localStorage["preURL"];
            alert("xxx");
            localStorage["preURL"] = "";
            window.location.href = temp;
        }
    },5000);
})();