Highlight Hourly Rates on Prolific

Highlight hourly rates based on their values.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Highlight Hourly Rates on Prolific 
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Highlight hourly rates based on their values.
// @author       You
// @match        *://*/*
// @grant        MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract the numeric value from the string like "£8.16/hr"
    function extractHourlyRate(text) {
        return parseFloat(text.match(/[\d.]+/));
    }

    // Function to apply the appropriate background color to the element
    function highlightElement(element) {
        const rate = extractHourlyRate(element.textContent);
        if (rate <= 7.79) {
            element.style.backgroundColor = 'red';
        } else if (rate >= 7.80 && rate <= 9.50) {
            element.style.backgroundColor = 'yellow';
        } else if (rate >= 9.51) {
            element.style.backgroundColor = 'green';
        }
        // Set the font color to black
        element.style.color = 'black';
    }

    // Function to process all elements with class="amount"
    function highlightHourlyRates() {
        const elements = document.getElementsByClassName('amount');
        for (const element of elements) {
            // Check if the element should be ignored
            if (element.getAttribute('data-testid') === 'study-tag-reward') {
                continue;
            }
            highlightElement(element);
        }
    }

    // Run the highlighting on page load
    highlightHourlyRates();

    // Observe the DOM for changes and re-run the highlighting if necessary
    const observer = new MutationObserver(() => {
        highlightHourlyRates();
    });

    const config = { childList: true, subtree: true };
    observer.observe(document.body, config);
})();