|
|
@ -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":[]}; |
|
|
|
const defaultSettingsString = JSON.stringify(defaultSettings); |
|
|
|
localStorage.setItem('alwayswin_settings',defaultSettingsString); |
|
|
|
alwaysWinSettingsString = defaultSettingsString; |
|
|
@ -73,14 +73,17 @@ function saveSettings() { |
|
|
|
let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value; |
|
|
|
let bidCap = document.querySelector("[name='bidCap']").value; |
|
|
|
|
|
|
|
let oversight = []; |
|
|
|
|
|
|
|
var latestSettings = alwaysWinSettings; |
|
|
|
latestSettings.isReloadEnabled = isReloadEnabledValue; |
|
|
|
latestSettings.isAutoLoginEnabled = isAutoLoginEnabledValue; |
|
|
|
latestSettings.minSecondsBetweenReloads = minSecondsBetweenReloadsValue; |
|
|
|
latestSettings.maxSecondsBetweenReloads = maxSecondsBetweenReloadsValue; |
|
|
|
latestSettings.bidCap = bidCap; |
|
|
|
//console.log("latestSettings");
|
|
|
|
//console.log(latestSettings);
|
|
|
|
if(latestSettings.oversight == null || latestSettings == undefined) { |
|
|
|
latestSettings.oversight = oversight; |
|
|
|
} |
|
|
|
|
|
|
|
const latestSettingsString = JSON.stringify(latestSettings); |
|
|
|
localStorage.setItem('alwayswin_settings',latestSettingsString); |
|
|
@ -135,24 +138,17 @@ function autoLoginIsEnabled(){ |
|
|
|
function getBidCap(countyId) { |
|
|
|
//Get the default bidcap from settings
|
|
|
|
var bidCap = alwaysWinSettings.bidCap; |
|
|
|
return bidCap; |
|
|
|
const countyOversight = alwaysWinSettings.oversight.find(({ id }) => id === countyId); |
|
|
|
if(countyFound(countyOversight)) { |
|
|
|
bidCap = countyOversight.bidCap; |
|
|
|
} |
|
|
|
return Number(bidCap); |
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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=" Top Bid"> 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 +174,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 +188,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; |
|
|
@ -241,12 +234,20 @@ function winCounty(countyJson, saveChanges) { |
|
|
|
|
|
|
|
function tieCounty(countyJson, saveChanges) { |
|
|
|
//TODO: implemnt me
|
|
|
|
let countyInfo = countyJson.id + " "+ countyJson.name; |
|
|
|
awLog(countyInfo +" tieCounty code not yet implemented"); |
|
|
|
} |
|
|
|
|
|
|
|
function watchCounty(countyJson, saveChanges) { |
|
|
|
//TODO: implemnt me
|
|
|
|
let countyInfo = countyJson.id + " "+ countyJson.name; |
|
|
|
awLog(countyInfo +" watchCounty code not yet implemented"); |
|
|
|
} |
|
|
|
|
|
|
|
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 +327,46 @@ function getOversightOptions(countyId, selectedAction) { |
|
|
|
return optionsHtml; |
|
|
|
} |
|
|
|
|
|
|
|
function countyFound(countyValue) { |
|
|
|
return countyValue !== undefined; |
|
|
|
} |
|
|
|
|
|
|
|
function upsertOversight(countyOversightJson) { |
|
|
|
//console.log(countyOversightJson);
|
|
|
|
const countyId = countyOversightJson.id; |
|
|
|
var countyFoundAt = alwaysWinSettings.oversight.findIndex(({ id }) => id === countyId); |
|
|
|
if(countyFoundAt == -1) { |
|
|
|
alwaysWinSettings.oversight.push(countyOversightJson); |
|
|
|
countyFoundAt = alwaysWinSettings.oversight.length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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 upsert Code should live in injectOversight
|
|
|
|
const isBidCapEnabled = false; |
|
|
|
const countyOversightJson = convertToOversightJson(countyJson, action, isBidCapEnabled); |
|
|
|
upsertOversight(countyOversightJson); |
|
|
|
//// END TempCode
|
|
|
|
|
|
|
|
let countyRow = countyJson.countyRow; |
|
|
|
|
|
|
|
var oversightCountyDiv = document.createElement('div'); |
|
|
@ -350,7 +382,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 +389,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 +413,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'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; |
|
|
@ -420,51 +451,37 @@ jQuery(window).on('load',function() { |
|
|
|
} |
|
|
|
|
|
|
|
//Inject our bits into the page for oversight
|
|
|
|
injectOversight("84035","win"); //washington, OR
|
|
|
|
injectOversight("87833","win"); //marion, OR
|
|
|
|
injectOversight("84034","tie"); //cascade, MT
|
|
|
|
injectOversight("84037","watch"); //clackamas, OR
|
|
|
|
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
|
|
|
|
|
|
|
|
//TODO: Get rid of these calls and only read injections from settings (possible when apply button is coded)
|
|
|
|
// For now they will be commented out unless it's a first run of the script
|
|
|
|
//injectOversight("84035","win"); //washington, OR
|
|
|
|
//injectOversight("87833","win"); //marion, OR
|
|
|
|
//injectOversight("84034","tie"); //cascade, MT
|
|
|
|
//injectOversight("84037","watch"); //clackamas, OR
|
|
|
|
//injectOversight("84038","watch"); //benton, OR
|
|
|
|
|
|
|
|
//// Now do the work
|
|
|
|
let newStats = []; |
|
|
|
|
|
|
|
let okToSaveChanges = true; |
|
|
|
let countiesToWinCount = countiesToWin.length; |
|
|
|
awLog("Checking "+ countiesToWinCount +" countiesToWin"); |
|
|
|
for(let i = 0; i < countiesToWinCount; i++) { |
|
|
|
let currentEntity = getCountyInfo(countiesToWin[i]) |
|
|
|
winCounty(currentEntity,okToSaveChanges); |
|
|
|
newStats.push(currentEntity); |
|
|
|
} |
|
|
|
|
|
|
|
okToSaveChanges = true; |
|
|
|
let countiesToTieCount = countiesToTie.length; |
|
|
|
awLog("Checking "+ countiesToTieCount +" countiesToTie"); |
|
|
|
for(let i = 0; i < countiesToTieCount; i++) { |
|
|
|
let currentEntity = getCountyInfo(countiesToTie[i]) |
|
|
|
tieCounty(currentEntity,okToSaveChanges); |
|
|
|
newStats.push(currentEntity); |
|
|
|
} |
|
|
|
|
|
|
|
okToSaveChanges = false; |
|
|
|
let countiesToWatchCount = countiesToWatch.length; |
|
|
|
awLog("Checking "+ countiesToWatchCount +" countiesToWatch"); |
|
|
|
for(let i = 0; i < countiesToWatchCount; i++) { |
|
|
|
let currentEntity = getCountyInfo(countiesToWatch[i]) |
|
|
|
tieCounty(currentEntity,okToSaveChanges); |
|
|
|
newStats.push(currentEntity); |
|
|
|
let oversightCount = alwaysWinSettings.oversight.length; |
|
|
|
awLog("Checking "+ oversightCount +" counties"); |
|
|
|
for(let i = 0; i < oversightCount; i++) { |
|
|
|
let currentEntity = alwaysWinSettings.oversight[i]; |
|
|
|
injectOversight(currentEntity.id, currentEntity.action); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
//console.log("Saving county info stats");
|
|
|
|