Browse Source

Added Presidence, Renamed BidCap to GeneralCap

main
Steven 1 year ago
parent
commit
77e58001bd
  1. 7
      README.md
  2. 117
      tampermonkey.js

7
README.md

@ -10,7 +10,7 @@ To load the Tampermonkey script:
### Functionality For Release
- [ ] Read from /app/subscriptions to get list of initial counties - if county is missing it automatically gets added.
- [ ] Sitewide bidcap (if any county bid exceeds X only bid up to X for that county)
- [x] Expose Sitewide bidcap (if any county bid exceeds X only bid up to X for that county)
- [x] Save button to persist changes (instead of waiting for refresh code to run)
- [x] Save settings to local storage
- [x] Retrieve settings from local storage
@ -20,11 +20,12 @@ To load the Tampermonkey script:
- [ ] use bidcap when processing each oversight
- [ ] Implement tieCounty code
- [ ] Implement watchCounty code
- [ ] Add cap presidence setting.
- [x] Add cap presidence setting.
- [ ] Add General Cap Applies to option
*If a row and settings cap are enabled then [options🔽] takes presidence.*
```Options
S - SettingsBidCap
G - GeneralBidCap
R - RowCap
H - The highest cap
L - The lowest cap

117
tampermonkey.js

@ -21,7 +21,7 @@ var alwaysWinSettingsString = localStorage.getItem('alwayswin_settings');
//console.log(alwaysWinSettingsString);
if(alwaysWinSettingsString == null || alwaysWinSettingsString == undefined) {
const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300, "bidCap":500, "oversight":[]};
const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300, "isGeneralCapEnabled":false, "generalCap":500, "oversight":[]};
const defaultSettingsString = JSON.stringify(defaultSettings);
localStorage.setItem('alwayswin_settings',defaultSettingsString);
alwaysWinSettingsString = defaultSettingsString;
@ -45,6 +45,8 @@ function getCheckedValue(fieldName) {
return reloadIsEnabled() ? "checked": "";
case "isAutoLoginEnabled":
return autoLoginIsEnabled() ? "checked": "";
case "isGeneralCapEnabled":
return generalCapIsEnabled() ? "checked" :"";
default:
return "";
}
@ -71,7 +73,10 @@ function saveSettings() {
let isAutoLoginEnabledValue = document.querySelector("[name='isAutoLoginEnabled']").checked;
let minSecondsBetweenReloadsValue = document.querySelector("[name='minSecondsBetweenReloads']").value;
let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value;
let bidCap = document.querySelector("[name='bidCap']").value;
let isGeneralCapEnabledValue = document.querySelector("[name='isGeneralCapEnabled']").checked;
let generalCap = document.querySelector("[name='generalCap']").value;
let capPresidence = document.querySelector("[name='capPresidence']").value;
let oversight = [];
@ -80,7 +85,9 @@ function saveSettings() {
latestSettings.isAutoLoginEnabled = isAutoLoginEnabledValue;
latestSettings.minSecondsBetweenReloads = minSecondsBetweenReloadsValue;
latestSettings.maxSecondsBetweenReloads = maxSecondsBetweenReloadsValue;
latestSettings.bidCap = bidCap;
latestSettings.isGeneralCapEnabled = isGeneralCapEnabledValue;
latestSettings.generalCap = generalCap;
latestSettings.capPresidence = capPresidence;
if(latestSettings.oversight == null || latestSettings == undefined) {
latestSettings.oversight = oversight;
}
@ -135,9 +142,15 @@ function autoLoginIsEnabled(){
return retVal;
}
function generalCapIsEnabled () {
var checkedValue = alwaysWinSettings.isGeneralCapEnabled ?? false;
var retVal = (checkedValue == true);
return retVal;
}
function getBidCap(countyId) {
//Get the default bidcap from settings
var bidCap = alwaysWinSettings.bidCap;
var bidCap = alwaysWinSettings.generalCap;
const countyOversight = alwaysWinSettings.oversight.find(({ id }) => id === countyId);
if(countyFound(countyOversight)) {
bidCap = countyOversight.bidCap;
@ -195,6 +208,10 @@ function getCountyInfo(countyId){
}
function winCounty(countyJson, saveChanges) {
if(countyJson?.id == undefined) {
awLog("Unable to find county. So no way to win it.");
return;
}
let countyInfo = countyJson.id + " "+ countyJson.name;
//console.log(countyJson.isWinning +" = "+ countyJson.tieBid +" > "+ countyJson.bid);
//console.log(countyJson.isWinningByTooMuch +" = "+ countyJson.bid +" > "+ countyJson.winningBid);
@ -315,15 +332,27 @@ function loginIfNeeded(){
return loginIsNeeded;
}
function renderOption(value, selectedValue) {
function renderOption(value, selectedValue, displayValue) {
if(displayValue == null || displayValue===undefined) {
displayValue = value;
}
var optionHtml = '<option value="'+ value +'"';
if(value == selectedValue) {
optionHtml += ' selected';
}
optionHtml += '>'+ value +'</option>';
optionHtml += '>'+ displayValue +'</option>';
return optionHtml;
}
function getCapPresidenceOptions(selectedAction) {
var optionsHtml = "";
optionsHtml += renderOption("row", selectedAction, "Row Cap");
optionsHtml += renderOption("general", selectedAction, "General Cap");
optionsHtml += renderOption("highest", selectedAction, "Highest Cap");
optionsHtml += renderOption("lowest", selectedAction, "Lowest Cap");
return optionsHtml;
}
function getOversightOptions(countyId, selectedAction) {
var optionsHtml = "";
optionsHtml += renderOption("win", selectedAction);
@ -392,11 +421,65 @@ function injectOversight(countyId, action) {
oversightPriceDiv.id = "oversight-price-"+countyId;
oversightPriceDiv.style = "border: 1px dotted gray; padding: 0; margin: 0; font-size: 12px; overflow-x: visible";
//Begin TODO: move this code block elsewhere IT IS WIP
const settingsCapPresidence = alwaysWinSettings.capPresidence;
const settings_Presidence_RowCap = (settingsCapPresidence == "row");
const settings_Presidence_GeneralCap = (settingsCapPresidence == "generl");
const settings_Presidence_HighestCap = (settingsCapPresidence == "highest");
const settings_Presidence_LowestCap = (settingsCapPresidence == "lowest");
const settingsGeneralCapAppliesTo = "capped" //[n,a,c,u]
const settings_GeneralCapAppliesTo_None = (settingsGeneralCapAppliesTo == "none")//None of the
const settings_GeneralCapAppliesTo_All = (settingsGeneralCapAppliesTo == "all")//All
const settings_GeneralCapAppliesTo_Capped = (settingsGeneralCapAppliesTo == "capped")//Capped Only
const settings_GeneralCapAppliesTo_Uncapped = (settingsGeneralCapAppliesTo == "uncapped")//UnCapped Only
const rowCapControlsShouldBeVisible = (action == "win" || action == "tie"); //TODO write logic to determine if the enable Bidcap checkbox and words should be visible
const rowCapCheckboxShouldBeVisible = (action == "win" || action == "tie"); //TODO: write logic
const rowCapCheckboxShouldBeDisabled = false; //TODO: write logic
const rowCapCheckboxShouldBeChecked = false; //TODO: write logic
const rowCapInputShouldBeVisible = (action == "win"); //TODO: run thru rules to determine showCapInfo value
const rowCapInputIsBeingOverridden = settings_Presidence_GeneralCap; //TODO: write logic
const rowCapInputShouldBeDisabled = (rowCapInputIsBeingOverridden || !rowCapCheckboxShouldBeChecked); //TODO: write logic
const trueCap = alwaysWinSettings.generalCap; //countyJson.bidCap; //TODO actually calcuate instead of reading from settings
const capIsCurrentlyBeingAppliedToBid = countyJson.bid > Number(trueCap);
//End TODO
var priceDivHtml ='';
//priceDivHtml += ''+ countyJson.id +'';
priceDivHtml += '<label><input disabled type="checkbox" style="transform:scale(.5);" name="enableBidCap-'+countyId+'" />cap:<input disabled type="text" name="bidCap-'+ countyId +'" id="bidCap-'+ countyId +'" style="font-size:10px; width:40px; height:12px;" value="'+ countyJson.bidCap +'" /></label>';
priceDivHtml += ' | <label for="oversightAction-'+countyId+'">act:</label><select disabled name="oversightAction-'+ countyId +'" id="oversightAction-'+ countyId +'">'+ getOversightOptions(countyId, action) +'</select>';
priceDivHtml += '<button disabled id="oversightSave-'+countyId+'" style="font-size:9px;background-color:#aaaaaa;color:#FFFFFF;padding:1px;border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px;margin:0px;">Apply</button>';
priceDivHtml += '<label for="oversightAction-'+countyId+'"><select name="oversightAction-'+ countyId +'" id="oversightAction-'+ countyId +'">'+ getOversightOptions(countyId, action) +'</select></label>';
if(rowCapControlsShouldBeVisible) {
priceDivHtml += ' | <label><input ';
if(rowCapCheckboxShouldBeDisabled) {
priceDivHtml += 'disabled ';
}
priceDivHtml += 'type="checkbox" style="transform:scale(.5);" name="enableBidCap-'+countyId+'"';
if(rowCapCheckboxShouldBeChecked) {
priceDivHtml += ' checked';
}
priceDivHtml += '/>cap';
if(rowCapInputShouldBeVisible) {
priceDivHtml += ' at <input ';
if(rowCapInputShouldBeDisabled) {
priceDivHtml += 'disabled ';
}
priceDivHtml += 'type="text" name="bidCap-'+ countyId +'" id="bidCap-'+ countyId +'" style="font-size:10px; width:40px; height:12px;" value="'+ countyJson.bidCap +'" /></label>';
}
if(rowCapInputIsBeingOverridden) {
priceDivHtml += '<strike>'+ countyJson.bidCap +'</strike> ->'+ alwaysWinSettings.bidCap;//TODO render override html
}
}
if(capIsCurrentlyBeingAppliedToBid) {
priceDivHtml += '🔀 bid is capped at '+ trueCap;
}
//priceDivHtml += '<button disabled id="oversightSave-'+countyId+'" style="font-size:9px;background-color:#aaaaaa;color:#FFFFFF;padding:1px;border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px;margin:0px;">Apply</button>';
oversightPriceDiv.innerHTML = priceDivHtml;
var targetContainer = countyRow.lastElementChild;
@ -412,19 +495,25 @@ jQuery(window).on('load',function() {
let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 180;
let isReloadEnabled = alwaysWinSettings.isReloadEnabled ?? false;
let isAutoLoginEnabled = alwaysWinSettings.isAutoLoginEnabled ?? false;
let bidCap = alwaysWinSettings.bidCap ?? 500;
let isGeneralCapEnabled = alwaysWinSettings.isGeneralCapEnabled ?? false;
let capPresidence = alwaysWinSettings.capPresidence ?? "row";
let generalCap = alwaysWinSettings.generalCap ?? 500;
let secondsBetweenReloads = getRandomNumberBetween(minSecondsBetweenReloads, maxSecondsBetweenReloads);
console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds");
//console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds");
//Inject our controls
var newDiv = document.createElement ('div');
var newHtml = '<div class="alwaysWin-ntsmhf" id="alwaysWin-ntsmhf">';
newHtml += '<input type="checkbox" name="isReloadEnabled" '+ getCheckedValue("isReloadEnabled") +'/><label for="isReloadEnabled">Auto Refresh</label> | ';
newHtml += '<input type="checkbox" name="isAutoLoginEnabled" '+ getCheckedValue("isAutoLoginEnabled") +'/><label for="isAutoLoginEnabled">Auto Login</label> | ';
newHtml += '<button class="alwaysWinButton" id="alwaysWin-ntsmhf-save" type="button">Save</button>';
newHtml += '<br />';
newHtml += '<button class="alwaysWinButton" id="alwaysWin-ntsmhf-save" type="button">Save</button><br />';
newHtml += '<label for="minSecondsBetweenReloads">Reload Every</label>:<input id="minSecondsBetweenReloads" type="text" size="3" name="minSecondsBetweenReloads" value="'+minSecondsBetweenReloads+'" /> to <input id="maxSecondsBetweenReloads" type="text" size="3" name="maxSecondsBetweenReloads" value="'+maxSecondsBetweenReloads+'" /> seconds <br/>';
newHtml += '<label for="bidCap">Don&apos;t bid more than</label>: <input id="bidCap" type="text" size="5" name="bidCap" value="'+ bidCap+'"/> per county<br />';
newHtml += '<label for="isGeneralCapEnabled"><input type="checkbox" name="isGeneralCapEnabled" '+ getCheckedValue("isGeneralCapEnabled") +'/>Don&apos;t bid more than</label> ';
newHtml += '<label for="generalCap">:</label><input id="generalCap" type="text" size="5" name="generalCap" value="'+ generalCap+'"/> per county<br />';
newHtml += '<label for="capPresidence">If a rowCap is enabled the <select id="capPresidence" name="capPresidence" />'+ getCapPresidenceOptions(capPresidence) +'</select> takes presidence</label><br/>';
newHtml += '<div id="reloaderData"><div id="countdown"></div><progress value="0" max="100" id="progressBar" style="width: 100%;"></progress></div><div id="awLog" class="alwaysWinLog"></div>';
newHtml += '</div>';

Loading…
Cancel
Save