DofusPlanet Quest Progress Saving

Save progress for DofusPlanet without account.

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         DofusPlanet Quest Progress Saving
// @namespace    https://github.com/blackstar0169/dofusplanet-quest-saving
// @version      1.1
// @description  Save progress for DofusPlanet without account.
// @author       blackstar0169
// @match        https://dofusplanet.com/quetes/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=dofusplanet.com
// @license GNU GPLv3
// @grant  GM.setValue
// @grant  GM.getValue
// ==/UserScript==

(function() {
    'use strict';

    // Retrieve checkboxes
    const checkboxeSelector = 'input[type="checkbox"][name^="quete"]';
    const checkboxes = document.querySelectorAll(checkboxeSelector);
    const scriptID = 'DPQPS_5ece4797eaf5e';

    console.log('['+scriptID+'] Init DofusPlanet Quest Progress Saving');

    function parseDatas(datas) {
        const defaultDatas = {
            quests: {}
        };
        if (typeof datas === 'string' && datas.charAt(0) === '{') {
            try {
                datas = JSON.parse(datas);
                datas = Object.assign(defaultDatas, datas);
            } catch (e) {
                datas = defaultDatas;
            }
        } else {
            datas = defaultDatas;
        }
        return datas;
    }

    function updateCheckboxes(datas) {
        // console.log('['+scriptID+'] updateCheckboxes');
        // console.log(datas);
        for (var i=0; i<checkboxes.length; i++) {
            var checked = false;
            const questId = checkboxes[i].name.replace('quete', '');

            for (var id in datas.quests) {
                if (datas.quests.hasOwnProperty(id) && id == questId) {
                    checked = datas.quests[id];
                    break;
                }
            }

            checkboxes[i].checked = checked;
        }
    }

    // Retrieve datas and update checkboxes
    setInterval(function () {
        GM.getValue(scriptID).then(function (datas) {
            updateCheckboxes(parseDatas(datas));
        });
    }, 3000);

    // Listen any modifications
    for (var i=0; i<checkboxes.length; i++) {
        checkboxes[i].addEventListener('change', function (e) {
            const questId = e.target.name.replace('quete', '');
            // console.log(e);
            //console.log('['+scriptID+'] Change '+questId);
            // Save modifications
            GM.getValue(scriptID).then(function (datas) {
                datas = parseDatas(datas);
                datas.quests[questId] = e.target.checked;
                GM.setValue(scriptID, JSON.stringify(datas));
            });
        });
    }


})();