Paid for things

New pips!

目前為 2023-05-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Paid for things
// @namespace    http://tampermonkey.net/
// @version      1.1.1
// @description  New pips!
// @author       tharglet
// @match        https://myfigurecollection.net/users.v4.php?*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('/manager.v4.php?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isPaid=1').then((response) => {
            return response.text();
        }).then((html) => {
            const doc = parser.parseFromString(html, 'text/html');
            const items = doc.querySelectorAll('.cell-0u a');
            if(items) {
                items.forEach((item) => {
                    paidItems.push(item.getAttribute('href'));
                });
            }
        }).catch(function (err) {
            console.warn('Something went wrong.', err);
        });
        await fetch('/manager.v4.php?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isShipped=1').then((response) => {
            return response.text();
        }).then((html) => {
            const doc = parser.parseFromString(html, 'text/html');
            const items = doc.querySelectorAll('.cell-0u 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);
            }
        });
    }
})();