BT:QC - Upload parcel

Adds BT-QC button next to Tips

当前为 2023-11-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         BT:QC - Upload parcel
// @version      0.1.1
// @namespace    https://www.reddit.com/user/BasetaoKaj
// @description  Adds BT-QC button next to Tips
// @author       BasetaoKaj
// @match        https://www.basetao.com/*my_account/parcel/*
// @match        https://basetao.com/*my_account/parcel/*
// @match        https://www.basetao.com/best-taobao-agent-service/my_account/support_tools.html
// @match        https://basetao.com/best-taobao-agent-service/my_account/support_tools.html
// @grant        none
// @license      MIT
// @icon         https://basetao.com/style/index/img/favicon.png
// ==/UserScript==

(function () {
    "use strict";

    // Functie om de gegevens naar de PHP-script te verzenden
    function sendDataToServer(item) {
        // Gegevens om naar de server te verzenden
        const data = {
            sid: item.sid,
            uname: item.uname,
            oids: item.oids,
            freight: item.freight,
            countmoney: item.countmoney,
            serverfee: item.serverfee,
            customsfee: item.customsfee,
            operationfee: item.operationfee,
            totalfee: item.totalfee,
            deliveryname: item.deliveryname,
            Insurancefee: item.Insurancefee,
            countweight: item.countweight,
            actualWeight: item.actualWeight,
            actualFreight: item.actualFreight,
            iosstax: item.iosstax,
            iossdeclare: item.iossdeclare,
            rehearsal_fee: item.rehearsal_fee,
            packing_fee: item.packing_fee,
            insurance: item.insurance,
            waterproof_fee: item.waterproof_fee,
            corner_fee: item.corner_fee
        };

        // Voer een POST-verzoek uit naar het PHP-script
        fetch("https://bt-qc.com/func-parcelupload", {
            method: "POST",
            body: JSON.stringify(data),
            headers: {
                "Content-Type": "application/json"
            }
        })
        .then(response => response.text())
        .then(responseText => {
            console.log(responseText); // Toon het antwoord van de server in de console
            // Toon een zichtbare bevestiging
            const confirmationMessage = document.createElement("div");
            confirmationMessage.textContent = "Data pushed to BT:QC!";
            confirmationMessage.style.backgroundColor = "green";
            confirmationMessage.style.color = "white";
            confirmationMessage.style.padding = "10px";
            confirmationMessage.style.position = "fixed";
            confirmationMessage.style.top = "10px";
            confirmationMessage.style.right = "10px";
            confirmationMessage.style.borderRadius = "5px";
            confirmationMessage.style.zIndex = "9999";

            document.body.appendChild(confirmationMessage);

            // Verberg de zichtbare bevestiging na 2 seconden
            setTimeout(() => {
                confirmationMessage.style.display = "none";
            }, 5000);
        })
        .catch(error => {
            console.error("Fout bij het verzenden van gegevens naar de server: " + error);
        });
    }

    // Functie om knoppen toe te voegen aan een specifieke tabel
    function addButtonsToTable(tableId) {
        const $container = $(tableId);

        $container.on("load-success.bs.table", (e, data) => {
            data.rows.forEach((item) => {
                // If no payid exists, just skip this item
                if (!item.sid || item.sid === "") {
                    return;
                }

                const $item = $(`[data-uniqueid="${item.sid}"]`);
                $item.find("td:first-child span.btn-danger-soft.badge.listtipmodal").remove();
                const $orderBadge = $item.find("td:nth-child(1) > span.badge.bg-secondary.me-1");
                const $payId = $(`<a href="#" class="bg-info badge me-1">Push to BT-QC</a>`);

                // Voeg een click-event toe aan de knop
                $payId.click(function (event) {
                    event.preventDefault(); // Voorkom het standaardgedrag van een link
                    sendDataToServer(item); // Roep de functie aan om de gegevens naar de server te verzenden
                });

                $orderBadge.after($payId);
            });
        });
    }

    // Roep de functie tweemaal aan, eenmaal voor #table en eenmaal voor #table2
    addButtonsToTable("#table");
    addButtonsToTable("#table2");
})();