MoveBuy

Moves the "Yes" button on Torn item listings for speedy purchases

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         MoveBuy
// @author       realfakedoorz [2302156]
// @match        https://www.torn.com/imarket.php*
// @match        https://www.torn.com/pmarket.php*

// @description  Moves the "Yes" button on Torn item listings for speedy purchases
// @version 0.0.7
// @namespace https://greatest.deepsurf.us/users/517405
// ==/UserScript==


const hideSuccess = true; // Hides success box if true

const callbackIMarket = function() {
    if(document.contains(document.querySelector(".items > .active"))){

        var container = document.querySelector (".items > .active");
        var firstTargDiv = container.querySelector (".yes-buy");
        var lastTargDiv = container.querySelector (".buy-link");
        //-- Swap last to first.

        if (firstTargDiv){
            try {
                lastTargDiv.replaceWith(firstTargDiv);
            } catch(error) {
                return
            }
        }
        var endLink = container.querySelector(".yes-buy");
        if (endLink){
            endLink.classList.remove("m-left10");
        }

        if (hideSuccess){
            var succ = container.querySelector(".success-buy");
            succ.style.display = "none";
        }
    }
}

const callbackPMarket = function() {
        if(document.contains(document.querySelector(".ui-state-active"))){

        var container = document.querySelector (".ui-state-active").parentNode;
        var firstTargDiv = container.querySelector (".yes");
        var lastTargDiv = container.querySelector (".wai-btn");
        //-- Swap last to first.

        if (firstTargDiv){
            try {
                lastTargDiv.replaceWith(firstTargDiv);
            } catch(error) {
                return
            }
        }
    }
}

var observerIMarket = new MutationObserver(callbackIMarket);
var observerPMarket = new MutationObserver(callbackPMarket);

var items = document.getElementById("item-market-main-wrap");
var points = document.getElementsByClassName("users-point-sell")[0];

var config = { attributes: true, childList: true, subtree: true };

if (window.location.href.indexOf("imarket") > -1) {
    console.log('Observing for active item selection');
    observerIMarket.observe(items, config);
} else {
    console.log('Changed points market links');
    //observerPMarket.observe(points, config);
    for (var i = 0; i < document.getElementsByClassName("expander").length; i++){
        var hrefTo = (document.getElementsByClassName("expander")[i].getAttribute("href")).split("&")
        var btn = document.getElementsByClassName("expander")[i].getElementsByClassName("action")[0]

        btn.className = "yes wai-support"
        btn.setAttribute("href", (hrefTo[0] + "1&" + hrefTo[1]))

        btn.style.marginTop = "-1px"
        btn.style.paddingTop = "1px"
        btn.style.marginBottom = "-1px"
        btn.style.paddingBottom = "1px"

        var btnInner = btn.getElementsByTagName("button")[0]
        btnInner.className = ""
        btnInner.style.border = "None"
        btnInner.style.background = "Transparent"
}

}