From 2a81d98de98e9760dca276783b049f5700f09389 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 16 Nov 2023 02:30:08 -0800 Subject: [PATCH] Saving countyInfoStats to localStorage --- README.md | 5 +++- tampermonkey.js | 61 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6865ded..4df9744 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ To load the Tampermonkey script: [] show rowAction2 array //AlwaysTie [] show rowAction3 array //WatchTie [] PriceChangeOverTime Chart + [] Download Stats + [] Clear Stats [] For each countyRow inject [] "rowAction" dropdown with options: 0 - Ignore @@ -27,7 +29,8 @@ To load the Tampermonkey script: [] save to analytics checkbox [] county bidcap [] Option to sell leads that don't fit your criteria but you can't return on the secondary market. - [] Store tie values for statistical analysis over time. + [x] Store tie values for statistical analysis over time. + [] Implement tieCounty code diff --git a/tampermonkey.js b/tampermonkey.js index 8dea7cc..8feed56 100644 --- a/tampermonkey.js +++ b/tampermonkey.js @@ -72,6 +72,19 @@ function saveSettings() { return latestSettings; } +function saveCountyInfoStats(newStats) { + let existingStats = []; + //get existing stats if they exist + let existingStatsString = localStorage.getItem('alwayswin_stats'); + if(existingStatsString != null && existingStatsString !== undefined) { + existingStats = JSON.parse(existingStatsString); + } + const combinedStats = existingStats.concat(newStats) + const updatedStatsString = JSON.stringify(combinedStats); + localStorage.setItem('alwayswin_stats',updatedStatsString); + //console.log(combinedStats); +} + function reload() { console.log("Saving settings..."); let alwaysWinSettings = saveSettings(); @@ -129,6 +142,7 @@ function getCountyInfo(countyId){ num_clicksToMinWin = (winGap + bidIncriment) / bidIncriment; } + bidController.readTimestamp = new Date(); bidController.isEnabled = county.checked; bidController.id = county.dataset.subscription_id; bidController.name = county.closest("div").getElementsByTagName('a')[0].innerText; @@ -181,6 +195,11 @@ function winCounty(countyJson, saveChanges) { } } +function tieCounty(countyJson, saveChanges) { + //TODO: implemnt me +} + + jQuery(window).on('load',function() { console.log("Page loaded at: "+ new Date()); @@ -202,23 +221,47 @@ jQuery(window).on('load',function() { var countiesToWin = []; countiesToWin.push("84035"); //washington, OR countiesToWin.push("87833"); //marion, OR - //countiesToWin.push("84038"); //benton, OR - //countiesToWin.push("84037"); //clackamas, OR - //var countiesToTie = []; - //countiesToTie.push("84034"); //cascade, MT - //countiesToTie.push("84038"); //benton, OR - //countiesToTie.push("84037"); //clackamas, OR - //tieCounty(getCountyInfo(countiesToTie[0].id); + var countiesToTie = []; + countiesToTie.push("84034"); //cascade, MT + + var countiesToWatch = []; + //countiesToWatch.push("84038"); //benton, OR + countiesToWatch.push("84037"); //clackamas, OR + + let newStats = []; let okToSaveChanges = true; let countiesToWinCount = countiesToWin.length; - for(var i = 0; i < countiesToWinCount; i++) { + for(let i = 0; i < countiesToWinCount; i++) { let currentEntity = getCountyInfo(countiesToWin[i]) winCounty(currentEntity,okToSaveChanges); + newStats.push(currentEntity); + } + + okToSaveChanges = true; + let countiesToTieCount = countiesToTie.length; + for(let i = 0; i < countiesToTieCount; i++) { + let currentEntity = getCountyInfo(countiesToTie[i]) + tieCounty(currentEntity,okToSaveChanges); + newStats.push(currentEntity); + } + + okToSaveChanges = false; + let countiesToWatchCount = countiesToWatch.length; + for(let i = 0; i < countiesToWatchCount; i++) { + let currentEntity = getCountyInfo(countiesToWatch[i]) + tieCounty(currentEntity,okToSaveChanges); + newStats.push(currentEntity); } + //console.log("Saving county info stats"); + const countyInfoStats = saveCountyInfoStats(newStats); + //Refresh the page when we are suposed to let interval = setInterval(reload, secondsBetweenReloads*1000); - }); + + + +