// ==UserScript== // @name Pomocnik Bazarowicza // @namespace http://tampermonkey.net/ // @version 0.5.0 // @description Pomaga zarządzać swoimi ofertami sprzedaży na bazar.lowcygier.pl / Helps managing offers at bazar.lowcygier.pl // @author nochalon // @match https://bazar.lowcygier.pl/offer/my* // @icon https://bazar.lowcygier.pl/favicon.ico // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; var re = /\d+\.\d+ zł/g; var ths = document.querySelectorAll(".fa.fa-usd.icon-sm"); for (var i = 0; i < ths.length; i++) { var originalText = ths[i].getAttribute("title"); if (originalText === null || originalText == "") { originalText = ths[i].getAttribute("data-original-title"); } var content = originalText.match(re); var lowestPrice = document.createElement("div"); var priceElem = ths[i].parentNode.parentNode.parentNode.querySelectorAll(".prc-offert")[0]; var myPrice = document.createElement("div"); var myPriceVal = parseFloat(priceElem.innerHTML.replace(',', '.')); var lowestPriceVal = parseFloat(content) || 0; var difference = myPriceVal - lowestPriceVal; var color = 255 * (difference / myPriceVal); var factor = 0.9; if (difference >= myPriceVal * 0.5) { myPrice.style.color= "rgb(" + color + "," + (255 - factor * color) + "," + (255 - factor * color) + ")"; } else { myPrice.style.color= "rgb(" + (factor * color) + "," + (255 - color) + "," + (factor * color) + ")"; } var percentage = (100 * (difference / myPriceVal)).toFixed(1); lowestPrice.innerHTML = content; lowestPrice.title = "taniej o " + percentage + "%"; lowestPrice.setAttribute('data-toggle', 'tooltip'); lowestPrice.classList.add("trader"); myPrice.innerHTML = priceElem.innerHTML; priceElem.innerHTML = ""; priceElem.appendChild(myPrice); priceElem.appendChild(lowestPrice); priceElem.parentNode.parentNode.parentNode.setAttribute('data-sort', percentage); } var result = $('div.list-view > div').sort(function (a, b) { var contentA = parseFloat($(a).data('sort')) || 0; var contentB = parseFloat($(b).data('sort')) || 0; return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0; }); $('div.list-view > div').remove(); $('div.list-view').prepend(result); })();