Skip to content

Instantly share code, notes, and snippets.

@vogler
Last active June 16, 2020 12:28
Show Gist options
  • Save vogler/2d1bfcd01ad5c248bf0fa38a7cced198 to your computer and use it in GitHub Desktop.
Save vogler/2d1bfcd01ad5c248bf0fa38a7cced198 to your computer and use it in GitHub Desktop.
Tampermonkey: AliExpress: show coupon percentage
// ==UserScript==
// @name AliExpress: show coupon percentage
// @namespace https://gist.github.com/vogler
// @downloadURL https://gist.github.com/vogler/2d1bfcd01ad5c248bf0fa38a7cced198/raw/coupon-percentage.aliexpress.tamper.js
// @version 0.1
// @description Show percentage for each coupon.
// @author Ralf Vogler
// @match https://coupon.aliexpress.com/buyer/coupon/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const f = el => {
const xs = el.querySelectorAll('.use-coupons-info-price');
for (const x of xs) {
const limit = parseFloat(x.querySelector('.use-coupons-info-lang-limit').innerText.match(/\d+\.\d+/));
const price = parseFloat(x.querySelector('.use-coupons-info-lang-price').innerText.match(/\d+\.\d+/));
const ratio = (price/limit*100).toFixed(2);
// console.log(limit, price, ratio);
if (ratio) x.querySelector('.use-coupons-info-lang-price').appendChild(document.createTextNode(` ${ratio}%`));
}
}
f(document.body); // handle initially loaded items
// increase font size of minimum order price
document.querySelectorAll('.use-coupons-info-price').forEach(e => { e.style.fontSize = 'inherit' });
// handle dynamically loaded items
// (new MutationObserver((ms, ob) => ms.forEach(m => m.addedNodes.forEach(f)))).observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment