// ==UserScript==
// @name Show price combinations list
// @namespace http://tampermonkey.net/
// @version 0.1
// @author Dimokin
// @match https://ru.aliexpress.com/item/*
// @grant none
// @require http://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==
(function() {
'use strict';
var $ = window.jQuery;
$(document).ready(function() {
let startHTML = document.querySelector("html").outerHTML.split('window.runParams =')[1];
let endHTML = startHTML.split('var GaData')[0];
function strToObj(str) {
var obj = {};
if (str && typeof str === 'string') {
var objStr = str.match(/\{(.)+\}/g);
eval("obj =" + objStr);
}
return obj
}
let mainObject = strToObj(endHTML);
console.log('mainObject', mainObject);
mainObject.skuModule.skuPriceList.sort(function(a, b) {
let priceField = a.skuVal.actSkuMultiCurrencyCalPrice ? 'actSkuMultiCurrencyCalPrice' : 'skuMultiCurrencyCalPrice';
var keyA = parseFloat(a.skuVal[priceField]),
keyB = parseFloat(b.skuVal[priceField]);
if (keyA < keyB) return -1;
if (keyA > keyB) return 1;
return 0;
});
var div = document.createElement('div');
div.className = 'prices';
div.innerHTML += `
<button class="price-toggle">
Show/Hide
</div>
`;
$(div).append('<div class="price-list"></div>');
mainObject.skuModule.skuPriceList.forEach(function(element) {
let propsId = element.skuPropIds.split(',');
let propString = '';
propsId.forEach(function(prop, index) {
mainObject.skuModule.productSKUPropertyList.forEach(function(listItem) {
listItem.skuPropertyValues.forEach(function(skuProp) {
if (prop == skuProp.propertyValueId) {
propString += skuProp.propertyValueDisplayName;
}
});
});
if (index !== propsId.length - 1) {
propString += ' - '
}
});
let priceField = element.skuVal.actSkuMultiCurrencyCalPrice ? 'actSkuMultiCurrencyCalPrice' : 'skuMultiCurrencyCalPrice';
let price = element.skuVal[priceField]
var oldHtml = $(div).find('.price-list').html();
if (element.skuVal.availQuantity > 0) {
$(div).find('.price-list').html(oldHtml + `
<div class="price-row">
<div class="price-row__left">${propString} </div>
<div class="price-row__right">${price} ${mainObject.commonModule.currencyCode}</div>
</div>
`);
}
});
var styles = `
.prices {
position: fixed;
top: 0;
right: 0;
background: white;
box-shadow: 1px -1px 4px 1px;
max-width: 40%;
max-height: 400px;
padding: 10px 20px;
overflow-y: auto;
overflow-x: hidden;
z-index:9999;
}
.price-list {
margin-top: 15px;
}
.price-row {
display:flex;
margin-bottom:5px;
justify-content: space-between;
}
.price-row__left {}
.price-row__right {
min-width: 90px;
text-align: right;
margin-left: 20px;
width: 10%;
flex-shrink: 0;
}
.price-toggle {
display: block;
margin-right: auto;
cursor:pointer;
}`
var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.appendChild(styleSheet)
document.body.appendChild(div);
$(document).on("click", ".price-toggle", function() {
$(div).find('.price-list').toggle();
setTimeout($(window).trigger('resize'), 300);
});
});
})();