User:Tamzin/sandbox.js

/* jshint esversion: 6 */

var now = new Date; now.setMinutes(0); now.setSeconds(0); const currentStoredValue = mw.storage.getObject(now.toUTCString);

function warnMe(level) { let logo = $("#p-logo"); logo.css("background-color: red"); switch(level) { case 'warning-percentage': logo.attr('title', "Less than 40% of your recent edits are to contentspace"); break; case 'warning-nonauto': logo.attr('title', "You do not have enough recent non-automated contentspace edits."); } }

if (currentStoredValue.startsWith('warning-')) { warnMe(currentStoredValue); throw ''; }

var lastMonth = new Date; lastMonth.setDate(lastMonth.getDate - 30); const username = mw.config.get('wgUserName'); const contentNamespaces = [0, 14, 100, 118];

function getRecentContentFraction { let monthCounts = fetch("https://xtools.wmcloud.org/api/user/month_counts/enwiki/" + username); let contentEdits, totalEdits = getEditsInMonth(now.getUTCFullYear, now.getUTCMonth, monthCounts); if (totalEdits < 100) { let lastContentEdits, lastTotalEdits = getContentEditsInMonth(lastMonth.getUTCFullYear, lastMonth.getUTCMonth, monthCounts); contentEdits += lastContentEdits; totalEdits += lastTotalEdits; }	return contentEdits / totalEdits; }

function getEditsInMonth(year, month, monthCounts) { let totalEdits = 0; let contentEdits = 0; for (const ns in contentNamespaces) { contentEdits += monthCounts.totals[ns][year][month]; }	return (contentEdits, totalEdits); }

function getNonAutoEdits { let nonAuto = []; for (const ns in contentNamespaces) { let namespaceNonAuto = fetch("https://xtools.wmcloud.org/api/user/nonautomated_edits/en.wikipedia/" + username + "/" + ns).nonautomated_edits.slice(0, 50); nonAuto.concat(namespaceNonAuto); } }

function storeValue(value) { mw.storage.set(now, value, 3600); }

function main { let contentFraction = getRecentContentFraction; let outcome = 'clear'; if (contentFraction < 0.4) { outcome = 'warning-value'; }	else { let nonAutoEdits = getNonAutoEdits; } }