Browse Source

Added oversight for each county

main
Steven 1 year ago
parent
commit
3f59bb5a19
  1. 163
      tampermonkey.js

163
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};
const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300, "bidCap":500, "oversight":{"all":[]}};
const defaultSettingsString = JSON.stringify(defaultSettings);
localStorage.setItem('alwayswin_settings',defaultSettingsString);
alwaysWinSettingsString = defaultSettingsString;
@ -73,12 +73,22 @@ function saveSettings() {
let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value;
let bidCap = document.querySelector("[name='bidCap']").value;
let oversight = {};
//oversight.win = [];//["84035","87833"]; //win
//oversight.tie = [];//["84034"]; //tie
//oversight.watch = [];//["84038"]; //watch
//oversight.ignore = [];//["84037"]; //ignore
oversight.all = [];
var latestSettings = alwaysWinSettings;
latestSettings.isReloadEnabled = isReloadEnabledValue;
latestSettings.isAutoLoginEnabled = isAutoLoginEnabledValue;
latestSettings.minSecondsBetweenReloads = minSecondsBetweenReloadsValue;
latestSettings.maxSecondsBetweenReloads = maxSecondsBetweenReloadsValue;
latestSettings.bidCap = bidCap;
if(latestSettings.oversight == null || latestSettings == undefined) {
latestSettings.oversight = oversight;
}
//console.log("latestSettings");
//console.log(latestSettings);
@ -135,6 +145,10 @@ function autoLoginIsEnabled(){
function getBidCap(countyId) {
//Get the default bidcap from settings
var bidCap = alwaysWinSettings.bidCap;
const countyOversight = alwaysWinSettings.oversight.all.find(({ id }) => id === countyId);
if(countyFound(countyOversight)) {
bidCap = countyOversight.bidCap;
}
return bidCap;
}
@ -142,17 +156,6 @@ function getBidCap(countyId) {
// Always win code to find and take the highest/tie bid
////////////////////////////////////////////////////////////////////////////////////
function getCountyInfo(countyId){
//<tr><th><div class="form-group form-row ml-1 mb-0"><label class="switch"><input class="subscription-status" type="checkbox" data-subscription_id="84035" checked=""><span class="async-slider round active"></span></label>
//<div class="ml-3"><label class="col-form-label"><a href="/app/subscription/84035">WASHINGTON, OR</a></label>
//</div></div></th>
//<td><div class="bid-controller input-group input-group-sm" data-subscription_id="84035" data-baseprice_default="75" data-base_price="75" data-top_bid="300" data-investor="24304">
//<div class="input-group-prepend"><span class="input-group-text bid-status top-bid" data-bid_status="&nbsp;Top Bid">&nbsp;Top Bid</span>
//<button class="btn btn-outline-primary bid-controller-btn bid-controller-btn--decrement" data-operation="decrement" type="button"><i class="icon ion-minus-round"></i></button></div>
//<input class="bid-controller--bid" readonly="readonly" size="4" style="text-align: center" type="text" value="425" name="investor_bid">
//<div class="input-group-append">
//<button class="btn btn-outline-primary bid-controller-btn bid-controller-btn--increment" data-operation="increment" type="button"><i class="icon ion-plus-round"></i></button>
//<button class="btn btn-primary btn-sm bid-controller-btn bid-controller-btn--save" type="button" data-operation="save" disabled="disabled">Save</button>
//</div></div></td></tr>
var county = document.querySelector('[data-subscription_id="'+ countyId +'"].subscription-status');
if(county === null) {
console.log("county "+ countyId +" row not found");
@ -178,8 +181,6 @@ function getCountyInfo(countyId){
let num_bidCap = getBidCap(countyId);
let num_clicksToBidCap = num_clicksToMinWin;
let oversightAction = "win"; //TODO: implement oversight actions per county and persist
bidController.readTimestamp = new Date();
bidController.isEnabled = county.checked;
bidController.id = county.dataset.subscription_id;
@ -194,8 +195,7 @@ function getCountyInfo(countyId){
bidController.clicksToMinWin = num_clicksToMinWin;
bidController.bidCap = num_bidCap;
bidController.clicksToBidCap = num_clicksToBidCap;
bidController.oversightAction = oversightAction;
bidController.btnSave = countyRow.querySelector('.bid-controller-btn--save');
bidController.btnSave = countyRow.querySelector('.bid-controller-btn--save');
bidController.btnBidUp = countyRow.querySelector('.bid-controller-btn--increment');
bidController.btnBidDown = countyRow.querySelector('.bid-controller-btn--decrement');
return bidController;
@ -243,10 +243,14 @@ function tieCounty(countyJson, saveChanges) {
//TODO: implemnt me
}
function watchCounty(countyJson, saveChanges) {
//TODO: implemnt me
}
function awLog(message) {
console.log(message);
const currentContent = document.getElementById("awLog").innerHTML;
document.getElementById("awLog").innerHTML = currentContent +"<br/>"+ message;
document.getElementById("awLog").innerHTML = currentContent +""+ message +"<br/>";
}
function encryptAndStore(encryptionKey, clearText) {
@ -326,15 +330,82 @@ function getOversightOptions(countyId, selectedAction) {
return optionsHtml;
}
function countyFound(countyValue) {
return countyValue !== undefined;
}
function upsertOversight(countyOversightJson) {
//console.log(countyOversightJson);
const countyId = countyOversightJson.id;
//console.log("checking "+countyOversightJson.action+" for "+countyId);
/*
var countyValue;
switch (countyOversightJson.action) {
case "win":
countyValue = alwaysWinSettings.oversight.win.find((value, index) => value === countyId);
if(!countyFound){
alwaysWinSettings.oversight.win.push(countyId);
}
break;
case "tie":
countyValue = alwaysWinSettings.oversight.tie.find((value, index) => value === countyId);
if(!countyFound){
alwaysWinSettings.oversight.tie.push(countyId);
}
break;
case "watch":
countyValue = alwaysWinSettings.oversight.watch.find((value, index) => value === countyId);
if(!countyFound){
alwaysWinSettings.oversight.watch.push(countyId);
}
break;
case "ignore":
countyValue = alwaysWinSettings.oversight.ignore.find((value, index) => value === countyId);
if(!countyFound){
alwaysWinSettings.oversight.ignore.push(countyId);
}
break;
default:
break;
}
*/
var countyFoundAt = alwaysWinSettings.oversight.all.findIndex(({ id }) => id === countyId);
console.log(countyId +" countyFoundAt: "+countyFoundAt);
if(countyFoundAt == -1) {
alwaysWinSettings.oversight.all.push(countyOversightJson);
countyFoundAt = alwaysWinSettings.oversight.all.length;
}
//console.log(alwaysWinSettings.oversight.all[countyFoundAt]);
}
function convertToOversightJson(countyInfoJson, action, isBidCapEnabled){
const countyInfo = {
"id":countyInfoJson.id,
"bidCap": countyInfoJson.bidCap,
"isBidCapEnabled": isBidCapEnabled,
"action": action
};
return countyInfo;
}
function injectOversight(countyId, action) {
countyId += ""; //cast into string incase number was passed in
//console.log("injecting oversight into county "+countyId);
var countyJson = getCountyInfo(countyId);
countyJson.oversightAction = action; //TODO stop overwriting this and have getCountyInfo read the stored value.
if(countyJson === null || countyJson === undefined) {
console.log(" could not find the county row "+countyId);
return;
}
//// BEGIN TempCode TODO: figure out if I want this code to live here
const isBidCapEnabled = false;
const countyOversightJson = convertToOversightJson(countyJson, action, isBidCapEnabled);
upsertOversight(countyOversightJson);
//// END TempCode
let countyRow = countyJson.countyRow;
var oversightCountyDiv = document.createElement('div');
@ -350,7 +421,6 @@ function injectOversight(countyId, action) {
var targetContainerCounty = countyRow.firstElementChild;
targetContainerCounty.appendChild(oversightCountyDiv);
var oversightPriceDiv = document.createElement('div');
oversightPriceDiv.id = "oversight-price-"+countyId;
oversightPriceDiv.style = "border: 1px dotted gray; padding: 0; margin: 0; font-size: 12px; overflow-x: visible";
@ -358,7 +428,7 @@ function injectOversight(countyId, action) {
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, countyJson.oversightAction) +'</select>';
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>';
oversightPriceDiv.innerHTML = priceDivHtml;
@ -382,13 +452,13 @@ jQuery(window).on('load',function() {
//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">AlwaysWin</label> | ';
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 += '<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 += '<div id="reloaderData"><div id="countdown"></div><progress value="0" max="100" id="progressBar" style="width: 100%;"></progress></div><div id="awLog" class="alwaysWinLog">Log:</div>';
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>';
newDiv.innerHTML = newHtml;
@ -427,45 +497,58 @@ jQuery(window).on('load',function() {
injectOversight("84038","watch"); //benton, OR
//// Now do the winning
var countiesToWin = [];
countiesToWin.push("84035"); //washington, OR
countiesToWin.push("87833"); //marion, OR
var countiesToTie = [];
countiesToTie.push("84034"); //cascade, MT
var countiesToWatch = [];
//countiesToWatch.push("84038"); //benton, OR
countiesToWatch.push("84037"); //clackamas, OR
let newStats = [];
let countiesToWinCount = alwaysWinSettings.oversight.all.length;
awLog("Checking "+ countiesToWinCount +" counties");
for(let i = 0; i < countiesToWinCount; i++) {
let currentEntity = alwaysWinSettings.oversight.all[i];
const countyInfoJson = getCountyInfo(currentEntity.id);
//console.log(currentEntity);
switch (currentEntity.action) {
case "win":
winCounty(countyInfoJson,true);
break;
case "tie":
tieCounty(countyInfoJson,true);
break;
case "watch":
watchCounty(countyInfoJson,false);
break;
default:
break;
}
newStats.push(countyInfoJson);
}
/*
let okToSaveChanges = true;
let countiesToWinCount = countiesToWin.length;
let countiesToWinCount = alwaysWinSettings.oversight.win.length;
awLog("Checking "+ countiesToWinCount +" countiesToWin");
for(let i = 0; i < countiesToWinCount; i++) {
let currentEntity = getCountyInfo(countiesToWin[i])
let currentEntity = getCountyInfo(alwaysWinSettings.oversight.win[i])
winCounty(currentEntity,okToSaveChanges);
newStats.push(currentEntity);
}
okToSaveChanges = true;
let countiesToTieCount = countiesToTie.length;
let countiesToTieCount = alwaysWinSettings.oversight.tie.length;
awLog("Checking "+ countiesToTieCount +" countiesToTie");
for(let i = 0; i < countiesToTieCount; i++) {
let currentEntity = getCountyInfo(countiesToTie[i])
let currentEntity = getCountyInfo(alwaysWinSettings.oversight.tie[i])
tieCounty(currentEntity,okToSaveChanges);
newStats.push(currentEntity);
}
okToSaveChanges = false;
let countiesToWatchCount = countiesToWatch.length;
let countiesToWatchCount = alwaysWinSettings.oversight.watch.length;
awLog("Checking "+ countiesToWatchCount +" countiesToWatch");
for(let i = 0; i < countiesToWatchCount; i++) {
let currentEntity = getCountyInfo(countiesToWatch[i])
tieCounty(currentEntity,okToSaveChanges);
let currentEntity = getCountyInfo(alwaysWinSettings.oversight.watch[i])
watchCounty(currentEntity,okToSaveChanges);
newStats.push(currentEntity);
}
*/
//console.log("Saving county info stats");
const countyInfoStats = saveCountyInfoStats(newStats);

Loading…
Cancel
Save