Paid for things

New pips!

目前為 2024-02-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Paid for things
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  New pips!
// @author       tharglet
// @match        https://myfigurecollection.net/?*mode=view&*tab=collection&*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=myfigurecollection.net
// @grant        GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

//Polyfill for GM_addStyle for Greasemonkey...
if(typeof GM_addStyle == 'undefined') {
    GM_addStyle = (aCss) => {
        'use strict';
        let head = document.getElementsByTagName('head')[0];
        if (head) {
            let style = document.createElement('style');
            style.setAttribute('type', 'text/css');
            style.textContent = aCss;
            head.appendChild(style);
            return style;
        }
        return null;
    };
}

GM_addStyle(`
.item-is-paid {
    display: block;
    position: absolute;
    right: 1px;
    bottom: 1px;
    height: 16px;
    padding: 1px 2px 2px 3px;
    line-height: 16px;
    background-color: green;
    color: white;
}

.item-is-shipped {
    display: block;
    position: absolute;
    right: 1px;
    bottom: 1px;
    height: 16px;
    padding: 1px 2px 2px 3px;
    line-height: 16px;
    background-color: gold;
    color: white;
}

.icon-dollar:before {
    font-family: serif !important;
    content: "$";
    font-weight: bolder !important;
}

.icon-plane:before {
    font-family: serif !important;
    content: "🛩️";
    font-weight: bolder !important;
}
`);

(async function() {
    'use strict';

    const isUsersPreorderPage = () => {
        const urlParams = new URLSearchParams(window.location.search);
        const status = urlParams.get("status");
        if(status == 1) {
            let loggedInUser = $(".user-menu .handle");
            if(loggedInUser) {
                let userLink = loggedInUser.attr("href");
                if(userLink === "/session/signup") {
                    return false;
                } else {
                    let userParam;
                    const windowLocation = window.location.href;
                    if(windowLocation.startsWith("https://myfigurecollection.net/profile/")) {
                        userParam = windowLocation.match(/https:\/\/myfigurecollection\.net\/profile\/([^\/]*)/)[1];
                    } else {
                        const urlParams = new URLSearchParams(window.location.search);
                        userParam = urlParams.get("username");
                    }
                    return userParam === userLink.substring("9");
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    };
    if(isUsersPreorderPage()) {
        const paidItems = [];
        const shippedItems = [];
        const parser = new DOMParser();
        await fetch('/?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isPaid=1&_tb=manager').then((response) => {
            return response.text();
        }).then((html) => {
            const doc = parser.parseFromString(html, 'text/html');
            const items = doc.querySelectorAll('.cell-15u a');
            if(items) {
                items.forEach((item) => {
                    paidItems.push(item.getAttribute('href'));
                });
            }
        }).catch(function (err) {
            console.warn('Something went wrong.', err);
        });
        await fetch('/?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isShipped=1&_tb=manager').then((response) => {
            return response.text();
        }).then((html) => {
            const doc = parser.parseFromString(html, 'text/html');
            const items = doc.querySelectorAll('.cell-15u a');
            if(items) {
                items.forEach((item) => {
                    shippedItems.push(item.getAttribute('href'));
                });
            }
        }).catch(function (err) {
            console.warn('Something went wrong.', err);
        });
        const itemIcons = document.querySelectorAll('.item-icon a');
        itemIcons.forEach((item) => {
            if(shippedItems.includes(item.getAttribute('href'))) {
                const shippedPipContainer = document.createElement('span');
                shippedPipContainer.classList.add('item-is-shipped');
                const shippedPip = document.createElement('span');
                shippedPip.classList.add('tiny-icon-only', 'icon-plane');
                shippedPipContainer.appendChild(shippedPip);
                item.appendChild(shippedPipContainer);
            } else if(paidItems.includes(item.getAttribute('href'))) {
                const paidPipContainer = document.createElement('span');
                paidPipContainer.classList.add('item-is-paid');
                const paidPip = document.createElement('span');
                paidPip.classList.add('tiny-icon-only', 'icon-dollar');
                paidPipContainer.appendChild(paidPip);
                item.appendChild(paidPipContainer);
            }
        });
    }
})();