dmm 换算人名币

dmm 日元价格转换成人民币显示

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         dmm 换算人名币
// @namespace    http://94cat.com/
// @version      0.9
// @description  dmm 日元价格转换成人民币显示
// @author       Bmm
// @match        https://www.dmm.co.jp/digital/*
// @match        https://www.dmm.co.jp/search/*
// @match        https://cashier.dmm.co.jp/choice/*
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    var fx = 18.99; //2023年3月26日

    //初始化date fx
    var now = new Date();
    var date = now.getDate();
    if (GM_getValue('date', '') == '') {
        GM_setValue('date', -1);
        GM_setValue('fx', fx);
    }

    //显示价格元素的选择器
    var DOM = '.price, '; //默认价格选择器
    DOM += '.tx-price,'; //打折状态下
    DOM += '.tx-lt,'; //打折前价格
    DOM += '#side-rank-tab .red,'; //二级分类下,右侧列表价格
    DOM += '.package-item_plice,';
    DOM += '#tr_bmm_price,'; //翻译扩展使用
    DOM += '.choice-totalAmount__txt'; //结算界面

    //页面监控到变动,运行 Start()
    var config = { childList: true, subtree: true };
    var $node = $('#mu')[0];
    var observer = new MutationObserver(Start);

    //跨域获取日本汇率API
    if (GM_getValue('date') != date) {
        console.log('开始请求汇率');
        GM_xmlhttpRequest({
            method: "GET",
            //url: 'http://hq.sinajs.cn/list=fx_sjpycny',//TODO
            url: 'https://api.exchangerate-api.com/v4/latest/CNY',
            responseType: "json",
            onload: function (response) {
                //获取新汇率
                //fx = response.response.split(',')[1];
                fx = response.response.rates.JPY;
                if(fx != undefined)
                {
                    GM_setValue("date", date);
                    GM_setValue("fx", fx);
                    console.log('使用日元->人名币汇率: ' + fx);
                }
                Start();
            },
            onerror: function () { fx = GM_getValue('fx'); Start(); },
            ontimeout: function () { fx = GM_getValue('fx'); Start(); }
        });
    } else {
        fx = GM_getValue('fx');
        console.log('使用日元->人名币汇率: ' + fx);
        Start();
    }

    function Start() {
        observer.disconnect(); //暂停页面监控
        $(DOM).not(".is_rmb").each(function () {
            var $this = $(this);
            if($this.find(".salecount").length){
                $this.find(".salecount").remove();
            }
            $this.addClass('is_rmb'); //修改的数据添加标记,下次跳过
            //打折
            if ($this.find('.tx-hangaku').length > 0) { $this = $this.find('.tx-hangaku'); }
            //列表
            if ($this.find('.normal').length > 0) { $this = $this.find('.normal'); }
            var price = $this.html();
            price = price.replace(/[^0-9]/ig, "");
            price = new Number(price / fx);
            $this.html(price.toFixed(2) + '元');
        });
        observer.observe($node, config); //开启页面监控
    }
})();