From dc59fc6f20f9aeff1635e2049400d9d1091df46b Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Sun, 17 Sep 2017 02:23:04 +0200 Subject: uftow-stats, -simple 1.4.0 --- uftow-stats-simple.user.js | 134 +++++++++++++++++++++++------------------ uftow-stats.user.js | 144 +++++++++++++++++++++++++-------------------- 2 files changed, 158 insertions(+), 120 deletions(-) diff --git a/uftow-stats-simple.user.js b/uftow-stats-simple.user.js index f04c987..c8993b7 100644 --- a/uftow-stats-simple.user.js +++ b/uftow-stats-simple.user.js @@ -2,7 +2,7 @@ // @name uftow-stats-simple // @namespace uftow-stats-simple // @include https://ubuntuforums.org/showthread.php?t=1579442* -// @version 1.3.0 +// @version 1.4.0 // @Description Generates stats for Tug of War - simple variant. // @grant GM_log // @grant GM_getValue @@ -15,7 +15,7 @@ var towStats = { alreadyHasStartCounting:false, scores:new Array(), - lastPostNumber:null, + lastPostNumber:0, lastPoster:null, startPostNumber:null, endPostNumber:null, @@ -24,12 +24,17 @@ var towStats = { this.firstPostNumber=parseInt(this.postContainers[0].getElementsByClassName('postcounter')[0].textContent.substr(1)); this.lastPostNumber=parseInt(this.postContainers[this.postContainers.length-1].getElementsByClassName('postcounter')[0].textContent.substr(1)); if(!GM_getValue("statsActive",false)){ - GM_registerMenuCommand("Start counting posts",function(){towStats.startCounting();},'S'); - this.alreadyHasStartCounting=true; + this.addStartCounting(); }else{ - this.startCounting(); + this.continueCounting(); } - GM_registerMenuCommand("Clear counter",function(){towStats.clearStats();},'A'); + GM_registerMenuCommand("Tug of War: Clear counter",function(){towStats.clearStats();},'A'); + }, + addStartCounting: function(){ + GM_registerMenuCommand("Tug of War: Start counting",function(){towStats.startCounting();},'S'); + GM_registerMenuCommand("Tug of War: Continue counting",function(){towStats.continueCounting();},'C'); + GM_registerMenuCommand("Tug of War: Show last results",function(){towStats.showSummary();},'R'); + this.alreadyHasStartCounting=true; }, recordPosts: function(startPost){ var postNumber; @@ -71,6 +76,13 @@ var towStats = { } }, getSummary: function(){ + if(this.scores.length>=2 && !(this.endPostNumber!=null && this.lastPostNumber=this.endPostNumber) || !this.goToNextPage()){ - if(this.scores.length>=2 && !(this.endPostNumber!=null && this.lastPostNumber=200){ this.winner='community'; }if(this.winner!=null){ - this.marker=postInfo[0]; - this.markerPost=postInfo[3]; break; } //GM_log("Post: "+postInfo[3]+", Round score: "+this.currentScore); @@ -114,6 +115,18 @@ var towStats = { } }, getSummary: function(){ + if(this.winner!=null){ + window.alert("Counting complete.\n"+ + "The "+((this.currentScore<0)?'-':'')+"200 mark is at post #"+this.lastPostNumber+"\n"+ + "Stats will be displayed in the next dialog box."); + }else if(this.scores.length>=3){ + window.alert("Tug of War is yet to be completed.\n"+ + "Its score is "+this.currentScore+" points as of post #"+this.lastPostNumber+"\n"+ + "Intermediate stats will be displayed in the next dialog box."); + }else{ + window.alert("Tug of War is yet to be completed."); + return false; + } var alertText="[B]TUG OF WAR LAST ROUND STATS[/B]\n"; var totalPoints=0; var totalPosts=0; @@ -138,7 +151,7 @@ var towStats = { } totalPosts+=this.scores[i+1]; } - totalWinningPoints=(this.winner=='community')?totalCommunityPoints:totalModPoints; + totalWinningPoints=(this.currentScore>=0)?totalCommunityPoints:totalModPoints; minimumRequiredMVP=Math.round(totalWinningPoints*0.15); alertText+="[B]Total points:[/B] "+totalPoints+" from "+totalPosts+" posts\n"; alertText+="[B]Total community points:[/B] "; @@ -164,11 +177,11 @@ var towStats = { modStats=this.getListText(modParticipants,minimumRequiredMVP); alertText+=modStats[0]+"\n"; alertText+="[B]LAST ROUND MVPs[/B]\n"; - alertText+="- "+this.marker+" (at post #"+this.markerPost+")\n"; - //GM_log("MVP order: "+this.marker+" made the mark at post #"+this.markerPost); - mvpList=(this.winner=='community')?communityStats[1]:modStats[1]; + alertText+="- "+this.lastPoster+" (at post #"+this.lastPostNumber+")\n"; + //GM_log("MVP order: "+this.lastPoster+" made the mark at post #"+this.lastPostNumber); + mvpList=(this.currentScore>=0)?communityStats[1]:modStats[1]; for(var i=0;i