diff --git a/tampermonkey.js b/tampermonkey.js index c787ee6..55a37c0 100644 --- a/tampermonkey.js +++ b/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){ - //
- //
- //
- //
- //
 Top Bid - //
- // - //
- // - // - //
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 +"
"+ message; + document.getElementById("awLog").innerHTML = currentContent +""+ message +"
"; } 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 += ''; - priceDivHtml += ' | '; + priceDivHtml += ' | '; priceDivHtml += ''; oversightPriceDiv.innerHTML = priceDivHtml; @@ -382,13 +452,13 @@ jQuery(window).on('load',function() { //Inject our controls var newDiv = document.createElement ('div'); var newHtml = '
'; - newHtml += ' | '; + newHtml += ' | '; newHtml += ' | '; newHtml += ''; newHtml += '
'; newHtml += ': to seconds
'; newHtml += ': per county
'; - newHtml += '
Log:
'; + newHtml += '
'; newHtml += '
'; 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);