https://dotnettutorials.net/ - Marking items complete

Allows marking lessons as completed in the site: dotnettutorials.net

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name     https://dotnettutorials.net/ - Marking items complete
// @description    Allows marking lessons as completed in the site: dotnettutorials.net
// @version  1
// @license MIT
// @namespace vivek201
// @grant    GM.getValue
// @grant    GM.setValue
// @include  https://dotnettutorials.net/*
// ==/UserScript==
(() => {
    let completedItems = [];

    async function init() {
        completedItems = [...JSON.parse(await GM.getValue("completedItems", "[]"))];
        console.log('Starting setup...');

        setupStyle();

        let courseOutline = document.querySelector('.llms-course-outline');
        if (courseOutline) {
            console.log('Course outline found...');
            let lessons = Array.from(courseOutline.querySelectorAll('.llms-section .llms-lesson li'));

            if (lessons.length && completedItems.length) {
                console.log('Completed items found...');
                console.log('Checking completed items...');

                let completedLessons = lessons.filter(x => completedItems.includes(x.innerText.trim()));
                completedLessons.forEach(x => {
                    x.querySelector('.llms-lesson-complete').classList.add('checked');
                });
            }

            console.log('Setting up handler for functionality...');

            courseOutline.addEventListener('click', onClick);
        }
    }

    async function onClick(e) {
        let item;
        if (e.target.tagName.toUpperCase() == "I") {
            item = e.target.parentElement;
        } else if (e.target.tagName.toUpperCase() == "SPAN" && e.target.classList.contains("llms-lesson-complete")) {
            item = e.target;
        }

        if (item) {
            let lessonTitle = item.parentElement.querySelector('.lesson-title').innerText.trim();
            console.log('Clicked...', lessonTitle);
            if (item.classList.contains("checked")) {
                console.log('Uncompleting...');
                completedItems = completedItems.filter(x => x != lessonTitle);
            } else {
                console.log('Completing...')
                completedItems.push(lessonTitle);
            }
            completedItems = [...new Set(completedItems)];
            await GM.setValue("completedItems", JSON.stringify(completedItems));

            item.classList.toggle('checked');
        }
    }

    function setupStyle() {
        console.log('Setting up styles...');

        let styles = `.llms-lesson-complete { cursor: pointer; } .llms-lesson-complete.checked { color: green; }`;
        let $styles = document.createElement('style');
        $styles.innerText = styles;
        document.body.appendChild($styles);

        console.log('Completed setting up styles...');
    }

    init();
})();