My Test Task: Ethereum ETH Price Rate Extractor

Extracts Ethereum ETH price rate and displays it in the console

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();