Evalea Feedback Copy

Ermöglicht Speichern und Laden für Feedbackgespräche

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Evalea Feedback Copy
// @namespace   Violentmonkey Scripts
// @match       https://evalea.de/tool/interviews/answer/*
// @grant       none
// @version     1.0.3
// @author      Der_Floh
// @description Ermöglicht Speichern und Laden für Feedbackgespräche
// @license     MIT
// @icon				https://i.vimeocdn.com/portrait/42410065_200x200
// @homepageURL	https://greasyfork.org/de/scripts/492811-evalea-feedback-copy
// @supportURL	https://greasyfork.org/de/scripts/492811-evalea-feedback-copy/feedback
// ==/UserScript==

class SingleAnswer {
    constructor(spanElem) {
        this.value = spanElem.querySelector('input').value;

        const questionElem = spanElem.parentNode.parentNode;
        this.questionText = questionElem.querySelector('span').textContent;

        const sectionElem = questionElem.parentNode.parentNode.parentNode.parentNode;
        this.sectionText = sectionElem.getAttribute("data-cy");
    }
}

window.addEventListener("load", async () => {
    const container = document.getElementById("wrap");

    const saveButton = document.createElement("button");
    saveButton.id = "feedbacksavebutton";
    saveButton.textContent = "Save Feedback";
    saveButton.style.padding = "6px";
    saveButton.style.margin = "4px";
    saveButton.onclick = () => {
        saveButton.textContent = "Saving...";
        saveAnswersFromCurrentFeedback();
        saveButton.textContent = "Saved";
        setTimeout(() => {
            saveButton.textContent = "Save Feedback";
        }, 2000);
    };
    container.appendChild(saveButton);

    const loadButton = document.createElement("button");
    loadButton.id = "feedbackloadbutton";
    loadButton.textContent = "Load Feedback";
    loadButton.style.padding = "6px";
    loadButton.style.margin = "4px";
    loadButton.onclick = () => {
        loadButton.textContent = "Loading...";
        loadAnswersFromLastFeedback();
        loadButton.textContent = "Loaded";
        setTimeout(() => {
            loadButton.textContent = "Load Feedback";
        }, 2000);
    };
    container.appendChild(loadButton);
});

function saveAnswersFromCurrentFeedback() {
    const answers = getAnswersFromCurrentFeedback();
    saveAnswers(answers);
}

function getAnswersFromCurrentFeedback() {
    const spans = document.body.querySelectorAll('span[class="activeB"]');
    const answers = [];
    for (const spanElem of spans) {
        const inputElem = spanElem.querySelector("input");
        if (inputElem && inputElem.value) {
            const answer = new SingleAnswer(spanElem);
            answers.push(answer);
        }
    }
    return answers;
}

function saveAnswers(answers) {
    const serializedData = JSON.stringify(answers);
    localStorage.setItem("lastfeedbackanswers", serializedData);
}

function getAnswersFromLastFeedback() {
    const serializedData = localStorage.getItem("lastfeedbackanswers");
    if (serializedData)
        return JSON.parse(serializedData);
}

function loadAnswersFromLastFeedback() {
    const answers = getAnswersFromLastFeedback();
    loadAnswers(answers);
}

function loadAnswers(answers) {
    const inputs = document.body.querySelectorAll('input[class="scale-circle"]');
    for (const inputElem of inputs) {
        const questionElem = inputElem.parentNode.parentNode.parentNode;
        const questionText = questionElem.querySelector('span').textContent;

        const sectionElem = questionElem.parentNode.parentNode.parentNode.parentNode;
        const sectionText = sectionElem.getAttribute("data-cy");

        const answer = answers.find(elem => elem.sectionText == sectionText && elem.questionText == questionText);
        if (answer && answer.value == inputElem.value)
            inputElem.click();
    }
}