Market Page Jump

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();