漂流瓶价格

显示漂流瓶每个瓶子的总重和价格(单件物品的瓶子无法显示)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         漂流瓶价格
// @namespace    https://hkfoggyu.github.io/
// @version      0.6
// @description  显示漂流瓶每个瓶子的总重和价格(单件物品的瓶子无法显示)
// @author       Young
// @supportURL   https://github.com/HKFoggyU/USTscripts
// @match        http://www.piaoliuhk.com/packageList.php
// @icon         http://www.piaoliuhk.com/css/images/favicon.ico
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

function getBottles() {
    let tds = document.getElementsByTagName("td");
    var bottles = [];
    for (var i=1; i<tds.length; i++) {
        if (tds[i].hasAttribute("rowspan")) {
            bottles.push(tds[i]);
        }
    }
    return bottles;
}

function calcWeightAndPrice(bottleNum) {
    var total = 0.0;
    let updatedNumber = 0;
    let addedNumber = 0;
    var trs = document.getElementsByTagName("tr");
    for (var i=1; i<trs.length; i++) {
        var tds = trs[i].getElementsByTagName("td");
        if (tds[1].innerText == bottleNum) {
            addedNumber += 1;
            if (tds[7].innerText != "") {
                total += parseFloat(tds[7].innerText);
                updatedNumber += 1;
            }
        }
    }
    var totalWeight = total.toFixed(1);
    var totalPriceHKD = totalWeight>1.0 ? (Math.ceil((totalWeight-1)/0.5)*3.5+12.5).toFixed(1) : 12.5;
    var totalPriceCNY = totalWeight>1.0 ? (Math.ceil((totalWeight-1)/0.5)*3.2+11.4).toFixed(1) : 11.4;
    return [updatedNumber, addedNumber, totalWeight, totalPriceHKD, totalPriceCNY];
}

(function() {
    'use strict';
    var bottles = getBottles();
    for (var i=0; i<bottles.length; i++) {
        var bottle = bottles[i];
        var bottleNum = bottle.innerText;
        var [updatedNumber, addedNumber, totalWeight, totalPriceHKD, totalPriceCNY] = calcWeightAndPrice(bottleNum);
        var outputText = `${bottle.innerText} (${updatedNumber}/${addedNumber} items, ${totalWeight} kg, ${totalPriceHKD} HKD, ${totalPriceCNY} CNY)`;
        bottle.innerText=outputText;
    }
    //window.scrollTo(0,document.body.scrollHeight);
})();