My Test Task: Ethereum ETH Price Rate Extractor

Extracts Ethereum ETH price rate and displays it in the console

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         My Test Task: Ethereum ETH Price Rate Extractor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Extracts Ethereum ETH price rate and displays it in the console
// @author       Boris Becker
// @match        https://www.coingecko.com/en/coins/ethereum
// @match        https://greasyfork.org/en
// @grant GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract and display ETH price rate
    function extractETHPriceRate(html) {
        // Find the element containing the ETH price rate
        var ethPriceElement = html.querySelector('div.tw-font-bold > span');

        // Check if the element is found
        if (ethPriceElement) {
            var ethPriceRate = ethPriceElement.textContent.trim();
            console.log('Ethereum ETH Price Rate: ', ethPriceRate);
        } else {
            console.error('Failed to find Ethereum ETH Price Rate element');
        }
    }

    function interactWithWebsite() {

        GM_xmlhttpRequest({
            method: "GET",
            url: "https://www.coingecko.com/en/coins/ethereum/",
            headers: {
                "Content-Type": "application/json"
            },
            onload: function(response) {
                var res = response.responseText;
                var parser = new DOMParser();
                var doc = parser.parseFromString(res, 'text/html');
                extractETHPriceRate(doc);
            }
        });

    }

    // Wait for the page to load completely before extracting the ETH price rate
    window.addEventListener('load', interactWithWebsite);
})();