Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Show price combinations list (10.05.2022)
- // @namespace http://tampermonkey.net/
- // @version 0.7
- // @author Dimokin - https://mipped.com/f/members/dimokin.65355/
- // @match https://ru.aliexpress.com/item/*
- // @match https://www.aliexpress.com/item/*
- // @match https://aliexpress.ru/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);
- mainObject.skuModule.skuPriceList.sort(function(a, b) {
- let actPriceField = a.skuVal.skuActivityAmount ? 'skuActivityAmount' : 'skuAmount';
- let defaultPriceField;
- if (a.skuVal.skuActivityAmount || a.skuVal.skuAmount) {
- defaultPriceField = a.skuVal.skuActivityAmount ? 'skuActivityAmount' : 'skuAmount';
- } else {
- defaultPriceField = a.skuVal.skuAmount ? 'skuAmount' : 'skuActivityAmount';
- }
- var keyA = parseFloat(a.skuVal[actPriceField].value),
- keyB = parseFloat(b.skuVal[actPriceField].value),
- keyC = parseFloat(a.skuVal[defaultPriceField].value),
- keyD = parseFloat(b.skuVal[defaultPriceField].value);
- if (keyA == keyB) {
- return (keyC > keyD) ? -1 : (keyA < keyD) ? 1 : 0;
- } else {
- return (keyA < keyB) ? -1 : 1;
- }
- });
- var div = document.createElement('div');
- div.className = 'prices';
- div.innerHTML += `
- <button class="price-toggle">
- Show/Hide
- </button>
- `;
- $(div).append('<div class="price-list"></div>');
- let pricesIndexes = [];
- let newPriceList = [];
- let hasCountries = false;
- mainObject.skuModule.productSKUPropertyList.forEach(function(element) {
- if (element.skuPropertyId === 200007763) {
- hasCountries = true;
- }
- });
- mainObject.skuModule.skuPriceList.forEach(function(element) {
- if (hasCountries) {
- if (element.skuPropIds.includes('201336100') || element.skuPropIds.includes('201336103') || element.skuPropIds.includes('203124901')) {
- newPriceList.push(element);
- }
- } else {
- newPriceList.push(element);
- }
- });
- newPriceList.forEach(function(element) {
- let propsId = element.skuPropIds.split(',');
- let availableCount = element.skuVal.availQuantity;
- let propString = '';
- let propIndex = [];
- if (propsId.length) {
- propsId.forEach(function(prop, index) {
- if (mainObject.skuModule.productSKUPropertyList && mainObject.skuModule.productSKUPropertyList.length) {
- mainObject.skuModule.productSKUPropertyList.forEach(function(listItem) {
- listItem.skuPropertyValues.forEach(function(skuProp, skuIndex) {
- if (prop == skuProp.propertyValueId && availableCount > 0) {
- propString += skuProp.propertyValueDisplayName;
- propIndex.push(skuIndex);
- }
- });
- });
- if (index !== propsId.length - 1) {
- propString += ' - '
- }
- }
- });
- }
- if (propIndex.length) {
- pricesIndexes.push(propIndex);
- }
- let priceField = element.skuVal.skuActivityAmount ? 'skuActivityAmount' : 'skuAmount';
- let price = element.skuVal[priceField].value;
- 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;
- padding:3px;
- margin-bottom:0;
- justify-content: space-between;
- cursor:pointer;
- }
- .price-row:hover,.price-row.active {
- background: lightgrey;
- }
- .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);
- });
- let propertyLists = $('.product-sku').find('.sku-property-list');
- if (pricesIndexes.length) {
- pricesIndexes[0].forEach(function(price, priceIndex) {
- for (var i = 0; i < propertyLists.length; i++) {
- if (i === priceIndex) {
- let propIndex = pricesIndexes[0][priceIndex];
- let prop = $('.sku-property-list').eq(i).find('.sku-property-item').eq(propIndex)
- if (prop.hasClass("selected")) {} else {
- prop.trigger('click');
- }
- }
- }
- });
- }
- $('.price-row').eq(0).addClass('active');
- $('.price-row').click(function(event) {
- let index = $(this).index();
- $('.price-row').each(function() {
- if ($(this).hasClass("active")) {
- $(this).removeClass('active');
- }
- });
- $(this).addClass('active');
- let propertyLists = $('.product-sku').find('.sku-property-list');
- pricesIndexes[index].forEach(function(price, priceIndex) {
- for (var i = 0; i < propertyLists.length; i++) {
- if (i === priceIndex) {
- let propIndex = pricesIndexes[index][priceIndex];
- let prop = $('.sku-property-list').eq(i).find('.sku-property-item').eq(propIndex)
- if (prop.hasClass("selected")) {} else {
- prop.trigger('click');
- }
- }
- }
- });
- });
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement