// ==UserScript== // @name EyeWire Statistics // @namespace http://tampermonkey.net/ // @version 2.6 // @description Shows EW Statistics and adds some other functionality // @author Krzysztof Kruk // @match https://*.eyewire.org/* // @exclude https://*.eyewire.org/1.0/* // @downloadURL https://raw.githubusercontent.com/ChrisRaven/EWStats/master/ewStats.user.js // @updateURL https://raw.githubusercontent.com/ChrisRaven/EWStats/master/ewStats.meta.js // @grant GM_xmlhttpRequest // @connect ewstats.feedia.co // @require https://chrisraven.github.io/EWStats/jquery-jvectormap-2.0.3.min.js // @require https://chrisraven.github.io/EWStats/jquery-jvectormap-world-mill.js // @require https://chrisraven.github.io/EWStats/spectrum.js // @require https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js // ==/UserScript== /*jshint esversion: 6 */ /*globals $, account, tomni */ var LOCAL = false; if (LOCAL) { console.log('%c--== TURN OFF "LOCAL" BEFORE RELEASING!!! ==--', "color: red; font-style: italic; font-weight: bold;"); } (function() { 'use strict'; 'esversion: 6'; var K = { gid: function (id) { return document.getElementById(id); }, qS: function (sel) { return document.querySelector(sel); }, qSa: function (sel) { return document.querySelectorAll(sel); }, addCSSFile: function (path) { $("head").append(''); }, // Source: https://stackoverflow.com/a/6805461 injectJS: function (text, sURL) { var tgt, scriptNode = document.createElement('script'); scriptNode.type = "text/javascript"; if (text) { scriptNode.textContent = text; } if (sURL) { scriptNode.src = sURL; } tgt = document.getElementsByTagName('head')[0] || document.body || document.documentElement; tgt.appendChild(scriptNode); }, // localStorage ls: { get: function (key) { return localStorage.getItem(account.account.uid + '-ews-' + key); }, set: function (key, val) { localStorage.setItem(account.account.uid + '-ews-' + key, val); }, remove: function (key) { localStorage.removeItem(account.account.uid + '-ews-' + key); } } }; var intv = setInterval(function () { if (typeof account === 'undefined' || !account.account.uid) { return; } clearInterval(intv); main(); }, 100); function main() { // migration to localStorage variables associated with an account and variables' names cleaning var lsData = localStorage; if (lsData['ews-settings']) { K.ls.set('settings', lsData['ews-settings']); localStorage.removeItem('ews-settings'); } if (lsData.ewsAccuData) { K.ls.set('accu-data', lsData.ewsAccuData); localStorage.removeItem('ewsAccuData'); } if (lsData.ewsLastHighlighted) { K.ls.set('last-highlighted', lsData.ewsLastHighlighted); localStorage.removeItem('ewsLastHighlighted'); } if (lsData.ewsSCHistory) { K.ls.set('sc-history', lsData.ewsSCHistory); localStorage.removeItem('ewsSCHistory'); } if (lsData['overview-draggable']) { K.ls.set('overview-draggable', lsData['overview-draggable']); localStorage.removeItem('overview-draggable'); } // end: migration // SETTINGS var EwsSettings = function () { // var intv; var _this = this; var settings = { 'ews-auto-refresh-showmeme': false, 'ews-submit-using-spacebar': false }; // var settingsName = account.account.uid + '-ews-settings'; var stored = K.ls.get('settings'); if(stored) { $.extend(settings, JSON.parse(stored)); } this.get = function(setting) { return settings[setting]; }; $('#settingsMenu').append(` `); function add(name, id) { $('#ews-settings-group').append(`
` + name + `
`); } if (account.roles.scythe || account.roles.mystic) { add('Auto Refresh ShowMeMe', 'ews-auto-refresh-showmeme'); } add('Submit using Spacebar', 'ews-submit-using-spacebar'); this.set = function(setting, value) { settings[setting] = value; K.ls.set('settings', JSON.stringify(settings)); }; this.getAll = function () { return settings; }; // source: crazyman's script $('#ews-settings-group input').each(function() { var elem, pref, sets; elem = $(this); pref = this.id; sets = _this.getAll(); this.checked = sets[pref]; elem.add(elem.closest('.checkbox')).removeClass(sets[pref] ? 'off' : 'on').addClass(sets[pref] ? 'on' : 'off'); $(document).trigger('ews-setting-changed', {setting: pref, state: sets[pref]}); }); $('#ews-settings-group input').closest('div.setting').click(function(evt) { var $elem, elem, newState; $elem = $(this).find('input'); elem = $elem[0]; newState = !elem.checked; evt.stopPropagation(); elem.checked = newState; _this.set(elem.id, newState); $elem.add($elem.closest('.checkbox')).removeClass(newState ? 'off' : 'on').addClass(newState ? 'on' : 'off'); $(document).trigger('ews-setting-changed', {setting: elem.id, state: newState}); }); $(document).on('ews-setting-changed', function (evt, data) { if (data.setting === 'ews-custom-highlight') { $('#ews-custom-highlight-color-label')[data.state ? 'slideDown' : 'slideUp'](); } }); }; // end: SETTINGS if (LOCAL) { K.addCSSFile('http://127.0.0.1:8887/EWStats.css'); } else { K.addCSSFile('https://chrisraven.github.io/EWStats/EWStats.css?v=10'); } K.injectJS(` (function (open) { XMLHttpRequest.prototype.open = function (method, url, async, user, pass) { this.addEventListener("readystatechange", function (evt) { if (this.readyState == 4 && this.status == 200 && url.indexOf('/1.0/task/') !== -1 && url.indexOf('/submit') === -1 && method.toLowerCase() === 'post') { $(document).trigger('votes-updated', {cellId: tomni.cell, cellName: tomni.getCurrentCell().info.name, datasetId: tomni.getCurrentCell().info.dataset_id}); } if (this.readyState == 4 && this.status == 200 && url.indexOf('/stats') !== -1 && method.toLowerCase() === 'get') { $(document).trigger('stats-collected'); } }, false); open.call(this, method, url, async, user, pass); }; }) (XMLHttpRequest.prototype.open); `); var settings = new EwsSettings(); $(document).on('votes-updated', function (event, data) { var host = window.location.hostname, targetUrl = 'https://'; if (host.indexOf('beta') !== -1) { targetUrl += 'beta.'; } else if (host.indexOf('chris') !== -1) { targetUrl += 'chris.'; } targetUrl += 'eyewire.org/1.0/cell/' + data.cellId + '/tasks/complete/player'; $.getJSON(targetUrl, function (JSONData) { var btn = $('.showmeme button'); if (!JSONData) { return; } if (!btn.hasClass('on1')) { if (btn.hasClass('on2')) { btn.click().click().click(); } else { btn.click(); setTimeout(function () { btn.click(); setTimeout(function () { btn.click(); }, 500); }, 500); } } }); }); // submit using Spacebar $('body').keydown(function (evt) { var btn; if (evt.keyCode === 32 && tomni.gameMode && settings.get('ews-submit-using-spacebar')) { if (!tomni.task.inspect) { btn = K.gid('actionGo'); } else { if (account.roles.scythe || account.roles.mystic) { btn = K.gid('saveGT'); } else { btn = K.gid('flagCube'); } } if (btn) { evt.stopPropagation(); btn.click(); } } }); // end: submit using Spacebar // tu } // end: main() })(); // end: wrapper