One Bazaar

one bazaar, quick buying menu

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         One Bazaar
// @namespace    onebazaar.zero.nao
// @version      1.3.1
// @description  one bazaar, quick buying menu
// @author       nao
// @match        https://www.torn.com/bazaar.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none

// ==/UserScript==

let percentage = 50;

let toBuy = {};

let done = [];

let itemsdata = [];
let bought=[];

function update() {
    let content = ``;
    console.log(itemsdata);
    for (let val of itemsdata){
        console.log(val[2], bought);
        if (!bought.includes(val[2])){
            content += (val[1]);
        }
    }
    $("#itemList").html(content);
    $(".itembuynao").off("click");
    $(".itembuynao").on("click", async function () {
        let iid = $(this).attr("id");
        let iitemid = $(this).attr("itemid");
        let iamount = $(this).attr("amount");
        let iuid = $(this).attr("userid");
        let ip = $(this).attr("price");

        await buy(iuid, iid, iitemid, iamount, ip, "none");

    });


}

function insert() {
    let cont = `<div id="displayContainer" style="
    display: grid;
        grid-template-columns: 40% auto;
        background: rgb(51 177 227);
        width: 500px;
        bottom: 30px;
        right:0;
        height: 30%;
        color: yellow;
        border-radius: 10px;
        padding: 10px;
        position:fixed;

z-index:100000;



        ::-webkit-scrollbar {
                width: 5px;
            }

            ::-webkit-scrollbar-track {
                border-radius: 8px;
                background-color: #e7e7e7;
                border: 1px solid #cacaca;
            }

            ::-webkit-scrollbar-thumb {
                border-radius: 8px;
                background-color: #3b9ab7;
            }


    ">
        <div id="itemList" style=" overflow-y: scroll;">
        </div>
        <div id = "actionsHistory" style=" overflow-y: scroll;">
            <p class="actionsElement">{result}</p>



        </div>`;

    if ($("div[class^='topSection']").length == 0) {
        setTimeout(insert, 300);
        return;
    }

    if ($("#displayContainer").length == 0) {
        $(".content-wrapper").prepend(cont);

    }



}


async function buy(userid, id, itemid, amount, price, name) {
    var money = Math.floor(parseInt(document.getElementById('user-money').getAttribute('data-money')));
    //  amount = Math.min(Math.floor(money/price), amount);
    if (toBuy[name]){
        amount = Math.min(10, toBuy[name][3]);
    }




    await $.post(`https://www.torn.com/bazaar.php?sid=bazaarData&step=buyItem&rfcv=${getRFC()}`, {
        userID: userid,
        id: id,
        itemid: itemid,
        amount: amount,
        price: price,
        beforeval: price * amount

    }, function (response) {
        console.log(response);
        response = JSON.parse(response);
        console.log(response);
        addResult(response.text, response.success ? "green" : "red");
        if (response.success && response.text.includes("bought")){
            $(`#${id}`).remove();
            bought.push(id * 1);

            if (toBuy[name]){
                toBuy[name][3] = Math.max(0,toBuy[name][3]-10);
            }
            console.log(toBuy);
        }
    })

}

function addResult(resultMsg, rescol) {
    let curtime = $(".server-date-time").html().split("-")[0];
    let resmsg = `<p style="color: ${rescol}">${curtime} ${resultMsg}</p>`;
    $("#actionsHistory").prepend(resmsg);


}

function getRFC() {
    var rfc = $.cookie('rfc_v');
    if (!rfc) {
        var cookies = document.cookie.split('; ');
        for (var i in cookies) {
            var cookie = cookies[i].split('=');
            if (cookie[0] == 'rfc_v') {
                return cookie[1];
            }
        }
    }
    return rfc;
}


if (window.location.href.includes("userId")){


    insert();
    const { fetch: origFetch } = window;
    window.fetch = async (...args) => {
        console.log("onebazaar called with args:", args);

        const response = await origFetch(...args);

        /* work with the cloned response in a separate promise
     chain -- could use the same chain with `await`. */

        if (response.url && response.url.includes('/bazaar.php?sid=bazaarData&step=getBazaarItems')) {
            let clonedResponse = response.clone();
            let clonedJ = await clonedResponse.json();
            let uid = clonedJ.ID;

            // console.log("userid" + uid);


            for (let item of clonedJ.list) {
                let id = item.bazaarID * 1;

                

                let itemid = item.ID;

       

                let amount = item.amount;
                let price = item.price;
                let mv = item.averageprice;
                let isBlockedForBuying = item.isBlockedForBuying;
                let name = item.name.replace("'","");
                // console.log(item);

                toBuy[name] = [uid, id, itemid, amount, price];
                if (!isBlockedForBuying && parseInt(price) <= (100 - percentage) / 100 * mv && !done.includes(id)) {
                    let con = `<button style="color:white; margin:5px; height:40px" class="itembuynao torn-btn" userid=${uid} id=${id} itemid=${itemid} amount=${amount} price=${price}>${name} $${(price * amount).toLocaleString()}</button>`;

                    while ($("#itemList").length == 0) {

                        console.log("itemlist");

                    }
                    done.push(id);
                    itemsdata.push([parseInt(mv - price), con, id]);
                    

                }


            }


        }
        //  console.log(toBuy);
        itemsdata = itemsdata.sort(function (a, b) {
            return b[0] - a[0];


        });
        update();



        return response;
    };

}