The West - Player Checker

With this script you can easy check status of players

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            The West - Player Checker
// @description		With this script you can easy check status of players
// @author          neversleep1911
// @namespace       https://greasyfork.org/users/8637
// @include         http://*.the-west.*/game.php*
// @include         https://*.the-west.*/game.php*
// @version         2.0.2
// @grant           none
// @copyright       Copyright (c) 2015 neversleep1911
// @license         MIT (http://opensource.org/licenses/MIT)
// ==/UserScript==

(function(func) {
    var script;
    script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.textContent = "(" + func.toString() + ")();";
    document.body.appendChild(script);
    document.body.removeChild(script);
    return true;
})(function() {
    $(document).ready(function() {
        var I18n = function() {
            var DEFAULT_LANGUAGE, STRINGS, language;
            function I18n() {}
            DEFAULT_LANGUAGE = "en_US";
            STRINGS = {
                de_DE: {
                    buttons: {
                        check: "Prüfen",
                        save: "Speichern",
                    },
                    messages: {
                        empty_players: 'Spielernamen eingeben',
                        players_saved: 'Liste gespeichert!'
                    },
                    status: {
                        checking: 'Lädt...',
                        player_not_found: 'Spieler nicht gefunden',
                        homeless_player: 'Stadtlos',
                        player_not_sleeping: 'Schäft nicht'
                    }
                },
                en_US: {
                    buttons: {
                        check: "Check",
                        save: "Save",
                    },
                    messages: {
                        empty_players: 'Enter a list of players',
                        players_saved: 'Player list successfully saved!'
                    },
                    status: {
                        checking: 'Checking...',
                        player_not_found: 'Player not found',
                        homeless_player: 'Homeless player',
                        player_not_sleeping: 'Not sleeping'
                    }
                },
                ru_RU: {
                    buttons: {
                        check: "Проверить",
                        save: "Сохранить",
                    },
                    messages: {
                        empty_players: 'Введите список игроков с новой строки',
                        players_saved: 'Список игроков сохранён!'
                    },
                    status: {
                        checking: 'Проверка...',
                        player_not_found: 'Игрок не найден',
                        homeless_player: 'Игрок без города',
                        player_not_sleeping: 'Не спит'
                    }
                },
            };
            language = DEFAULT_LANGUAGE;
            I18n.language = function() {
                return language;
            };
            I18n.setLanguage = function(lang) {
                return language = STRINGS[lang] ? lang : DEFAULT_LANGUAGE;
            };
            I18n.tr = function(id) {
                var string;
                string = STRINGS[language];
                $(id.split(".")).each(function(k, v) {
                    return (string = string[v]) !== void 0;
                });
                return string || id;
            };
            return I18n;
        }();
        
        I18n.setLanguage(Game.locale);
        
        var PlayerChecker = {
            PlayerState: {
                Player_NotFound: -1,
                Player_Nomeless: -2
            }
        };
        PlayerChecker.check = function(players, before, after) {
            var result = [], ranking = [], currentPlayer = 0, saloonCache = [], nextPlayer, checkPlayer, nextSaloon, checkSaloon;
            nextPlayer = function() {
                if (++currentPlayer < players.length) checkPlayer(); else {
                    currentPlayer = 0;
                    checkSaloon();
                }
            };
            checkPlayer = function() {
                var player = players[currentPlayer].trim();
                Ajax.remoteCallMode("ranking", "get_data", {
                    rank: NaN,
                    search: player,
                    tab: "experience"
                }, function(json) {
                    var found = false;
                    for (var j = 0; j < json.ranking.length; j++) {
                        if (json.ranking[j].name.toLowerCase() == player.toLowerCase()) {
                            ranking.push(json.ranking[j]);
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        ranking.push(PlayerChecker.PlayerState.Player_NotFound);
                    }
                    nextPlayer();
                });
            };
            nextSaloon = function() {
                if (++currentPlayer < ranking.length) checkSaloon(); else after(result);
            };
            checkSaloon = function() {
                var player = ranking[currentPlayer];
                if (player == PlayerChecker.PlayerState.Player_NotFound) {
                    result.push(PlayerChecker.PlayerState.Player_NotFound);
                    nextSaloon();
                    return;
                }
                if (player.town_id == null) {
                    result.push(PlayerChecker.PlayerState.Player_Nomeless);
                    nextSaloon();
                    return;
                }
                var findPlayer = function(saloon, id) {
                    for (var i = 0; i < saloon.players.length; i++) {
                        if (saloon.players[i].player_id == id) return saloon.players[i];
                    }
                    return null;
                };
                for (var i = 0; i < saloonCache.length; i++) {
                    if (saloonCache[i].town_id == player.town_id) {
                        player = findPlayer(saloonCache[i].saloon, player.player_id);
                        if (player) result.push(player);
                        nextSaloon();
                        return;
                    }
                }
                Ajax.remoteCallMode("building_saloon", "get_data", {
                    town_id: player.town_id
                }, function(json) {
                    saloonCache.push({
                        town_id: player.town_id,
                        saloon: json
                    });
                    player = findPlayer(json, player.player_id);
                    if (player) result.push(player);
                    nextSaloon();
                });
            };
            before();
            checkPlayer();
        };
        PlayerChecker.showWindow = function() {
            var wnd = wman.open("tw-playerchecker-window", null, "noreload").setTitle("Player Checker").setMiniTitle("Player Checker").addEventListener("WINDOW_DESTROY", function() {});
            
            //var tablePlayers = new west.gui.Table().addColumns(['status', 'duel_level', 'distance']);
            //tablePlayers.setHeight(315).setWidth(450);
            //$(tablePlayers.getMainDiv()).css({position: 'absolute', width: 470, height: 335, left: 220, top: 0});
            
            var txtPlayers = new west.gui.Textarea(undefined);
            txtPlayers.setHeight(315).setWidth(200);
            
            try {
                txtPlayers.textarea.val(localStorage.getItem("players") || Character.name);
            } catch (e) {
                new UserMessage(e, UserMessage.TYPE_ERROR).show();
            }
    
            var txtLog = new west.gui.Textarea(undefined);
            txtLog.setReadonly().setHeight(315).setWidth(450);
            
            $(txtLog.getMainDiv()).css("position", "absolute").css("left", "220px");
            var button = new west.gui.Button(I18n.tr('buttons.check'), function() {
                var text = txtPlayers.textarea.val().trim();
                if (text == "") {
                    new UserMessage(I18n.tr('messages.empty_players'), UserMessage.TYPE_HINT).show();
                    return;
                }
                txtLog.textarea.val(I18n.tr('status.checking'));
                PlayerChecker.check(text.split("\n"), function() { wnd.showLoader(); }, function(players) {
                    var tmp = SaloonWindow.self;
                    if (SaloonWindow.self && SaloonWindow.self.confAfterDeath === undefined) {
                        SaloonWindow.self.confAfterDeath = 48;
                    }
                    text = "";
                    for (var i = 0; i < players.length; i++) {
                        var player = players[i];
                        if (player == PlayerChecker.PlayerState.Player_NotFound) {
                            text += I18n.tr('status.player_not_found') + "\n";
                        } else if (player == PlayerChecker.PlayerState.Player_Nomeless) {
                            text += I18n.tr('status.homeless_player') + "\n";
                        } else {
                            text += SaloonWindow.playerStat(player).replace(/(<([^>]+)>)/gi, "");
                            if (!(player.isSleeping || player.isSleepingFort)) {
                                text += " | " + I18n.tr('status.player_not_sleeping');
                            }
                            text += " | " + player.duel_level + " | " + Character.calcWayTo(player.x, player.y).formatDuration() + "\n";
                        }
                    }
    
                    txtLog.textarea.val(text);
                    SaloonWindow.self = tmp;
                    wnd.hideLoader();
                });
            });
            $(button.getMainDiv()).css("position", "absolute").css("left", "0").css("top", "342px");
            var buttonSave = new west.gui.Button(I18n.tr('buttons.save'), function() {
                try {
                    var text = txtPlayers.textarea.val().trim();
                    localStorage.setItem("players", text);
    
                    new UserMessage(I18n.tr('messages.players_saved'), UserMessage.TYPE_SUCCESS).show();
                } catch (e) {
                    new UserMessage(e, UserMessage.TYPE_ERROR).show();
                }
            });
            $(buttonSave.getMainDiv()).css("position", "absolute").css("left", 104).css("top", 342);
            wnd.appendToContentPane(txtPlayers.getMainDiv());
            //wnd.appendToContentPane(tablePlayers.getMainDiv());
            wnd.appendToContentPane(txtLog.getMainDiv());
            wnd.appendToContentPane(button.getMainDiv());
            wnd.appendToContentPane(buttonSave.getMainDiv());
        };
        var menuImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAZCAYAAABzVH1EAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wIXBSQ1OSLfcgAACxtJREFUWMOt1tuP3ddVwPHv3r/9+53f7dznzMUzHo89jhM7rh1HaS51m5KUiIBSgloqgZCKoPSlSIgHVC4SAiEhwR/AY6XygADxgIhKJUQpTVEIbVLHiRzHl9jjGXvmzMw5c+bcz++29+bBhr7xwGS9L332XmvtpS3++KsXbXunS2P+Ejfu38GOJpSDmMyfEukyQSVhVghqcZ1RmnI46BPogqFrqKOgsFSjGvv9CZt7PbpZAsphLq6gZylLtYALZxu0dxLmFpfYuL9DNp1QqTUYjw1x3aACMIlPrRwynRrG/QHGSyhygfE1ca7wwoiD7oC9/oiDaY4sSWKnhLKaVqWE+JNfvmQff/IS3/yLb9PWBlEASlIYi2NdrHUxIkFZjUZipcUzDpmQlGxI5vSROFijMVYSKJ+8mHGsAr//e19j/8oPcfyQE6df4Or1a+ynY6wAXWSURBkYkiQKtxSg/TFFKlFWUKiUUlrH+Br0GGElxkg0Gtd1cURGrVTm6fNPsnHlLcRvfuGMvXVzjysPhgQNn2989Ys8dmKJdqfLxkaH67fukuuC4e4hGeAqhywpmFgNWHJt8dwSk9mEIneQCGyRY7TmpctP8o3XzvJP37vC1Y+7NJbrVJsVXv78syzPzTEZTrnX3mHr/i6h8OhO9imhiEKfQZagMkXmGpT0yJKU2WSCkCFCKop8hkJQKVX4xc8uokDQnQzRnkMkHc4/tsLTF8+gjWHjQZfZGw6/9ksvcO3mNgJDp3NIFHhcu7WFI2EyHDGbZfTGCRW3zGEyYDrtcziY8e6H17jx8kWceoOxnHCuWWU4HLLSbHHm9Am0MVTm5ri+MeH1R4aSht7hiNWyz62NB9SUAm0Y531EVGV1ucVg2KdpJO3eITf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ZMpjMOemN+cm3z/2c4kp37bZTNifSYleU64jPn1+2VG3cJ/BKNSsiwN0T5HlmWoxyHJEkJo4jZLKUSR0ymE4IwJApKCEcQ+j6BL4lCn1o1ZjSecrg7oHPQBms5sVzCsTV+cGuP1cUq/f4Iw6OtJQRaa/K8wJESpRyCKERaMFhC38WREulIGrUIVylqtZh+f4w71gg9ZKvTYXW1iXr9c2sMDjtsHyQ45LSaLtoaRKAeftwin0IaKoHC2AS/6iJEBlmClpZhIhgJB6zBWKhVG8RhmWRbs3Ii4OTKPJ8/+xSZfY8ffrRF7EdYWVAYQ57laGNxpENJuSQ59PcHuMohL/T/jhNYPFegtcVikULylRef490P7vDEydN4vsX5+guLf3ruicf48fXbtAdQDwImxhKUAvQECs9hOnNwsThSkqdQFA65CJCJxWhJKYyYGUNhcjb3x4x2u6yeiHnpZ5/FtDc4vhrw1IXLbN+5wcyxtKKAhUbCajVmKYLVVpOmO0Erw9mFkFjB3EKTtajEsTlJrBWtxTqnT9QokoxjseTNG/c4/tQyX3q6iSr2EH/+q8/aipTc3NujPS5YXlygN0ppH04YTyaQTai35giEoQLELnglh0pYIqw7+B5MEkvQWGDa7dEdjjD2gFc+u46n+1y9VycfK6oK7vVztjq7HDu2zCSzbO/3GOQF6bBHww9w6zGNsWChqpg4M5aiABU5VGrOo76AVCv0u5u4+wNOXq6g4yabWw/4bz9uBjNvtQs2AAAAAElFTkSuQmCC';
        var menuButton = $("<div class='menulink' title='Player Checker' />");
        menuButton.css("background-image", "url(" + menuImage + ")");
        menuButton.hover(function() {
            $(this).css("background-position", "-25px 0px");
            return true;
        }, function() {
            $(this).css("background-position", "0px 0px");
            return true;
        }).on("click", function() {
            PlayerChecker.showWindow();
            return false;
        });
        $("div#ui_menubar").append($('<div class="ui_menucontainer" />').append(menuButton).append('<div class="menucontainer_bottom" />'));
    });
});