Browse Source

refactored oversight be what oversight.all was

main
Steven 1 year ago
parent
commit
37ed84c86d
  1. 42
      tampermonkey.js

42
tampermonkey.js

@ -21,7 +21,7 @@ var alwaysWinSettingsString = localStorage.getItem('alwayswin_settings');
//console.log(alwaysWinSettingsString); //console.log(alwaysWinSettingsString);
if(alwaysWinSettingsString == null || alwaysWinSettingsString == undefined) { if(alwaysWinSettingsString == null || alwaysWinSettingsString == undefined) {
const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300, "bidCap":500, "oversight":{"all":[]}}; const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300, "bidCap":500, "oversight":[]};
const defaultSettingsString = JSON.stringify(defaultSettings); const defaultSettingsString = JSON.stringify(defaultSettings);
localStorage.setItem('alwayswin_settings',defaultSettingsString); localStorage.setItem('alwayswin_settings',defaultSettingsString);
alwaysWinSettingsString = defaultSettingsString; alwaysWinSettingsString = defaultSettingsString;
@ -73,8 +73,7 @@ function saveSettings() {
let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value; let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value;
let bidCap = document.querySelector("[name='bidCap']").value; let bidCap = document.querySelector("[name='bidCap']").value;
let oversight = {}; let oversight = [];
oversight.all = [];
var latestSettings = alwaysWinSettings; var latestSettings = alwaysWinSettings;
latestSettings.isReloadEnabled = isReloadEnabledValue; latestSettings.isReloadEnabled = isReloadEnabledValue;
@ -139,11 +138,11 @@ function autoLoginIsEnabled(){
function getBidCap(countyId) { function getBidCap(countyId) {
//Get the default bidcap from settings //Get the default bidcap from settings
var bidCap = alwaysWinSettings.bidCap; var bidCap = alwaysWinSettings.bidCap;
const countyOversight = alwaysWinSettings.oversight.all.find(({ id }) => id === countyId); const countyOversight = alwaysWinSettings.oversight.find(({ id }) => id === countyId);
if(countyFound(countyOversight)) { if(countyFound(countyOversight)) {
bidCap = countyOversight.bidCap; bidCap = countyOversight.bidCap;
} }
return bidCap; return Number(bidCap);
} }
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
@ -235,10 +234,14 @@ function winCounty(countyJson, saveChanges) {
function tieCounty(countyJson, saveChanges) { function tieCounty(countyJson, saveChanges) {
//TODO: implemnt me //TODO: implemnt me
let countyInfo = countyJson.id + " "+ countyJson.name;
awLog(countyInfo +" tieCounty code not yet implemented");
} }
function watchCounty(countyJson, saveChanges) { function watchCounty(countyJson, saveChanges) {
//TODO: implemnt me //TODO: implemnt me
let countyInfo = countyJson.id + " "+ countyJson.name;
awLog(countyInfo +" watchCounty code not yet implemented");
} }
function awLog(message) { function awLog(message) {
@ -331,10 +334,10 @@ function countyFound(countyValue) {
function upsertOversight(countyOversightJson) { function upsertOversight(countyOversightJson) {
//console.log(countyOversightJson); //console.log(countyOversightJson);
const countyId = countyOversightJson.id; const countyId = countyOversightJson.id;
var countyFoundAt = alwaysWinSettings.oversight.all.findIndex(({ id }) => id === countyId); var countyFoundAt = alwaysWinSettings.oversight.findIndex(({ id }) => id === countyId);
if(countyFoundAt == -1) { if(countyFoundAt == -1) {
alwaysWinSettings.oversight.all.push(countyOversightJson); alwaysWinSettings.oversight.push(countyOversightJson);
countyFoundAt = alwaysWinSettings.oversight.all.length; countyFoundAt = alwaysWinSettings.oversight.length;
} }
} }
@ -358,7 +361,7 @@ function injectOversight(countyId, action) {
return; return;
} }
//// BEGIN TempCode TODO: figure out if I want this code to live here //// BEGIN TempCode TODO: figure out if upsert Code should live in injectOversight
const isBidCapEnabled = false; const isBidCapEnabled = false;
const countyOversightJson = convertToOversightJson(countyJson, action, isBidCapEnabled); const countyOversightJson = convertToOversightJson(countyJson, action, isBidCapEnabled);
upsertOversight(countyOversightJson); upsertOversight(countyOversightJson);
@ -448,18 +451,21 @@ jQuery(window).on('load',function() {
} }
//Inject our bits into the page for oversight //Inject our bits into the page for oversight
injectOversight("84035","win"); //washington, OR //TODO: Get rid of these calls and only read injections from settings (possible when apply button is coded)
injectOversight("87833","win"); //marion, OR // For now they will be commented out unless it's a first run of the script
injectOversight("84034","tie"); //cascade, MT //injectOversight("84035","win"); //washington, OR
injectOversight("84037","watch"); //clackamas, OR //injectOversight("87833","win"); //marion, OR
injectOversight("84038","watch"); //benton, OR //injectOversight("84034","tie"); //cascade, MT
//injectOversight("84037","watch"); //clackamas, OR
//injectOversight("84038","watch"); //benton, OR
//// Now do the work //// Now do the work
let newStats = []; let newStats = [];
let countiesToWinCount = alwaysWinSettings.oversight.all.length; let oversightCount = alwaysWinSettings.oversight.length;
awLog("Checking "+ countiesToWinCount +" counties"); awLog("Checking "+ oversightCount +" counties");
for(let i = 0; i < countiesToWinCount; i++) { for(let i = 0; i < oversightCount; i++) {
let currentEntity = alwaysWinSettings.oversight.all[i]; let currentEntity = alwaysWinSettings.oversight[i];
injectOversight(currentEntity.id, currentEntity.action);
const countyInfoJson = getCountyInfo(currentEntity.id); const countyInfoJson = getCountyInfo(currentEntity.id);
//console.log(currentEntity); //console.log(currentEntity);
switch (currentEntity.action) { switch (currentEntity.action) {

Loading…
Cancel
Save