// ==UserScript== // @name Wanikani Procrastination Annihilation // @namespace mempo // @description Hides the forums until you've completed some reviews // @include https://www.wanikani.com/* // @version 1.2.3.4 // @grant none // @downloadURL https://update.greasyfork.icu/scripts/14972/Wanikani%20Procrastination%20Annihilation.user.js // @updateURL https://update.greasyfork.icu/scripts/14972/Wanikani%20Procrastination%20Annihilation.meta.js // ==/UserScript== console.log('started Wanikani Procrastination Annihilation BETA'); var currentTime = new Date().getTime(); var debug = false; //TODO: change into method for 1-refresh-reinit var initialSettings = ({ 'apiKey': "", 'lastUnlock': 0, 'lastReviewAmount': 0, 'unlockPercentage': 0.5, 'onLockDown': false, 'resetTime': 1800000, //Half hour: 30min * 60sec * 1000ms 'offset': 30 }); //console.log(initialSettings); //$.jStorage = unsafeWindow.$.jStorage; var settings = $.jStorage.get('WPA_Settings'); console.log(settings); if(settings === null){ //not initialized yet console.log('#### no settings found'); if (window.location.href.indexOf('account') != - 1) { initialSettings.apiKey = "" + retrieveAPIkey(); settings = initialSettings; console.log('@@@@@' + initialSettings.apiKey); } else { var okcancel = confirm('Wanikani Procrastination Annihilation has no API key entered!\nPress OK to go to your settings page and retrieve your API key!'); if (okcancel == true) { window.location = 'https://www.wanikani.com/settings/account'; return; } } $.jStorage.set('WPA_Settings', JSON.stringify(settings)); console.log('settings loaded in jstorage'); //GO BACK TO DASHBOARD window.location = 'https://www.wanikani.com/dashboard'; return; /* TODO: find a way to look up API key without leaving dashboard var settingsHTML = $.get( "https://www.wanikani.com/settings/account.html", function(html) { retrieveAPIkey(html); }) .fail(function() { alert( "WPA error: The API key could not be located" ); }); */ }else{ settings = $.parseJSON(settings); console.log("##### found the settings!"); } console.log('//////////////////////////////'); console.log('apiKey is ' + settings.apiKey); console.log('lastUnlock is ' + settings.lastUnlock); console.log('lastReviewAmount is ' + settings.lastReviewAmount); console.log('onLockDown is ' + settings.onLockDown); console.log('//////////////////////////////'); /********************************************************************************* * * * checkPageRedirection * * * **********************************************************************************/ if (window.location.href.indexOf('chat') != -1 || window.location.href.indexOf('community') != -1) { if(settings.onLockDown === true){ alert("I'm very sorry, but the forums are on lockdown. Complete some reviews to unlock them!"); window.location = 'https://www.wanikani.com/review'; }else { console.log("well go on, the forums are unlocked!"); } } if (window.location.href.indexOf('dashboard') != -1 || window.location.href === "https://www.wanikani.com/") { displaySettings(); checkLockDown(); } /* TODO: for next update if (window.location.href.indexOf('review/session') != -1) { console.log('doing reviews!'); var currentReviewAmount = $.jStorage.get('activeQueue').length + $.jStorage.get('reviewQueue').length; console.log("//////////total amount of reviews at start is: " + currentReviewAmount); $.jStorage.listenKeyChange('completedCount', function(){ var currentCompletedAmount = $.jStorage.get('completedCount'); if(currentCompletedAmount >= (1 - settings.unlockPercentage) * currentCompletedAmount){ console.log('§§§§§§§§ Did sufficient amount of reviews! Forums unlocked'); $('#summary-button').after('
Sorry, the forums are on lockdown. Complete some reviews before you can socialize again.
' + // ' [settings]'+ '