Greasy Fork is available in English.
This script automatically buys items at the lowest price on the Shop Search page.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/30965/203154/Subeta%20Autobuy.js
// ==UserScript==
// @name Subeta Autobuy
// @namespace http://artees.pw/
// @description This script automatically buys items at the lowest price on the Shop Search page.
// @version 0.3
// @author Artees
// @match *://subeta.net/user_shops.php/search/shops/*
// @match *://subeta.net/shop.php?shopid=*
// @grant none
// @icon https://subeta.net/favicon.ico
// @icon64 https://img.subeta.net/items/accessory_hustlermoneyclip.gif
// ==/UserScript==
const KEY_AUTOBUY_SOURCE = "autobuySource",
KEY_AUTOBUY_NPC = "autobuyNpc";
function autobuy() {
setTimeout(buy, 500);
function buy() {
var source = sessionStorage[KEY_AUTOBUY_SOURCE];
if (source === undefined) return;
sessionStorage.removeItem(KEY_AUTOBUY_SOURCE);
var rows = document.getElementsByClassName("row"),
items = [];
if (rows.length === 0) return;
for (var i = 0; i < rows.length; i++) {
var row = rows[i],
buttons = getButtons(row);
if (buttons.length === 0) continue;
items.push(row);
}
function getButtons(e) {
return e.getElementsByClassName("btn btn-primary btn-sm");
}
items.sort(comparePrices);
var item = items[0],
isNPC = item.innerText.indexOf("NPC Shop") !== -1;
if (isNPC) {
sessionStorage[KEY_AUTOBUY_NPC] = source;
}
var button = getButtons(item)[0],
nextButton = getButtons(items[1])[0],
count = 0;
button.click();
if (!isNPC) {
var sourceIntervalId = setInterval(openSource, 500);
}
function openSource() {
count++;
if (button.disabled && nextButton.disabled && count < 10) return;
open(source, "_self");
clearInterval(sourceIntervalId);
}
}
function comparePrices(a, b) {
var aPrice = getPrice(a),
bPrice = getPrice(b);
function getPrice(item) {
var itemText = item.innerHTML,
end = itemText.indexOf(" sP"),
start = itemText.lastIndexOf(">", end) + 1,
priceText = replaceAll(itemText.substring(start, end), ",", "");
return parseInt(priceText);
}
return aPrice - bPrice;
}
function replaceAll(target, searchValue, replaceValue) {
return target.replace(new RegExp(searchValue, 'g'), replaceValue);
}
back();
function back() {
if (document.body.textContent.indexOf("been put in your items") === -1) return;
var source = sessionStorage[KEY_AUTOBUY_NPC];
if (source === undefined) return;
sessionStorage.removeItem(KEY_AUTOBUY_NPC);
open(source, "_self");
}
}