Market Page Jump

A script that allows user to jump pages in market items.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Market Page Jump
// @namespace    https://coding.net/u/sffxzzp
// @version      0.2.2
// @description  A script that allows user to jump pages in market items.
// @author       sffxzzp
// @match        *://steamcommunity.com/market
// @match        *://steamcommunity.com/market/
// @match        *://steamcommunity.com/market/listings/*/*
// @match        *://steamcommunity.com/market/search*
// @icon         https://store.steampowered.com/favicon.ico
// ==/UserScript==

(function() {
    var ifHistory = false;
    function loadHis () {
        var list = document.getElementById('tabContentsMyMarketHistory');
        if (list.childElementCount > 1) {
            ifHistory = true;
            main();
        }
        else {
            setTimeout(function(){loadHis();}, 200);
        }
    }
    function main () {
        var oriPageDiv;
        if (window.location.pathname.replace(/\//g, '') == "market") {
            var mHistory = document.getElementById('tabMyMarketHistory');
            mHistory.onclick = function () {
                setTimeout(function(){loadHis();}, 200);
            };
            if (ifHistory) {
                oriPageDiv = document.getElementById('tabContentsMyMarketHistory_ctn');
            }
            else {
                oriPageDiv = document.getElementById('tabContentsMyActiveMarketListings_ctn');
            }
        }
        else {
            oriPageDiv = document.getElementById('searchResults_ctn');
        }
        var oriPageCtl = oriPageDiv.children[1];
        var newPageCtl = document.createElement("div");
        newPageCtl.setAttribute("style", "float: right; padding-right: 20px");
        var newPageInput = document.createElement("input");
        newPageInput.setAttribute("class", "filter_search_box market_search_filter_search_box");
        newPageInput.setAttribute("style", "width: 30px;");
        newPageInput.setAttribute("type", "text");
        newPageInput.setAttribute("autocomplete", "off");
        newPageCtl.appendChild(newPageInput);
        var newPageGo = document.createElement("span");
        newPageGo.setAttribute("class", "pagebtn");
        if (window.location.pathname.replace(/\//g, '') == "market") {
            if (ifHistory) {
                newPageGo.onclick = function () {
                    g_oMyHistory.GoToPage( (newPageInput.value-1), true );
                };
            }
            else {
                newPageGo.onclick = function () {
                    g_oMyListings.GoToPage( (newPageInput.value-1), true );
                };
            }
        }
        else {
            newPageGo.onclick = function () {
                g_oSearchResults.GoToPage( (newPageInput.value-1), true );
            };
        }
        newPageGo.innerHTML = "Go!";
        newPageCtl.appendChild(newPageGo);
        oriPageDiv.insertBefore(newPageCtl, oriPageCtl);
        if (window.location.pathname.replace(/\//g, '') != "market") {
            var newPageSizeInput = document.createElement("input");
            newPageSizeInput.setAttribute("class", "filter_search_box market_search_filter_search_box");
            newPageSizeInput.setAttribute("style", "width: 30px;");
            newPageSizeInput.setAttribute("type", "text");
            newPageSizeInput.setAttribute("autocomplete", "off");
            var newPageSizeGo = document.createElement("span");
            newPageSizeGo.setAttribute("class", "pagebtn");
            newPageSizeGo.onclick = function () {
                g_oSearchResults.m_cPageSize = newPageSizeInput.value;
                g_oSearchResults.m_cMaxPages = Math.ceil(g_oSearchResults.m_cTotalCount / newPageSizeInput.value);
                g_oSearchResults.GoToPage(g_oSearchResults.m_iCurrentPage, true);
            };
            newPageSizeGo.innerHTML = "修改";
            var newPageSizeCtl = document.createElement("div");
            newPageSizeCtl.setAttribute("class", "market_pagesize_options");
            newPageSizeCtl.setAttribute("style", "margin: 0 0 2em 0; font-size: 12px;");
            newPageSizeCtl.innerHTML = "每页显示数:		";
            newPageSizeCtl.appendChild(newPageSizeInput);
            newPageSizeCtl.appendChild(newPageSizeGo);
            document.getElementById('searchResults_ctn').appendChild(newPageSizeCtl);
        }
    }
    main();
})();