Sprints AI - Mark as Watched

Adds a button to mark the video as watched on Sprints AI

目前為 2025-02-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Sprints AI - Mark as Watched
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to mark the video as watched on Sprints AI
// @author       UAEpro
// @match        https://sprints.ai/journeys/learning/*
// @grant        GM_xmlhttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    function getParameterByName(name) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(name);
    }

    function sendWatchedRequest(itemId) {
        const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '';

        GM_xmlhttpRequest({
            method: "POST",
            url: "https://sprints.ai/course/1999481/learningStatus",
            headers: {
                "User-Agent": navigator.userAgent,
                "Accept": "*/*",
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                "X-CSRF-TOKEN": csrfToken,
                "X-Requested-With": "XMLHttpRequest",
            },
            data: `item=file_id&item_id=${itemId}&status=true`,
            onload: function (response) {
                if (response.status === 200) {
                    alert("Marked as Watched!");
                } else {
                    alert("Failed to mark as watched.");
                }
            },
            onerror: function () {
                alert("Network error.");
            }
        });
    }

    function addWatchedButton() {
        const button = document.createElement("button");
        button.innerText = "Watched";
        button.style.position = "fixed";
        button.style.bottom = "20px";
        button.style.left = "20px";
        button.style.padding = "10px 15px";
        button.style.backgroundColor = "#28a745";
        button.style.color = "white";
        button.style.border = "none";
        button.style.borderRadius = "5px";
        button.style.cursor = "pointer";
        button.style.fontSize = "16px";
        button.style.zIndex = "1000";

        button.onclick = function () {
            const itemId = getParameterByName("item");
            if (!itemId) {
                alert("Item ID not found in URL.");
                return;
            }
            sendWatchedRequest(itemId);
        };

        document.body.appendChild(button);
    }

    addWatchedButton();
})();