Greasy Fork

来自缓存

Greasy Fork is available in English.

AliExpress Total Price

Display total price (including shipping) on AliExpress item pages

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        AliExpress Total Price
// @namespace   forked_bytes
// @match       https://*.aliexpress.com/*
// @match       https://*.aliexpress.us/*
// @grant       none
// @version     1.9
// @author      forked_bytes
// @license     0BSD
// @description Display total price (including shipping) on AliExpress item pages
// ==/UserScript==

const total = document.createElement('h2');
total.style.fontSize = '2em';
total.style.margin = '0.25em 0 0';

setInterval(function() {
  // Find price, shipping, quantity
  const priceElement = document.querySelector('.product-price-current, .dcss-price-first, .pdp-comp-price-current, span[class^="price-default--current--"]');
  if (!priceElement) return;

  const shippingElement = document.querySelector('.dynamic-shipping-line, div[ae_button_type="sku_shipmethod_click"]');
  const quantityElement = document.querySelector('div[class*="quantity--picker"] input');

  // Parse element text
  const [price, prefix, suffix] = parse(priceElement.textContent);
  const [shipping] = shippingElement?.textContent.includes(':') ? parse(shippingElement?.textContent) : [0];
  const quantity = parseInt(quantityElement?.value) || 1;

  // Add total price to DOM
  if (price) total.textContent = `Σ ${prefix}${(price * quantity + shipping).toFixed(2)}${suffix}`;
  if ((shipping || quantity > 1) && !total.isConnected) priceElement.parentNode.parentNode.appendChild(total);
}, 500);

function parse(text) {
  // Find number and currency (before or after)
  // May contain spaces, commas or periods as decimal or thousands separators
  const match = text?.match(/([^\d\s-]*)(\d[\d\s.,]*\d|\d)([^\d\s-]*)/);
  if (!match) return [0, '', ''];

  let [, prefix, price, suffix] = match;
  price = price.replace(/\s/g, '').split(/\D+/); // Remove whitespace and split on non-digit characters
  if (!prefix && !suffix && price.length <= 1) return [0, '', ''];

  // Assume the last non-digit was the decimal separator
  price = price.length > 1 ? price.slice(0, -1).join('') + '.' + price[price.length - 1] : price[0];
  return [parseFloat(price), prefix, suffix];
}