Sessionize AI detector

Check if a session is AI generated in Sessionize (using Winston AI)

As of 2024-08-16. See the latest version.

// ==UserScript==
// @name         Sessionize AI detector
// @namespace    http://tampermonkey.net/
// @version      2024-08-16
// @license      Apache 2.0
// @description  Check if a session is AI generated in Sessionize (using Winston AI)
// @author       Sebastiano Poggi
// @match        https://sessionize.com/app/organizer/event/evaluation/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sessionize.com
// @grant        GM_addStyle
// @grant        GM_xmlhttpRequest
// @connect      api.gowinston.ai
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        .ai-check { background: #ececec; border-radius: 4pt; padding: 0pt 3pt; font-size: small; font-weight: 600; }
        .ai-check::hover { color: unset; }
        .ai-checking { background: #95a2d3; color: white; }
        .ai-checking::before { content: "⌛"; margin-end: 4pt; }
        .ai-error { background: #c92c2c; color: white; }
        .ai-error::before { content: "❕"; margin-end: 4pt; }
        .ai-likely { background: #890d1d; color: white; }
        .ai-likely::before { content: "🚨"; margin-end: 4pt; }
        .ai-maybe { background: #dec7e5; color: #6a3183; }
        .ai-maybe::before { content: "❔"; margin-end: 4pt; }
        .ai-unlikely { background: #c0edbd; color: #358331; }
        .ai-unlikely::before { content: "✔️"; margin-end: 4pt; }
    `);

    function getSubmissionText(anchor) {
        const container = anchor.parentElement.parentElement.parentElement
            .querySelector('div.evaluation-session > p.es-description');
        return container.textContent.trim();
    }

    function showScore(anchor, score) {
        anchor.classList.remove('ai-checking');

        const displayScore = Math.round(100 - score);
        if (score < 30) {
            anchor.classList.add('ai-likely');
            anchor.textContent = `Likely LLM (${displayScore}%)`;
        } else if (score < 70) {
            anchor.classList.add('ai-maybe');
            anchor.textContent = `Maybe LLM (${displayScore}%)`;
        } else {
            anchor.classList.add('ai-unlikely');
            anchor.textContent = `Unlikely LLM (${displayScore}%)`;
        }
    }

    function checkIfAi(anchor) {
        anchor.classList.add('ai-checking');
        anchor.classList.remove('ai-error');
        anchor.textContent = 'Checking...';

        const text = getSubmissionText(anchor);
        const apiKey = undefined; // <---------------------------------------------------------- Your API key here
        if (!apiKey) {
            alert('You need to set an API key in the script!')
            throw Error('Missing API key')
        }

        const dataToSend = JSON.stringify({ 'text': text, 'sentences': false });
        GM_xmlhttpRequest({
            method: "POST",
            url: "https://api.gowinston.ai/functions/v1/predict",
            headers: {
                "Content-Type": "application/json",
                "Authorization": "Bearer " + apiKey
            },
            data: dataToSend,
            onload: function(response) {
                const data = JSON.parse(response.responseText);
                const score = data.score;
                console.log(`Prediction score: ${score} (used ${data.credits_used} credits, ${data.credits_remaining} remaining)`);
                showScore(anchor, score);
            },
            onerror: function(error) {
                console.error('Error:', error);
            }
        });
    }

    var elems = document.querySelectorAll("h3.es-title");
    for (let k = 0; k < elems.length; k++) {
        const titleElem = elems[k];
        var outerHtml = titleElem.outerHTML;
        titleElem.outerHTML = `${outerHtml}<p style="margin-top: -.5rem; margin-bottom: 2rem;"><a id='es-ai-check-${k}' class='ai-check' href="javascript:checkIfAi(${k})">Check for LLMs</a></p>`
        const anchor = document.getElementById('es-ai-check-' + k);
        anchor.addEventListener('click', () => checkIfAi(anchor));
    }
})();