Greasy Fork

来自缓存

Greasy Fork is available in English.

Neopets: Shop stock price check

Adds a button to automatically check the prices of that page

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Neopets: Shop stock price check
// @author       Tombaugh Regio
// @version      1.0
// @description  Adds a button to automatically check the prices of that page
// @namespace    http://greasyfork.icu/users/780470
// @match        http://www.neopets.com/market.phtml?type=your*
// @match        https://items.jellyneo.net/tools/shop-stock-price-checker/
// @grant        GM_openInTab
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// ==/UserScript==

const URL = document.URL

if (URL.includes("neopets")) {
    const title = document.querySelector(".content").querySelector("table").nextSibling.nextSibling.nextSibling.nextSibling

    //Add a price checker button
    const itemCheckerButton = document.createElement("button")
    const itemCheckerLink = document.createElement("a")
    itemCheckerButton.innerText = "Check prices on this page"
    itemCheckerButton.style.margin = "0 0.5em"

    //Get the entire HTML of this page
    GM_xmlhttpRequest({
        method: 'GET',
        url: URL,
        headers: {
            'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
            'Accept': 'application/atom+xml,application/xml,text/xml',
        },
        onload: function(responseDetails) {
            return new Promise((resolve, reject) => {
                resolve(GM_setValue("allHTML", responseDetails.responseText))
            })
        }
    })

    //Open the price checker page
    itemCheckerButton.onclick = e => {
        e.preventDefault()
        GM_openInTab("https://items.jellyneo.net/tools/shop-stock-price-checker/")
    }

    //Append button after title
    title.after(itemCheckerButton)
}

if (URL.includes("shop-stock-price-checker")) {
    const inputTextArea = document.querySelector("#price-check-code")
    const priceCheckButton = document.querySelector("#price-check-submit")
    const sdbPage = GM_getValue("allHTML")

    inputTextArea.textContent = sdbPage

    if (inputTextArea.textContent.length > 0) priceCheckButton.click()
}