Greasy Fork

Greasy Fork is available in English.

Total of all purchases

Calculates the sum of all completed orders that are visible on the page (scroll down to the end to count the orders for the entire time).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Total of all purchases
// @name:ru      Сумма покупок
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Calculates the sum of all completed orders that are visible on the page (scroll down to the end to count the orders for the entire time).
// @description:ru  Подсчитывает сумму всех завершенных заказов, которые видны на странице (прокрутите вниз до конца, чтобы подсчитать заказы за всё время).
// @author       Титан
// @match        https://www.aliexpress.com/p/order/index.html
// @match        https://trade.aliexpress.ru/orderList.htm*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=aliexpress.com
// @grant		 GM_registerMenuCommand
// @license      CC BY-NC-SA
// ==/UserScript==

let autoRedirect = true //Автоматически редиректить на нормальную страницу заказов

if (document.URL.indexOf("www.aliexpress.com")>=0)
	GM_registerMenuCommand("Подсчитать цены на этой странице", CalculateTotalPrice);
else
	if (autoRedirect) GoToNormalPage
	else
		GM_registerMenuCommand("Перейти на нормальную страницу заказов", GoToNormalPage)

function GoToNormalPage() {
	window.location.replace("https://www.aliexpress.com/p/order/index.html");
}

let finishedWords = ["Finished", "С отделкой"]; //: "Finished" word in all shitty AliExpress' translations

function CalculateTotalPrice() {
	let total = 0;
	let purchases = "";
	for(let item of document.querySelectorAll(".order-item")) {
		if (finishedWords.indexOf(item.querySelector(".order-item-header-status-text").textContent)<0) continue; //: checks is the order is finished
		let price = parseFloat(onlyNumbers(item.querySelector(".order-item-content-opt-price-total").textContent));
		let itemName = item.querySelector(".order-item-content-info-name")?.textContent;
		total+= price
		purchases+= "\n\n" + itemName + "\n>>> " + price + " <<<"
	}
	alert("Сумма покупок: " + total + "\n\nПокупки:" + purchases);
}

function onlyNumbers(str) {
	let num = ""
	let dot = false;
	for(char of str) {
		if(isNumber(char))
			num+=char;
		else
		if(!dot && (char == '.' || char == ","))
		{
			num+=".";
			dot = true;
		}
		else if (dot) {
			break;
		}
	}
	return num
}

function isNumber(c) { return c >= '0' && c <= '9'}