Buyee Item Page Enhancements

Fix up item page on mobile with: larger images; cruft remove; description pasted into item page

Per 16-02-2024. Zie de nieuwste versie.

// ==UserScript==
// @name         Buyee Item Page Enhancements
// @license      MIT
// @version      0.11
// @description  Fix up item page on mobile with: larger images; cruft remove; description pasted into item page
// @author       rhgg2
// @match        https://buyee.jp/item/yahoo/*
// @icon         https://www.google.com/s2/favicons?domain=buyee.jp
// @require      https://unpkg.com/[email protected]/js/smartphoto.min.js
// @namespace https://greasyfork.org/users/1243343
// ==/UserScript==

// stuff to handle loading stage of page
if (document.readyState === 'complete') {
    buyeeItemPageEnhance();
} else {
    window.addEventListener('load', () => buyeeItemPageEnhance());
}

// are we on the mobile site?
var isMobile = (navigator.userAgent.match(/Android/i)
         || navigator.userAgent.match(/webOS/i)
         || navigator.userAgent.match(/iPhone/i)
         || navigator.userAgent.match(/iPad/i)
         || navigator.userAgent.match(/iPod/i)
         || navigator.userAgent.match(/BlackBerry/i)
         || navigator.userAgent.match(/Windows Phone/i));

// fetch a URL and return a document containing it
function fetchURL(url) {
    return fetch(url)
    .then((response) => {
        return response.text()
    })
    .then((html) => {
        // Parse the text
        var parser = new DOMParser();
        var doc = parser.parseFromString(html, "text/html");
        return doc;
    });
}

// the main function
function buyeeItemPageEnhance () {
    var sp = new SmartPhoto(".js-smartPhoto");

    if (isMobile) {
        document.querySelectorAll("img.image").forEach( (card) => {
            card.style["max-height"] = "none";
            card.style.height = "auto";
        });

        document.querySelector("div.detail_toShopping").remove();
        document.querySelector("div.banner-outer").remove();
        document.querySelector("div.directDelivery").remove();
        document.querySelector("div.itemInformation__txtLink").remove();


        var infoBox = document.querySelector("div.itemInformation__detailLink");
        infoBox.style["text-align"] = "left";
        infoBox.style["font-size"] = "1.4rem";
        fetchURL(infoBox.querySelector("a").href).then( doc => {
            var text = doc.querySelector("div.inner");
            text.querySelectorAll("div:not(.googleTranslate):not(#google_translate_element)").forEach( (node) => infoBox.appendChild(node) );
            infoBox.querySelector("a").remove();
        });
    }
};