Created
June 4, 2023 22:17
-
-
Save tcortega/dfdbe55de0389aeeeae03ceafda228b9 to your computer and use it in GitHub Desktop.
correções pro cssbuy
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 CSSBuy Fixes | |
// @namespace https://tcortega.com/ | |
// @version 0.1 | |
// @description Melhora o carregamento de imagens do CSSBuy | |
// @author tcortega | |
// @match https://www.cssbuy.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=cssbuy.com | |
// @grant none | |
// ==/UserScript== | |
function changeSku() { | |
let keyStr = ''; | |
let skuVal = ''; | |
sku_data.forEach((data, i) => { | |
const selVal = $(`#sku_${data[0].code}`).val(); | |
let value = ''; | |
data.forEach((d) => { | |
if (d.key === selVal) { | |
value = d.value; | |
} | |
}); | |
if (keyStr) { | |
skuVal += `<br />${data[0].name} : ${value}`; | |
keyStr += `;${data[0].code}:${selVal}`; | |
} else { | |
skuVal = `${data[0].name} : ${value}`; | |
keyStr = `${data[0].code}:${selVal}`; | |
} | |
}); | |
itemdata.num = parseFloat(itemdata.sku_data[keyStr]?.quantity ?? '0'); | |
try { | |
const price = itemdata.sku_data[keyStr].price; | |
const newUsdPrice = price / $('#usdRate').val(); | |
$('#gsItemPrice').text(price); | |
$('#usdPrice').text(newUsdPrice.toFixed(2)); | |
$('#price_def').val(itemdata.sku_data[keyStr].price_def); | |
} catch { | |
$('#gsItemPrice, #usdPrice').text('NO STOCK'); | |
$('#price_def').val(0); | |
} | |
const postFee = parseFloat($("#post_fee").text(), 10); | |
const totalPrice = parseFloat($("#gsItemPrice").text(), 10) * parseFloat($("#quantity").val(), 10) + postFee; | |
$('#total_price').text(toMoneyStyle(totalPrice)); | |
if (1 !== activity_ratio) { | |
const oldPrice = itemdata.sku_data[keyStr].price / activity_ratio; | |
const oldTotalPrice = parseFloat($("#old_gsItemPrice").text(), 10) * parseFloat($("#quantity").val(), 10) + parseFloat($("#old_post_fee").val(), 10); | |
$('#old_gsItemPrice').text(toMoneyStyle(oldPrice)); | |
$('#old_total_price').text(toMoneyStyle(oldTotalPrice)); | |
} | |
const skuValArr = ['#sku_select', '#note', '#option']; | |
skuValArr.forEach(id => $(id).val(skuVal)); | |
const borderStyle = (props_data_length > 0 && props_data_length === $('a.on').length) ? 'none' : '4px dashed #ff6600'; | |
$('#sku').val(borderStyle === 'none' ? keyStr : ''); | |
$('#sku_box').css({ 'border': borderStyle }); | |
let skuId = ''; | |
if (itemdata.skus.sku) { | |
for (let i in itemdata.skus.sku) { | |
if (itemdata.skus.sku[i].properties === keyStr) { | |
skuId = itemdata.skus.sku[i].sku_id; | |
} | |
} | |
} | |
const quantity = itemdata.sku_data[keyStr]?.quantity ?? 0; | |
const skuUrl = `${itemdata.detail_url}${itemdata.detail_url.indexOf('?') !== -1 ? '&' : '?'}sku=${keyStr}&sku_id=${skuId}`; | |
$('#url').val(skuUrl); | |
$('#item_num').html(quantity); | |
} | |
(function () { | |
'use strict'; | |
window.addEventListener('load', () => { | |
const thumblist = $(".product-gallery-thumblist"); | |
const preview = $(".product-gallery-preview li"); | |
const goodsDescImg = $('.goods-desc img'); | |
const thumblistLiImg = thumblist.find('li img'); | |
const thumblistLiAnchor = thumblist.find('li > a'); | |
const itemInfo = $('.item-info'); | |
thumblist.off("click", "li"); | |
itemInfo.off("click", "#sku_box a"); | |
thumblist.on("click", 'li', function () { | |
const _this = $(this); | |
const datasrcValue = _this.find('img').attr('datasrc'); | |
thumblist.find("li").removeClass('active'); | |
_this.addClass('active'); | |
preview.removeClass('current'); | |
$(_this.find('a').attr('href')).addClass('current'); | |
if (datasrcValue) { | |
const eqImg = goodsDescImg.eq(_this.index()); | |
const img = _this.find('img'); | |
preview.find('img').eq(_this.index()).attr({ 'src': datasrcValue, 'referrerpolicy': 'no-referrer' }); | |
eqImg.attr({ 'src': datasrcValue, 'referrerpolicy': 'no-referrer' }).show(); | |
img.attr({ 'src': datasrcValue, 'referrerpolicy': 'no-referrer' }); | |
} | |
}); | |
thumblistLiImg.each(function () { | |
const _this = $(this); | |
const datasrcValue = _this.attr("datasrc"); | |
_this.attr({ | |
"referrerpolicy": "no-referrer", | |
"src": datasrcValue | |
}); | |
}); | |
thumblistLiAnchor.attr('onclick', 'event.preventDefault();'); | |
itemInfo.on('click', '#sku_box a', function () { | |
const _this = $(this); | |
const img = _this.find('img'); | |
if (img.length > 0) { | |
const src = img.attr('src').replace('/itemImg.php?url=', ''); | |
const previewLast = $('#previewlast'); | |
const liElement = $("<li id='previewlast' class='current'><img style='width:588px;height:578px;' src='" + src + "' referrerpolicy='no-referrer'></li>"); | |
preview.removeClass('current'); | |
if (previewLast.length > 0) { | |
preview.removeClass('current'); | |
previewLast.find('img').attr({ 'src': src, 'referrerpolicy': 'no-referrer' }); | |
previewLast.addClass('current'); | |
} else { | |
preview.removeClass('current'); | |
$(".product-gallery-preview").append(liElement); | |
} | |
} | |
}); | |
changesku = changeSku; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment