diff --git a/tampermonkey.js b/tampermonkey.js index 4baf374..33747ae 100644 --- a/tampermonkey.js +++ b/tampermonkey.js @@ -386,6 +386,183 @@ function convertToOversightJson(countyInfoJson, action, isBidCapEnabled){ return countyInfo; } +function getBidCapReasonIcon(reason) { + switch(reason) { + case 1: + return "🔀"; + case 2: + return "⏹"; + case 3: + return "🔼"; + case 4: + return "🔽"; + default: + return ""; + } + return ""; +} + +function getBidCapReason(tieBid, myBid, oversightAction, rowCapIsEnabled, rowCap, generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo) { + const Presidence_General = "general"; + const Presidence_Row = "row"; + const Presidence_Highest = "highest"; + const Presidence_Lowest = "lowest"; + const AppliesTo_All = "all"; + const AppliesTo_None = "none"; + const AppliesTo_Capped = "capped"; + const AppliesTo_Uncapped = "uncapped"; + const Oversight_Win = "win"; + const Oversight_Tie = "tie"; + const Oversight_Watch = "watch"; + const Oversight_Ignore = "ignore"; + const Capsource_Row = "row"; + const Capsource_General = "general"; + + let tieBidNum = number(tieBid); + let winBidNum = number(tieBid) + 25; + let generalCapNum = number(generalCap); + let rowCapNum = number(rowCap); + let myBidNum = number(myBid); + + //Build our response object + let bidCapData = {}; + results.shouldApplyCap = false; //Flag to indicate if the cap should be applied + results.reason = 0; //No Cap to start of with + results.trueCap = null; //Default to no true cap + results.capSource = null; //No caps applied + results.myBid = myBidNum; + + //WIP - LOTS of rules here - these are just the beginning. + if(generalCapIsEnabled) { + if(capPresidence == Presidence_General) { + if(applyPresidenceTo == AppliesTo_All) { + + results.shouldApplyCap = false; + results.capSource = Capsource_General; + results.trueCap = generalCapNum; + + switch(oversightAction) { + case Oversight_Win: + if(winBidNum > generalCapNum) { + results.shouldApplyCap = true; + results.reason = 1; + results.myBid = generalCapNum; + return results; + } + //winBidNum <= generalCapNum + results.reason = 2; + results.myBid = myBidNum; + break; + + case Oversight_Tie: + if(tieBidNum > generalCapNum) { + results.shouldApplyCap = true; + results.reason = 3; + results.myBid = generalCapNum; + return results; + } + //tieBidNum <= generalCapNum + results.reason = 4; + results.myBid = myBidNum; + break; + + case Oversight_Watch: + results.reason = 5; + break; + + case Oversight_Ignore: + results.reason = 6; + break; + + default: + //We should never get here because all oversight actions have been covered. + } + return results; + } + else if(applyPresidenceTo == AppliesTo_None){ + + } + else if(applyPresidenceTo == AppliesTo_Capped){ + + } + else if(applyPresidenceTo == AppliesTo_Uncapped){ + + } + return results; + } + else if(capPresidence == Presidence_Row) { + return results; + } + else if(capPresidence == Presidence_Highest){ + return results; + } + else if(capPresidence == Presidence_Lowest){ + return results; + } + } + //If we made it here, generalCapIsEnabled is FALSE so no conflicts should exist + //This means rowCaps are the winners if they are enabled. + if(rowCapIsEnabled) { + switch(oversightAction) { + case Oversight_Win: + if(winBidNum > rowCapNum) { + results.shouldApplyCap = true; + results.reason = 101; + results.trueCap = rowCapNum; + results.capSource = Capsource_Row; + results.myBid = rowCapNum; + return results; + } + //winBidNum <= rowCapNum + results.shouldApplyCap = false; + results.reason = 102; + results.trueCap = rowCapNum; + results.capSource = Capsource_Row; + results.myBid = myBidNum; + break; + + case Oversight_Tie: + if(tieBidNum > rowCapNum) { + results.shouldApplyCap = true; + results.reason = 103; + results.trueCap = rowCapNum; + results.capSource = Capsource_Row; + results.myBid = rowCapNum; + return results; + } + //tieBidNum <= generalCapNum + results.shouldApplyCap = false; + results.reason = 104; + results.trueCap = rowCapNum; + results.capSource = Capsource_Row; + results.myBid = myBidNum; + break; + + case Oversight_Watch: + results.shouldApplyCap = false; + results.reason = 105; + results.trueCap = null; + results.capSource = Capsource_Row; + results.myBid = myBidNum; + break; + + case Oversight_Ignore: + results.shouldApplyCap = false; + results.reason = 106; + results.trueCap = null; + results.capSource = Capsource_Row; + results.myBid = myBidNum; + break; + default: + //We should never get here because all oversight actions have been covered. + } + return results; + } + //Caps are not enabled for this row. + + return results; +} + function injectOversight(countyId, action) { countyId += ""; //cast into string incase number was passed in @@ -475,7 +652,7 @@ function injectOversight(countyId, action) { } if(capIsCurrentlyBeingAppliedToBid) { - priceDivHtml += '🔀 bid is capped at '+ trueCap; + priceDivHtml += getBidCapReasonIcon(1) + ' bid is capped at '+ trueCap; } @@ -512,7 +689,7 @@ jQuery(window).on('load',function() { newHtml += ' '; newHtml += ' per county
'; - newHtml += '
'; + newHtml += '
'; newHtml += '
'; newHtml += '';