(MTurk) Show Qualtrics Survey Progress

Shows hidden progress on qualtrics surveys

As of 2019-09-07. See the latest version.

// ==UserScript==
// @name         (MTurk) Show Qualtrics Survey Progress
// @namespace    https://greasyfork.org/en/users/367017-shinobu-oshino
// @version      1.25
// @description  Shows hidden progress on qualtrics surveys
// @author       letsfindcommonground (mktemp@pm.me)
// @match        https://*.qualtrics.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let oldProgressBar = document.querySelector('#ProgressBar');
    if(oldProgressBar) {
        oldProgressBar.style.display = 'none';
    }

    if(!(window.QSettings && window.QSettings.pt)) {
        return;
    }
    let progress = window.QSettings.pt.ProgressPercent;

    const indicator = document.createElement('span');
    indicator.textContent = `${progress}%`;
    indicator.style.cssText = `color: white; background: black; padding: 8px 12px;
position: absolute; left: 0; top: 0; font-family: 'Roboto', sans-serif; font-size: 0.9em;
border-bottom-right-radius: 8px;`;
    document.body.appendChild(indicator);

    let oldXHROpen = window.XMLHttpRequest.prototype.open;
    window.XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
        if(url.includes('next?rand=')) {
            this.addEventListener('load', function() {
                const result = JSON.parse(this.response);
                indicator.textContent = `${result.ProgressPercent}%`;
            });
        }

        return oldXHROpen.apply(this, arguments);
    };
})();