// ==UserScript== // @name Price Converter with Tax for Specific Websites // @namespace http://tampermonkey.net/ // @version 0.6 // @description Convert price tags on websites // @author Nears // @match *://*.newegg.ca/* // @match *://*.canadacomputers.com/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (async function() { 'use strict'; // Define the tax rate const TAX_RATE = 0.14975; // Fetch the Euro conversion rate async function fetchExchangeRate() { const requestURL = 'https://api.exchangerate.host/convert?from=CAD&to=EUR'; const response = await fetch(requestURL); const data = await response.json(); return data.result; } const CAD_TO_EURO = await fetchExchangeRate(); // Add CSS block const css = ` .price-container { position: relative; display: inline-block; } .price-info { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; border: 1px solid #ddd; padding: 12px; z-index: 1; } .price-container:hover .price-info { display: block; } .tax-included { color: red; } .base-price { color: #666; } .euro-price { color: #4CAF50; } `; const styleElement = document.createElement('style'); styleElement.textContent = css; document.head.appendChild(styleElement); // Define the websites and their price tag selectors const websites = [ { domain: 'newegg.ca', selectors: ['li.price-current', '.goods-price-current'], updatePrice: (element) => { const strongElement = element.querySelector('strong'); const supElement = element.querySelector('sup'); if (strongElement && supElement) { const price = parseFloat(`${strongElement.textContent.replace(',', '')}${supElement.textContent}`); const convertedPrice = convertPrice(price); const euroPrice = convertToEuros(convertedPrice); const priceInfo = `
Tax included: $${convertedPrice}
Euro price: €${euroPrice}
`; element.outerHTML = `
${element.outerHTML}${priceInfo}
`; } } }, { domain: 'canadacomputers.com', selectors: [ '.h2-big > strong:nth-child(1)', '.text-red d-block mb-0 pq-hdr-product_price line-height', '.d-block.mb-0.pq-hdr-product_price.line-height', '.text-danger h2 price', ], updatePrice: (element) => { const price = parseFloat(element.textContent.replace('$', '').replace(',', '')); const convertedPrice = convertPrice(price); const euroPrice = convertToEuros(convertedPrice); const priceInfo = `
Tax included: $${convertedPrice}
Euro price: €${euroPrice}
`; element.outerHTML = `
${element.outerHTML}${priceInfo}
`; } } ]; // Function to convert the price with tax function convertPrice(price) { const priceWithTax = price * (1 + TAX_RATE); return priceWithTax.toFixed(2); } // Function to convert the price to Euros function convertToEuros(price) { const priceInEuros = price * CAD_TO_EURO; return priceInEuros.toFixed(2); } // Function to update price tags on the website function updatePriceTags(website) { website.selectors.forEach(selector => { const priceElements = document.querySelectorAll(selector); priceElements.forEach(element => { website.updatePrice(element); }); }); } // Get the current hostname const hostname = window.location.hostname; // Update price tags for the matching website websites.forEach(website => { if (hostname.includes(website.domain)) { updatePriceTags(website); } }); })();