ActionSearch

Searches mod actions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ActionSearch
// @namespace    https://greasyfork.org/en/users/9694-croned
// @version      1.1
// @description  Searches mod actions
// @author       Croned
// @match        https://epicmafia.com/moderator
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
 var findId = function (name, cb) {
        var id;
        $.get("https://epicmafia.com/user/search?q=" + name, function (data) {
            data = data.data;
            if (data.length > 0) {
                id = data[0].id;
                cb(id);
            }
            else {
                alert("User not found!");
				loadpage_actions(1);
            }
        });
    };

    var getModAct = function (mod, amt, cb) {
        var page = 1;
        var list = [];
        var x;
        var cb1 = function (data) {
            data = JSON.parse(data).data;
            for (x in data) {
                if (data[x]["user_id"] == mod) {
                    list.push(data[x]);
                }
            }
            page ++;
            if (page <= amt) {
                getActionPage(page, cb1);
            }
            else {
                cb(list);
            }
        }
        var cb2 = function (data) {
            data = JSON.parse(data).data;
            for (x in data) {
                list.push(data[x]);
            }
            page ++;
            if (page <= amt) {
                getActionPage(page, cb2);
            }
            else {
                cb(list);
            }
        };

        if (mod) {
            getActionPage(page, cb1);
        }
        else {
            getActionPage(page, cb2);
        }
    };

    var getByTarget = function (id, name, list, cb) {
        name = name.toLowerCase();
        var newList = [];
        for (var x in list) {
            if (list[x].name.toLowerCase().indexOf(id) != -1 || list[x].name.toLowerCase().indexOf(name) != -1) {
                newList.push(list[x]);
            }
        }
        cb(newList);
    }

    var getActionPage = function (page, cb) {
        $.get("https://epicmafia.com/action/page?page=" + page, function (data) {
            cb(data);
        });
    };

    var setPage = function (list) {
        $("#actionpages").html(window.get_template("actions")({data: list}));
    }

    $("#mod_actions h3").html($("#mod_actions h3").html() + '<a id="searchModAct" style="float: right; color: white; text-decoration: none; font-weight: normal;">Advanced search »</a>');
	
    $("#mod_actions h3").after(
		'<div id="search" style="display: none;">\
			<form id="searchForm" class="forum_default">\
				<div id="searchInput" style="text-align: center; padding: 5px;">\
					<input type="text" id="pA" placeholder="Any Mod" style="width: 80px;" autocomplete="off" /> did actions on <input type="text" id="pB" placeholder="Any User" style="width: 80px;" autocomplete="off" /> in the last <input type="text" id="amt" placeholder="amount" value="10" style="width: 80px; margin-top: 3px;" autocomplete="off" /> pages.\
				</div>\
				<input type="submit" value="Search" class="redbutton" style="display: block; font-size: 0.9em; margin: 5px auto 5px auto;" />\
				<a id="clearActions" style="display: block; margin: auto; text-align: center; font-size: 13px; margin-bottom: 10px;">Clear</a>\
			</form>\
		</div>'
	);

    $("#searchModAct").click(function () {
        $("#search").toggle();
    });

    $("#searchForm").submit(function (e) {
        e.preventDefault();
        $("#actionpages").html('<img src="http://i.imgur.com/1keL4Ac.gif" id="loadingList" width="25" height="25" style="display: block; margin: auto;">');

        var pA = $("#pA").val();
        var pB = $("#pB").val();
        var amt = $("#amt").val();

        if (pA && amt) {
            findId(pA, function (id) {
                getModAct(id, amt, function (list) {
                    if (pB) {
                        findId(pB, function (id) {
                            getByTarget(id, pB, list, function (list) {
                                setPage(list);
                            });
                        });
                    }
                    else {
                        setPage(list);
                    }
                });
            });
        }
        else if (amt) {
            getModAct(null, amt, function (list) {
                if (pB) {
                    findId(pB, function (id) {
                        getByTarget(id, pB, list, function (list) {
                            setPage(list);
                        });
                    });
                }
                else {
                    setPage(list);
                }
            });
        }
        else {
            alert("You must enter a page amount!");
			loadpage_actions(1);
        }
    });

    $("#clearActions").click(function () {
        loadpage_actions(1);
    });
})();