From c4fb2953a86deec48a7ad8123139ce9e69822cb7 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 11 Dec 2023 15:20:23 -0800 Subject: [PATCH] Reformatted and Moved code around for readability --- README.md | 32 ++++++++------- tampermonkey.js | 106 +++++++++++++++++++++++++++--------------------- 2 files changed, 77 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 0bb75b5..9bc6707 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,23 @@ To load the Tampermonkey script: ## Wishlist / Todo ### Functionality For Release +- [X] Expose buildNumber to settings view +- [ ] Add verbage to settings div that we are happy to JV on creative deals (get verbage from carolina) - [X] Add this link to the settings div: https://leads.needtosellmyhousefast.com/qhrei (added this instead because it made more sense:https://info.qhrei.com/temp/alwayswin-ntsmhf/index.htm) - [X] Add donation/support message to div - [ ] Read from /app/subscriptions to get list of initial counties - if county is missing it automatically gets added. -- [x] Expose Sitewide bidcap (if any county bid exceeds X only bid up to X for that county) -- [x] Save button to persist changes (instead of waiting for refresh code to run) -- [x] Save settings to local storage -- [x] Retrieve settings from local storage -- [x] county bidcap - store and read from settings +- [X] Expose Sitewide bidcap (if any county bid exceeds X only bid up to X for that county) +- [X] Save button to persist changes (instead of waiting for refresh code to run) +- [X] Save settings to local storage +- [X] Retrieve settings from local storage +- [X] county bidcap - store and read from settings - [ ] county isBidCapEnabled - store and read from settings - [ ] use isBidCapEnabled when processing each oversight - [ ] use bidcap when processing each oversight - [ ] Implement tieCounty code - [ ] Implement watchCounty code -- [x] Add cap presidence setting. -- [x] Add Presidence option to settings div +- [X] Add cap presidence setting. +- [X] Add Presidence option to settings div *If a row and general cap are enabled then [options🔽] takes presidence.* ``` @@ -61,23 +63,23 @@ To load the Tampermonkey script: ### UI Settings -- [x] How often should the status check be performed? -- [x] randomize refresh value to avoid detection +- [X] How often should the status check be performed? +- [X] randomize refresh value to avoid detection ### UI Rows -- [x] "rowAction" dropdown with options: +- [X] "rowAction" dropdown with options: ``` 0 - Ignore/Hide = Make this row invisible. 1 - Win = Ensure I am highest bidder 2 - Tie = Make sure I am Tied 3 - Watch = Dont bid just monitor ``` -- [x] expose countyId, tie, margin/clicksToWin data +- [X] expose countyId, tie, margin/clicksToWin data - [ ] enable apply, enableBidcap, bidCap, action inputs and persist values the values at a row level -- [x] Store tie values for statistical analysis over time. -- [x] Auto login if on signin page -- [x] Add verticle scroll overflow to awLog div -- [x] Refactor injection and alwayswin array code in main +- [X] Store tie values for statistical analysis over time. +- [X] Auto login if on signin page +- [X] Add verticle scroll overflow to awLog div +- [X] Refactor injection and alwayswin array code in main - [ ] Bidcap input for row is only visible if cap is checked for row or settings bidcap is enabled. - [ ] Refactor Row injections layout to be: diff --git a/tampermonkey.js b/tampermonkey.js index 1953df1..f9b51d4 100644 --- a/tampermonkey.js +++ b/tampermonkey.js @@ -13,6 +13,7 @@ 'use strict'; +const buildNumber = 0.125; //Load our settings //localStorage.removeItem('alwayswin_settings'); const verboseLevel=0; @@ -129,7 +130,7 @@ function reload() { location.reload(); } -function reloadIsEnabled(){ +function reloadIsEnabled() { var checkedValue = alwaysWinSettings.isReloadEnabled ?? false;// document.querySelector("[name='isReloadEnabled']").checked; if(checkedValue == true) { return true; @@ -137,7 +138,7 @@ function reloadIsEnabled(){ return false; } -function autoLoginIsEnabled(){ +function autoLoginIsEnabled() { var checkedValue = alwaysWinSettings.isAutoLoginEnabled ?? false; var retVal = (checkedValue == true); return retVal; @@ -162,7 +163,7 @@ function getBidCapForCountyId(countyId) { //////////////////////////////////////////////////////////////////////////////////// // Always win code to find and take the highest/tie bid //////////////////////////////////////////////////////////////////////////////////// -function getCountyInfo(countyId){ +function getCountyInfo(countyId) { var county = document.querySelector('[data-subscription_id="'+ countyId +'"].subscription-status'); if(county === null) { console.log("county "+ countyId +" row not found"); @@ -278,11 +279,11 @@ function encryptAndStore(encryptionKey, clearText) { return JSON.stringify(sjcl.encrypt(encryptionKey, clearText)); } -function unStoreAndDecrypt (encryptionKey, jsonObj) { +function unStoreAndDecrypt(encryptionKey, jsonObj) { return sjcl.decrypt(encryptionKey, JSON.parse(jsonObj)); } -function loginIfNeeded(){ +function loginIfNeeded() { var div_signin = document.querySelector('.signin-box'); var loginIsNeeded = false; if(div_signin != undefined && div_signin != null) { @@ -773,22 +774,12 @@ function injectOversight(countyId, action) { targetContainer.appendChild(oversightPriceDiv); } - -const sleep = ms => new Promise(res => setTimeout(res, ms)) - -jQuery(window).on('load',function() { - console.log("Page loaded at: "+ new Date()); +function injectSettingsDiv() { let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30; let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 180; - let isReloadEnabled = alwaysWinSettings.isReloadEnabled ?? false; - let isAutoLoginEnabled = alwaysWinSettings.isAutoLoginEnabled ?? false; - let isGeneralCapEnabled = alwaysWinSettings.isGeneralCapEnabled ?? false; let capPresidence = alwaysWinSettings.capPresidence ?? "row"; let generalCap = alwaysWinSettings.generalCap ?? 500; - let secondsBetweenReloads = getRandomNumberBetween(minSecondsBetweenReloads, maxSecondsBetweenReloads); - //console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds"); - //Inject our controls var newDiv = document.createElement ('div'); var newHtml = '
'; newHtml += ' | '; @@ -800,14 +791,15 @@ jQuery(window).on('load',function() { newHtml += ' '; newHtml += '
'; newHtml += '
'; - newHtml += '
Note: The bidcap functionality is currently under development is not being applied to any bids at the moment.
'; + newHtml += '
Note: The bidcap functionality is currently under development and is NOT being applied to any bids at the moment no matter what any messages say. The current bid IS accurate.
'; newHtml += '
If you got any value out of this tool please feel free to show your support here: https://info.qhrei.com/tools/AlwaysWin-ntsmhf
'; - newHtml += '
v0.122
'; + newHtml += '
v'+ buildNumber +'
'; newHtml += '
'; newDiv.innerHTML = newHtml; + document.body.appendChild (newDiv); addAlwaysWinStyle('.alwaysWin-ntsmhf {position: fixed; width:400px; top: 0px; left: 0px; background-color: #DDDDDD; border-radius: 5px; padding:2px; box-shadow: 5px 5px 3px #777777;}'); addAlwaysWinStyle('.alwaysWin-ntsmhf .alwaysWinLog {float:left; width:100%; overflow-y: auto; height: 100px; font-size: 0.75em; border-style:ridge; background-color:#FEFEFE;}'); @@ -817,12 +809,55 @@ jQuery(window).on('load',function() { addAlwaysWinStyle('.alwaysWin-ntsmhf .alwaysWinSupport {border: thick double #999999; width:100%; color: #111111; background-color: #44DDDD; padding: 1px 2px; text-align: left; text-decoration: none; display: inline-block; font-size: 12px; margin: 1px 1px; cursor: no-drop;}'); addAlwaysWinStyle('.alwaysWin-ntsmhf .buildNumber {position: absolute; top: 0; right: 0; text-align: left; color: #111111; font-size: 8px; padding:2px; cursor: context-menu;}'); addAlwaysWinStyle('.alwaysWin-ntsmhf .alwaysWinThanks {border: thick double #999999; width:100%; color: #CCCCCC; background-color: #444444; text-align: left; text-decoration: none; display: inline-block; font-size: 12px; padding: 2px; border-radius: 5px;}'); +} +function calculateOversight() { + //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","win"); //clackamas, OR + //injectOversight("84038","watch"); //benton, OR + //injectOversight("87835","watch"); //multnomah, OR + //injectOversight("91976","win"); //CLARK, WA +} - document.body.appendChild (newDiv); - +function registerEventListeners() { const alwaysWinSave = document.getElementById("alwaysWin-ntsmhf-save"); alwaysWinSave.addEventListener("click", handleSaveSettings); + //TODO include overlays control event listers too? +} + +function reloadPageAsNeeded() { + let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30; + let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 180; + let secondsBetweenReloads = getRandomNumberBetween(minSecondsBetweenReloads, maxSecondsBetweenReloads); + //console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds"); + + var reloadTimeleft = secondsBetweenReloads; + var reloadTimer = setInterval(function() { + var countdownElement = document.getElementById("countdown"); + countdownElement.innerHTML = "Next reload will occur in "+ reloadTimeleft +" seconds."; + countdownElement.title = "Refesh timer started at "+secondsBetweenReloads+" seconds"; + var progressBarValue = 100 - Math.floor(100 * (reloadTimeleft / secondsBetweenReloads)); //Calculate percent complete + document.getElementById("progressBar").value = progressBarValue; + if(reloadTimeleft <= 0){ + clearInterval(reloadTimer); + document.getElementById("countdown").innerHTML = secondsBetweenReloads +" second reload timer exhausted"; + reload(); + } + reloadTimeleft -= 1; + }, 1000); +} + +jQuery(window).on('load',function() { + console.log("Page loaded at: "+ new Date()); + + //Inject our controls + injectSettingsDiv(); + + registerEventListeners(); //Only run our code on certain pages //console.log(window.location.pathname); @@ -837,23 +872,14 @@ jQuery(window).on('load',function() { } //Are we logged in? - var logWasNeeded = loginIfNeeded(); - if (logWasNeeded) { + if (loginIfNeeded()) { return; //don't execute any more code until we are logged in. } //Inject our bits into the page for oversight - //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","win"); //clackamas, OR - //injectOversight("84038","watch"); //benton, OR - //injectOversight("87835","watch"); //multnomah, OR - //injectOversight("91976","win"); //CLARK, WA + calculateOversight(); - //// Now do the work + //// Now do the work of updating bids as needed and displaying oversight info let newStats = []; let oversightCount = alwaysWinSettings.oversight.length; awLog("Checking "+ oversightCount +" counties"); @@ -885,18 +911,6 @@ jQuery(window).on('load',function() { const countyInfoStats = saveCountyInfoStats(newStats); //Start our ui feedback for the enduser - var reloadTimeleft = secondsBetweenReloads; - var reloadTimer = setInterval(function() { - var countdownElement = document.getElementById("countdown"); - countdownElement.innerHTML = "Next reload will occur in "+ reloadTimeleft +" seconds."; - countdownElement.title = "Refesh timer started at "+secondsBetweenReloads+" seconds"; - var progressBarValue = 100 - Math.floor(100 * (reloadTimeleft / secondsBetweenReloads)); //Calculate percent complete - document.getElementById("progressBar").value = progressBarValue; - if(reloadTimeleft <= 0){ - clearInterval(reloadTimer); - document.getElementById("countdown").innerHTML = secondsBetweenReloads +" second reload timer exhausted"; - reload(); - } - reloadTimeleft -= 1; - }, 1000); + reloadPageAsNeeded(); + }); \ No newline at end of file