Last active
August 17, 2023 15:45
-
-
Save dragoncity17/f3a96f1af7fd94cf9aa4f57db08a3650 to your computer and use it in GitHub Desktop.
AliExpress Prix Total
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name AliExpress Prix Total | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Affiche le prix total en dessous du prix d'achat sur les pages AliExpress. | |
| // @author DragonCity | |
| // @match *://*.aliexpress.com/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // Fonction pour extraire le prix du format texte | |
| function extractPrice(text) { | |
| const priceRegex = /(\d+(\.\d{1,2})?)/; | |
| const match = text.match(priceRegex); | |
| return match ? parseFloat(match[0].replace(',', '.')) : 0; | |
| } | |
| // Fonction pour mettre à jour le prix total | |
| function updateTotalPrice() { | |
| const purchasePriceElement = document.querySelector('.product-price-current'); | |
| const shippingPriceElement = document.querySelector("#root > div.pdp-wrap.pdp-body > div.pdp-body-right > div > div > div.shipping--wrap--Dhb61O7 > div > div > div.dynamic-shipping-line.dynamic-shipping-titleLayout > span > span > strong"); | |
| const quantityInputElement = document.querySelector('#root > div.pdp-wrap.pdp-body > div.pdp-body-right > div > div > div:nth-child(7) > div.comet-input-number.quantity--picker--Zeoj1SK > input'); | |
| if (purchasePriceElement && quantityInputElement) { | |
| const purchasePrice = parseFloat(purchasePriceElement.textContent.replace(/[^0-9.,]/g, '').replace(',', '.')); | |
| const quantity = parseFloat(quantityInputElement.value); | |
| let shippingPrice = 0; // Default value for shipping price | |
| if (shippingPriceElement) { | |
| const shippingPriceText = shippingPriceElement.textContent; | |
| if (shippingPriceText.includes("Free Shipping") || shippingPriceText.includes("Livraison gratuite")) { | |
| shippingPrice = 0; | |
| } else { | |
| shippingPrice = parseFloat(shippingPriceText.replace(/[^\d.,]/g, '').replace(',', '.')); | |
| } | |
| } | |
| const totalPrice = (purchasePrice * quantity) + shippingPrice; | |
| const totalPricePerArticle = totalPrice / quantity; | |
| const totalPriceTextElement = document.querySelector('.total-price'); | |
| if (totalPriceTextElement) { | |
| totalPriceTextElement.textContent = 'TOTAL : ' + totalPrice.toFixed(2) + '€'; | |
| } else { | |
| const newTotalPriceTextElement = document.createElement('div'); | |
| newTotalPriceTextElement.className = 'total-price'; | |
| newTotalPriceTextElement.style.marginTop = '10px'; | |
| newTotalPriceTextElement.style.fontSize = '25px'; | |
| newTotalPriceTextElement.style.fontWeight = 'bold'; | |
| newTotalPriceTextElement.style.color = 'red'; | |
| newTotalPriceTextElement.textContent = 'TOTAL : ' + totalPrice.toFixed(2) + '€'; | |
| purchasePriceElement.parentNode.insertBefore(newTotalPriceTextElement, purchasePriceElement.nextSibling); | |
| } | |
| const perArticlePriceTextElement = document.querySelector('.per-article-price'); | |
| if (!perArticlePriceTextElement) { | |
| const newPerArticlePriceTextElement = document.createElement('div'); | |
| newPerArticlePriceTextElement.className = 'per-article-price'; | |
| newPerArticlePriceTextElement.style.marginTop = '5px'; | |
| newPerArticlePriceTextElement.style.fontSize = '18px'; | |
| newPerArticlePriceTextElement.style.fontWeight = 'bold'; | |
| newPerArticlePriceTextElement.style.color = 'blue'; | |
| newPerArticlePriceTextElement.textContent = 'Prix (Pcs) : ' + totalPricePerArticle.toFixed(2) + '€'; | |
| purchasePriceElement.parentNode.insertBefore(newPerArticlePriceTextElement, purchasePriceElement.nextSibling); | |
| } else { | |
| perArticlePriceTextElement.textContent = 'Prix (Pcs) : ' + totalPricePerArticle.toFixed(2) + '€'; | |
| } | |
| } | |
| } | |
| // Mettre à jour le prix total lorsque la page est chargée ou modifiée | |
| window.addEventListener('load', updateTotalPrice); | |
| window.addEventListener('DOMSubtreeModified', updateTotalPrice); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment