Moe Goods Helper

海淘吃谷插件

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Moe Goods Helper
// @namespace    WeiYuanStudio
// @version      0.1.1
// @description  海淘吃谷插件
// @author       WeiYuanStudio
// @match        www.mercari.com/*
// @match        www.suruga-ya.jp/*
// ==/UserScript==
'use strict';

const SETTING = {
    RATE_JPY_CNY: 0.061 //jpy to cny rate
}

let jpyToCny = function (jpyPrice) {
    return (jpyPrice * SETTING.RATE_JPY_CNY).toFixed(2)
}

let getNumberFromHell = function (hell) {
    return /[0-9,.]+/.exec(hell)[0].replace(',', '')
}

let updateMercariListPrice = function () {
    $('.items-box-price').each(function () {
        let rawPrice = $(this).text()

        let jpyPrice = parseFloat(rawPrice.replace('¥', '').replace(',', ''))
        $(this).attr('raw-price', `JPY: ${jpyPrice}`) //save raw price

        let cnyPrice = (jpyPrice * SETTING.RATE_JPY_CNY).toFixed(2)
        $(this).attr('cny-price', `CNY: ${cnyPrice}`) //save cny price

        $(this).text($(this).attr('cny-price')) //set cny price show

        //set up hover event
        $(this).hover(function () {
            $(this).text($(this).attr('raw-price'))
        }, function () {
            $(this).text($(this).attr('cny-price'))
        })
    })
};

let updateMercariPagePrice = function () {
    $('.item-price').each(function () {
        let rawPrice = $(this).text()

        let jpyPrice = parseFloat(rawPrice.replace('¥', '').replace(',', ''))

        let cnyPrice = (jpyPrice * SETTING.RATE_JPY_CNY).toFixed(2)

        $(this).text($(this).attr('cny-price')) //set cny price show

        $(this).text(`JPY: ${jpyPrice} | CNY: ${cnyPrice}`)
    })
};

let updateSurugayaListPrice = function () {
    $('.price_teika').each(function () {
        let jpyPrice = /[0-9,.]+/.exec($(this).text())[0].replace(',', '')
        let cnyPrice = jpyToCny(jpyPrice)
        let elem = document.createElement('div')
        elem.innerText = `CNY: ${cnyPrice}`
        elem.setAttribute('style', 'color: red; font-family: sans-serif; font-weight: bolder; text-decoration: underline;')
        $(this).after(elem)
    })
};

let updateSurugayaPagePrice = function () {
    $('#item_sellInfo #sellInfo_left input').parent().each(function () {
        let jpyPrice = getNumberFromHell($(this).text())

        let cnyPrice = jpyToCny(jpyPrice)

        let elem = document.createElement('div')
        elem.innerText = `CNY: ${cnyPrice}`
        elem.setAttribute('style', 'color: red; font-family: sans-serif; font-weight: bolder; text-decoration: underline;')
        $(this).after(elem)
    })
};

(function () {
    updateMercariListPrice()
    updateMercariPagePrice()
    updateSurugayaListPrice()
    updateSurugayaPagePrice()
})();