BLPPSC

Bricklink Price Per Stud Calculator

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         BLPPSC
// @version      0.1
// @namespace    Bricklink_Price_Per_Stud_Calculator
// @description  Bricklink Price Per Stud Calculator
// @author       Sencer ÖZTÜFEKÇİ
// @match        https://store.bricklink.com/*
// @icon         https://www.google.com/s2/favicons?domain=bricklink.com
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    window.onload=init;
    function init(){
        hesapla();
        const icerik = document.getElementsByClassName('store-view-panel in-menu')[0];
        const config = {
            attributes: true,
            childList: true,
            characterData: true
        };

        const callback = mutations => {
            mutations.forEach(mutation => {
                if(mutation.removedNodes[0]?.className==='wl-loading-spinner'){
                    console.log('değişti');
                    hesapla();
                }
            });
        }

        const observer = new MutationObserver(callback);
        observer.observe(icerik, config);

    }

    function hesapla(){
        var satirlar=document.getElementsByClassName('item component table-row');
        for(var i=0;i<satirlar.length;i++){
            //   var fiyat=Number(satirlar[i].childNodes[3].childNodes[1].childNodes[1].innerText.split(' ')[1].split(',').join());
            var _x=Number(satirlar[i].childNodes[2].childNodes[0].childNodes[0].childNodes[1].innerText.split(' ')[1]);
            var _y=Number(satirlar[i].childNodes[2].childNodes[0].childNodes[0].childNodes[1].innerText.split(' ')[3]);
            var fiyat=Number(satirlar[i].childNodes[3].childNodes[1].childNodes[1].innerText.split(' ')[1].split(',').join(''));
            var birim=satirlar[i].childNodes[3].childNodes[1].childNodes[1].innerText.split(' ')[0]
            var studFiyat= fiyat / (_x * _y);
            if(studFiyat){
                satirlar[i].childNodes[3].childNodes[1].childNodes[1].insertAdjacentHTML('afterend', '<br> PPS: <b>'+birim+' '+studFiyat.toFixed(4)+'</b>');
            }
        }
    }
})();