Pandabuy Cart Conversion Prices

Converts Pandabuy CNY prices to provided currency using provided exchange rate

  1. // ==UserScript==
  2. // @name Pandabuy Cart Conversion Prices
  3. // @namespace Scope
  4. // @version 0.1
  5. // @description Converts Pandabuy CNY prices to provided currency using provided exchange rate
  6. // @author Scope
  7. // @include https://www.pandabuy.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11. 'use strict';
  12.  
  13. const EXCHANGE_RATES = {
  14. "AUD": ["$", 4.66, "AUD"],
  15. "USD": ["", 6.89, "USD"],
  16. "CAD": ["", 5.11, "CAD"]
  17. }
  18.  
  19. const EXCHANGE_DATA = EXCHANGE_RATES["AUD"]
  20. const EXCHANGE_RATE = EXCHANGE_DATA[1]
  21. const EXCHANGE_CURRENCY = EXCHANGE_DATA[0]
  22. let ITEMS_COST = 0
  23. let SHIPPING_COST = 0
  24.  
  25.  
  26.  
  27. function convert() {
  28. const prices = document.getElementsByClassName('linethrow')
  29. Object.keys(prices).forEach(x => {
  30. let unconverted_price = prices[x].outerText.toString().replace(`¥ `,``)
  31. let converted_price = (parseInt(unconverted_price)/EXCHANGE_RATE).toFixed(2)
  32. ITEMS_COST+=parseInt(converted_price)
  33. document.getElementsByClassName('total center el-col el-col-3')[x].outerHTML = `<div data-v-f5a49c88="" class="total center el-col el-col-3">${EXCHANGE_CURRENCY}${converted_price} ${EXCHANGE_DATA[2]}</div>`
  34. })
  35. }
  36.  
  37. function overall_convert() {
  38. const totalelement = document.getElementsByClassName('inline-block account-price account-price-totalPrice')[0]
  39. const convertMoneyElement = document.querySelector("#app > div.person-center > div.center > div > div.content-right > div > div > div.cart-container > div.all-select-bottom.clearfix > div.shops-total-price > span > div > p:nth-child(2) > i")
  40. const price = (parseInt(totalelement.outerText.replace("¥",""))/EXCHANGE_RATE).toFixed(2)
  41. convertMoneyElement.classList.add(['account-price'],['account-price-totalPrice'])
  42. convertMoneyElement.innerText = `${EXCHANGE_CURRENCY} ${price}`
  43. }
  44.  
  45.  
  46. setInterval(function(){
  47. overall_convert()
  48. convert()
  49. }, 1000)