Greasy Fork

Greasy Fork is available in English.

Amazon送料込

Amazonで送料込みの値段を表示する

当前为 2023-07-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         Amazon送料込
// @version      0.7
// @description  Amazonで送料込みの値段を表示する
// @match        https://www.amazon.co.jp/dp/*
// @match        https://www.amazon.co.jp/*/dp/*
// @match        https://www.amazon.co.jp/gp/product/*
// @match        https://www.amazon.co.jp/*/ASIN/*
// @match        https://www.amazon.co.jp/product-reviews/*
// @match        https://www.amazon.co.jp/*/product-reviews/**
// @author       TNB
// @license      MIT
// @grant        none
// @namespace http://greasyfork.icu/users/3989
// ==/UserScript==

/********************  SETTING **************************/

// ハイライトテキストの色
const highlight_color = '#f00';
// 評価の設定値を下回った出品者の背景色
const caution_exhibitors_bg_color = 'rgba(255, 0, 0, 0.2)';
// 新規出品者の背景色
const new_exhibitors_bg_color = 'rgba(0, 0, 255, 0.2)';

// 一つでも下記の設定未満の評価がある場合出品者の背景色をcaution_exhibitors_bg_colorに変えます。0にするとその項目ではフィルターされません。
// 星の数
const star = 4;
// 評価件数
const evaluations_count = 15;
// 高評価の割合(%)
const evaluation = 70;

// 一つでも下記の設定未満の評価がある場合出品者を非表示にします。各項目の意味は上の設定と同じ。
const min_star = 3;
const min_evaluations_count = 0;
const min_evaluation = 60;

/********************************************************/

(function() {
    (function() {
        const style = document.head.appendChild(document.createElement('style'));
        style.innerHTML = `
            .aas_rated_low{filter: invert(12%) sepia(77%) saturate(7199%) hue-rotate(359deg) brightness(102%) contrast(108%);}
            span.aas_highlight_text,.aas_highlight_text>span,.aas_count_low{color:${highlight_color} !important}
            .aas_bold_text{font-weight:bold;}
            .aas_remove_exhibitors{display:none;}
            .aas_caution_exhibitors{background:${caution_exhibitors_bg_color};}
            .aas_new_exhibitors{background:${new_exhibitors_bg_color};}`;
    })();
    function addHighlight(i) {
        const rating = i.firstElementChild.className.match(/\sa-star-brand-mini-(.*?)\s/);
        if (!rating) return 'aas_new_exhibitors';
        const data = i.textContent.match(/(\d+).+?(\d+)%/);
        const r = rating[1].replace(/-/, '.');
        const len = data[1];
        const par = data[2];
        if (min_star > r || min_evaluations_count > len || min_evaluation > par) return 'aas_remove_exhibitors';
        if (star > r) i.firstElementChild.classList.add('aas_rated_low');
        if (evaluations_count > len) i.innerHTML = replaceText(i, `${len}件`, 'aas_count_low');
        if (evaluation > par) i.innerHTML = replaceText(i, `${par}%`, 'aas_count_low');
        if (i.querySelector('.aas_count_low, .aas_rated_low')) return 'aas_caution_exhibitors';
    }
    function checkExhibitors() {
        const exhibitors = document.querySelectorAll('#aod-offer-seller-rating:not(.aas_rating_checked)');
        if (exhibitors.length === 0) return;
        for (const i of exhibitors) {
            i.closest('#aod-offer-soldBy').parentElement.classList.add(addHighlight(i));
            i.classList.add('aas_rating_checked');
        }
    }
    function getShipping(data) {
        return data? data.textContent.match(/^.+?[\u00A5|\uffe5](\d+)/): '';
    }
    function getCostPrice(item) {
        if (document.querySelector('body[style *= "overflow: hidden"]')) return [item.closest('#aod-offer-price, #aod-pinned-offer, #aod-sticky-pinned-offer').querySelector('.a-price-whole')];
        if (item.closest('#moreBuyingChoices_feature_div')) return [item.closest('.a-row').firstElementChild];
        if (!document.querySelector('#desktop_accordion')) return document.querySelectorAll('div:is(#desktop_buybox, #apex_desktop) span:is(.a-price-whole, .offer-price)');
        if (item.closest('#newAccordionRow_0')) return [item.closest('.a-accordion-row-container').querySelector('.a-offscreen + span'), document.querySelector('li.selected .a-size-base')];
        return item.closest('.a-accordion-row-container').querySelectorAll('#usedPrice, .a-price-whole');
    }
    function replaceText(base_text, replace_text, css) {
        return base_text.innerHTML.replace(replace_text, `<span class="${css}">${replace_text.replace(/^\+/, '')}</span>`);
    }
    function addShipping(price, shipping) {
        if (!price.textContent) return;
        const base = price.textContent.trim().match(/^(\D)?(.+)$/);
        return (base[1] || '') + (base[2].replace(/[^\d]/g, '') * 1 + shipping * 1).toLocaleString();
    }
    function formattingText(price, shipping) {
        price.textContent = addShipping(price, shipping);
        price.parentElement.classList.add('aas_highlight_text');
    }
    new MutationObserver(() => {
        const postages = document.querySelectorAll('span[data-csa-c-delivery-price]:not(.aas_in-taxed), #moreBuyingChoices_feature_div .a-size-base:not(.aas_in-taxed)');
        if (postages.length === 0) return;
        for (const item of postages) {
            item.classList.add('aas_in-taxed');
            const postage = getShipping(item);
            if (postage) {
                const cost = getCostPrice(item);
                item.innerHTML = replaceText(item, postage[0], 'aas_highlight_text aas_bold_text');
                for (const price of cost) formattingText(price, postage[1]);
            }
        }
        if (document.querySelector('body[style *= "overflow: hidden"]')) checkExhibitors();
    }).observe(document.body, {childList: true, subtree: true});
})();