Buyee Package Information Image Inserter

Adds product images to the package information shipping tab for mercari and yahoo auctions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Buyee Package Information Image Inserter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds product images to the package information shipping tab for mercari and yahoo auctions
// @author       NO_ob
// @match        https://buyee.jp/mybaggages/shipped/1*
// @icon         https://www.google.com/s2/favicons?domain=buyee.jp
// @grant        none
// ==/UserScript==
var firstRun = 1;
var currentURL = window.location;
(function() {
  'use strict';
  (new MutationObserver(pageObserve)).observe(document, {
    childList: true,
    subtree: true
  });
})();

// observe for page to actually load, fuck webapps
function pageObserve(changes, observer) {
  if (currentURL != window.location) {
    currentURL = window.location;
    firstRun = 1;
  }
  if (firstRun == 1 && document.querySelectorAll("ul#luggageInfo_collection li.luggageInfo")) {
    firstRun = 0;
    document.querySelectorAll("ul#luggageInfo_collection li.luggageInfo").forEach(orderContainer => {
      addImage(orderContainer);
    })
  }
}


function addImage(orderContainer) {
  let url = orderContainer.querySelector("table.luggageInfo_order tbody tr:nth-child(2) td:nth-child(3) a").href;
  fetch(url)
    .then(function(response) {
      return response.text()
    })
    .then(function(html) {
      let div = document.createElement("div");
      div.innerHTML = html;
      let imagehref = "";
      if (url.includes("mercari")) {
        imagehref = div.querySelector("div.imageContainer__main img").getAttribute("data-lazy");
      } else if (url.includes("yahoo")) {
        imagehref = div.querySelector("ul.slides li a").href;
      }

      if (imagehref != "") {
        let newImg = document.createElement("img");
        newImg.setAttribute("src", imagehref);
        newImg.setAttribute("style", "width:50%;");

        let header = orderContainer.querySelector("div.luggageInfo_header");
        header.insertBefore(newImg, header.firstChild);
      }
    })
    .catch(function(err) {
      console.log('Failed to fetch page: ', err);
    });
}