Greasy Fork

Greasy Fork is available in English.

自動註冊 Udemy 免費課程

在特定網站自動執行

当前为 2025-05-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         自動註冊 Udemy 免費課程
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在特定網站自動執行
// @license      GPL-3.0
// @match        https://www.udemy.com/*
// @grant        none
// @author       twozwu
// ==/UserScript==

(function () {
    'use strict';

    console.log("腳本自動執行中!");

    const observer = new MutationObserver(() => {
        const bodyText = document.body.innerText;
        if (bodyText.includes("立即註冊")) {
            console.log("✅ 偵測到免費");

            let btn = document.querySelector('[data-purpose="buy-this-course-button"]') ||
                document.querySelector('.ud-btn-brand');

            if (btn && btn.innerText.includes("立即註冊")) {
                console.log("✅ 找到按鈕,可點擊");
                setTimeout((() => btn.click()), 2500);
                // btn.click();
                observer.disconnect(); // 停止監聽
            }
        } else {
            let btn = document.querySelector('[data-purpose="buy-this-course-button"]');
            if (['立即購買', '前往課程'].includes(btn.innerText)) {
                window.close();
            }
        }
    });

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