-
-
Save ireun/ab0185c67ca70465d50b59fc6132eba2 to your computer and use it in GitHub Desktop.
This file contains 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 Spent on Ali ( with PLN support) | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2.1 | |
// @description Get full amount of money spent on products in USD and PLN | |
// @author Peter Willemsen <peter@codebuffet.co> | |
// @author Michał Gątkowski <gatkowski.michal@gmail.com> | |
// @match https://trade.aliexpress.com/orderList.htm* | |
// @match https://trade.aliexpress.com/order_list.htm* | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js | |
// ==/UserScript== | |
var kfullPriceUSD = "full_price_USD" | |
var kfullPricePLN = "full_price_PLN" | |
var kStarted = "started" | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
$(function() { | |
var $btn = $("<input type='button' style='left: 10px;' class='ui-button ui-button-primary search-btn' value='Check full spend amount'/>"); | |
var $btn_disable = $("<input type='button' style='left: 10px;' class='ui-button ui-button-primary search-btn' value='Disable'/>"); | |
$btn.click(function() { | |
GM_setValue(kfullPriceUSD, 0); | |
GM_setValue(kfullPricePLN, 0); | |
GM_setValue(kStarted, true); | |
window.location.reload(); | |
}); | |
$btn_disable.click(function() { | |
GM_setValue(kStarted, false); | |
}); | |
if (!GM_getValue(kStarted, false)) { // if disabled | |
$('#simple-search').append($btn); | |
} else { // if enabled | |
$('#simple-search').append($btn_disable); | |
} | |
}); | |
(function() { | |
if (!GM_getValue(kStarted, false)) { // if disabled | |
return; | |
} | |
var floatify = function(text) { | |
return parseFloat(text.replace(",", ".").replace(/[^\d.-]/g, '')); | |
}; | |
var countOrdersTick = function() { | |
var currentPricePLN = 0; | |
var currentPriceUSD = 0; | |
$("p.amount-num").each(function() { | |
if (/[$]\s\d+[.]\d\d/.test($(this).text())) { // USD | |
currentPriceUSD += floatify($(this).text()); | |
} else if (/\d+[,]\d\d\sPLN/.test($(this).text())) { // PLN | |
currentPricePLN += floatify($(this).text()); | |
} | |
}); | |
console.log("current page price in USD: " + currentPriceUSD); | |
console.log("current page price in PLN: " + currentPricePLN); | |
var fullPriceUSD = GM_getValue(kfullPriceUSD, 0); | |
var fullPricePLN = GM_getValue(kfullPricePLN, 0); | |
GM_setValue(kfullPriceUSD, fullPriceUSD + currentPriceUSD); | |
GM_setValue(kfullPricePLN, fullPricePLN + currentPricePLN); | |
console.log("current full price in USD: " + (fullPriceUSD + currentPriceUSD)); | |
console.log("current full price in PLN: " + (fullPricePLN + currentPricePLN)); | |
var $nextBtn = $("a.ui-pagination-next.ui-goto-page:first"); | |
if ($nextBtn.length === 0) { | |
alert('Your total amount spent in USD on AliExpress: ' + (fullPriceUSD + currentPriceUSD).toFixed(2) + | |
'\nYour total amount spent in PLN on AliExpress: ' + (fullPricePLN + currentPricePLN).toFixed(2)); | |
GM_setValue(kStarted, false); | |
} else { | |
$nextBtn.get(0).click(); | |
} | |
} | |
setTimeout(countOrdersTick, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment