My Test Task: Ethereum ETH Price Rate Extractor

Extracts Ethereum ETH price rate and displays it in the console

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==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
// @match        https://hh.ru/
// @match        https://docs.google.com/forms/d/e/1FAIpQLSeqbuSM5aX8XAUU28Gy21H5r1Z_7_iOl3Mze2GKfAO1UJDb4Q/viewform
// @match        https://google.com
// @grant GM_xmlhttpRequest
// @license MIT
// ==/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);
})();