HERO Task Button Fix

Add Mark as Done buttons to set-tasks page

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         HERO Task Button Fix
// @namespace    https://gist.github.com/finlayacourt/b6d4bedb754bb375acb420d33942f6f1
// @version      1.1
// @description  Add Mark as Done buttons to set-tasks page
// @author       finlayacourt
// @match        http://hero.highgateschool.org.uk/set-tasks
// ==/UserScript==

(function() {
    'use strict';

    // Add mark as done buttons to each task
    $(".ff-messages li").each(function() {
        // Get taskID
        var taskID = $(this).attr("data-ff-id");
        $(this).children().append(
            $('<button></button>')
                .addClass('update-task-button ff_module-button ff_module-button--primary-compact')
                .css({float: 'right', color: 'pink'})
                .text('Mark As Done')
        );
    });

    // Mark task with ID taskID as done
    $('.update-task-button').click(function() {
        var taskID = $(this).parent().parent().attr("data-ff-id");
        var taskDataURL = "_api/1.0/tasks/" + taskID + "/responses";

        // Request student and teacher data
        $.getJSON(taskDataURL, function(returnedJson) {
            var a = returnedJson.responses.responses[0],
                b = a.events[0].description,
                studentGuid = a.recipient.guid,
                teacherGuid = b.author,
                taskDate = b.sent;

            // Request server to mark task as done
            $.ajax({
                url: taskDataURL,
                method: "POST",
                data: {
                    data: JSON.stringify({
                        recipient: {
                            type: "user",
                            guid: studentGuid
                        },
                        event: {
                            type: 'mark-as-done',
                            sent: taskDate,
                            author: teacherGuid
                        }
                    })
                }
            });
        });

        $('.update-task-button').remove();
    });
})();