Buyee Item Page Enhancements

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Buyee Item Page Enhancements
// @license      MIT
// @version      0.22
// @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 script = document.createElement("script");
    script.innerText = `
$('#js-item-images').slick('slickSetOption','speed',100,false);
$('#js-item-images').slick('slickSetOption','waitForAnimate',false,false);
$('#js-item-images').slick('slickSetOption','touchThreshold',15,false);`
    document.head.appendChild(script);
 
    if (isMobile) {
        document.querySelectorAll("img.image").forEach( (card) => {
            card.style["max-height"] = "400px";
            card.style.height = "auto";
        });
 
        ["div.detail_toShopping", "div.banner-outer", "div.directDelivery", "div.itemInformation__txtLink", "p.guide"].forEach( (text) => {
            let element = document.querySelector(text);
            if (element) {
                element.remove();
            }
        });
 
        let infoBox = document.querySelector("div.itemInformation__detailLink");
        if (infoBox) {
            infoBox.style["text-align"] = "left";
            fetchURL(infoBox.querySelector("a").href).then( doc => {
                var text = doc.querySelector("div.inner");
                text.querySelectorAll(".googleTranslate, #google_translate_element, h1").forEach( (node) => node.remove() );
                infoBox.appendChild(text);
                infoBox.querySelector("a").remove();
            });
        }
    }
};