Browse Source

Reformatted and Moved code around for readability

main
Steven 1 year ago
parent
commit
c4fb2953a8
  1. 32
      README.md
  2. 106
      tampermonkey.js

32
README.md

@ -9,21 +9,23 @@ To load the Tampermonkey script:
## Wishlist / Todo ## Wishlist / Todo
### Functionality For Release ### 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 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 - [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. - [ ] 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] 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 button to persist changes (instead of waiting for refresh code to run)
- [x] Save settings to local storage - [X] Save settings to local storage
- [x] Retrieve settings from local storage - [X] Retrieve settings from local storage
- [x] county bidcap - store and read from settings - [X] county bidcap - store and read from settings
- [ ] county isBidCapEnabled - store and read from settings - [ ] county isBidCapEnabled - store and read from settings
- [ ] use isBidCapEnabled when processing each oversight - [ ] use isBidCapEnabled when processing each oversight
- [ ] use bidcap when processing each oversight - [ ] use bidcap when processing each oversight
- [ ] Implement tieCounty code - [ ] Implement tieCounty code
- [ ] Implement watchCounty code - [ ] Implement watchCounty code
- [x] Add cap presidence setting. - [X] Add cap presidence setting.
- [x] Add Presidence option to settings div - [X] Add Presidence option to settings div
*If a row and general cap are enabled then [options🔽] takes presidence.* *If a row and general cap are enabled then [options🔽] takes presidence.*
``` ```
@ -61,23 +63,23 @@ To load the Tampermonkey script:
### UI Settings ### UI Settings
- [x] How often should the status check be performed? - [X] How often should the status check be performed?
- [x] randomize refresh value to avoid detection - [X] randomize refresh value to avoid detection
### UI Rows ### UI Rows
- [x] "rowAction" dropdown with options: - [X] "rowAction" dropdown with options:
``` ```
0 - Ignore/Hide = Make this row invisible. 0 - Ignore/Hide = Make this row invisible.
1 - Win = Ensure I am highest bidder 1 - Win = Ensure I am highest bidder
2 - Tie = Make sure I am Tied 2 - Tie = Make sure I am Tied
3 - Watch = Dont bid just monitor 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 - [ ] 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] Store tie values for statistical analysis over time.
- [x] Auto login if on signin page - [X] Auto login if on signin page
- [x] Add verticle scroll overflow to awLog div - [X] Add verticle scroll overflow to awLog div
- [x] Refactor injection and alwayswin array code in main - [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. - [ ] Bidcap input for row is only visible if cap is checked for row or settings bidcap is enabled.
- [ ] Refactor Row injections layout to be: - [ ] Refactor Row injections layout to be:

106
tampermonkey.js

@ -13,6 +13,7 @@
'use strict'; 'use strict';
const buildNumber = 0.125;
//Load our settings //Load our settings
//localStorage.removeItem('alwayswin_settings'); //localStorage.removeItem('alwayswin_settings');
const verboseLevel=0; const verboseLevel=0;
@ -129,7 +130,7 @@ function reload() {
location.reload(); location.reload();
} }
function reloadIsEnabled(){ function reloadIsEnabled() {
var checkedValue = alwaysWinSettings.isReloadEnabled ?? false;// document.querySelector("[name='isReloadEnabled']").checked; var checkedValue = alwaysWinSettings.isReloadEnabled ?? false;// document.querySelector("[name='isReloadEnabled']").checked;
if(checkedValue == true) { if(checkedValue == true) {
return true; return true;
@ -137,7 +138,7 @@ function reloadIsEnabled(){
return false; return false;
} }
function autoLoginIsEnabled(){ function autoLoginIsEnabled() {
var checkedValue = alwaysWinSettings.isAutoLoginEnabled ?? false; var checkedValue = alwaysWinSettings.isAutoLoginEnabled ?? false;
var retVal = (checkedValue == true); var retVal = (checkedValue == true);
return retVal; return retVal;
@ -162,7 +163,7 @@ function getBidCapForCountyId(countyId) {
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
// Always win code to find and take the highest/tie bid // 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'); var county = document.querySelector('[data-subscription_id="'+ countyId +'"].subscription-status');
if(county === null) { if(county === null) {
console.log("county "+ countyId +" row not found"); console.log("county "+ countyId +" row not found");
@ -278,11 +279,11 @@ function encryptAndStore(encryptionKey, clearText) {
return JSON.stringify(sjcl.encrypt(encryptionKey, clearText)); return JSON.stringify(sjcl.encrypt(encryptionKey, clearText));
} }
function unStoreAndDecrypt (encryptionKey, jsonObj) { function unStoreAndDecrypt(encryptionKey, jsonObj) {
return sjcl.decrypt(encryptionKey, JSON.parse(jsonObj)); return sjcl.decrypt(encryptionKey, JSON.parse(jsonObj));
} }
function loginIfNeeded(){ function loginIfNeeded() {
var div_signin = document.querySelector('.signin-box'); var div_signin = document.querySelector('.signin-box');
var loginIsNeeded = false; var loginIsNeeded = false;
if(div_signin != undefined && div_signin != null) { if(div_signin != undefined && div_signin != null) {
@ -773,22 +774,12 @@ function injectOversight(countyId, action) {
targetContainer.appendChild(oversightPriceDiv); targetContainer.appendChild(oversightPriceDiv);
} }
function injectSettingsDiv() {
const sleep = ms => new Promise(res => setTimeout(res, ms))
jQuery(window).on('load',function() {
console.log("Page loaded at: "+ new Date());
let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30; let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30;
let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 180; 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 capPresidence = alwaysWinSettings.capPresidence ?? "row";
let generalCap = alwaysWinSettings.generalCap ?? 500; 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 newDiv = document.createElement ('div');
var newHtml = '<div class="alwaysWin-ntsmhf" id="alwaysWin-ntsmhf">'; var newHtml = '<div class="alwaysWin-ntsmhf" id="alwaysWin-ntsmhf">';
newHtml += '<input type="checkbox" name="isAutoLoginEnabled" '+ getCheckedValue("isAutoLoginEnabled") +'/><label for="isAutoLoginEnabled">Auto Login</label> | '; newHtml += '<input type="checkbox" name="isAutoLoginEnabled" '+ getCheckedValue("isAutoLoginEnabled") +'/><label for="isAutoLoginEnabled">Auto Login</label> | ';
@ -800,14 +791,15 @@ jQuery(window).on('load',function() {
newHtml += '<label for="generalCap">:</label><input id="generalCap" type="text" size="2" name="generalCap" value="'+ generalCap+'" title="Don&apos;t bid more than this amount per county" /> '; newHtml += '<label for="generalCap">:</label><input id="generalCap" type="text" size="2" name="generalCap" value="'+ generalCap+'" title="Don&apos;t bid more than this amount per county" /> ';
newHtml += '<label for="capPresidence" title="If a row cap and general cap are both enabled..."> presidence:</label><select id="capPresidence" name="capPresidence" title="This takes presidence over any caps that may exist." />'+ getCapPresidenceOptions(capPresidence) +'</select><br/>'; newHtml += '<label for="capPresidence" title="If a row cap and general cap are both enabled..."> presidence:</label><select id="capPresidence" name="capPresidence" title="This takes presidence over any caps that may exist." />'+ getCapPresidenceOptions(capPresidence) +'</select><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"></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 id="support" class="alwaysWinSupport">Note: The bidcap functionality is currently under development is not being applied to any bids at the moment.</div>'; newHtml += '<div id="support" class="alwaysWinSupport">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.</div>';
newHtml += '<div id="alwaysWinThanks" class="alwaysWinThanks">If you got any value out of this tool please feel free to show your support here: <a href="https://info.qhrei.com/temp/alwayswin-ntsmhf/index.htm" target="_blank">https://info.qhrei.com/tools/AlwaysWin-ntsmhf</a></div>'; newHtml += '<div id="alwaysWinThanks" class="alwaysWinThanks">If you got any value out of this tool please feel free to show your support here: <a href="https://info.qhrei.com/temp/alwayswin-ntsmhf/index.htm" target="_blank">https://info.qhrei.com/tools/AlwaysWin-ntsmhf</a></div>';
newHtml += '<div id="buildNumber" class="buildNumber">v0.122</div>'; newHtml += '<div id="buildNumber" class="buildNumber">v'+ buildNumber +'</div>';
newHtml += '</div>'; newHtml += '</div>';
newDiv.innerHTML = 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 {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;}'); 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 .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 .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;}'); 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"); const alwaysWinSave = document.getElementById("alwaysWin-ntsmhf-save");
alwaysWinSave.addEventListener("click", handleSaveSettings); 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 //Only run our code on certain pages
//console.log(window.location.pathname); //console.log(window.location.pathname);
@ -837,23 +872,14 @@ jQuery(window).on('load',function() {
} }
//Are we logged in? //Are we logged in?
var logWasNeeded = loginIfNeeded(); if (loginIfNeeded()) {
if (logWasNeeded) {
return; //don't execute any more code until we are logged in. return; //don't execute any more code until we are logged in.
} }
//Inject our bits into the page for oversight //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) calculateOversight();
// 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
//// Now do the work //// Now do the work of updating bids as needed and displaying oversight info
let newStats = []; let newStats = [];
let oversightCount = alwaysWinSettings.oversight.length; let oversightCount = alwaysWinSettings.oversight.length;
awLog("Checking "+ oversightCount +" counties"); awLog("Checking "+ oversightCount +" counties");
@ -885,18 +911,6 @@ jQuery(window).on('load',function() {
const countyInfoStats = saveCountyInfoStats(newStats); const countyInfoStats = saveCountyInfoStats(newStats);
//Start our ui feedback for the enduser //Start our ui feedback for the enduser
var reloadTimeleft = secondsBetweenReloads; reloadPageAsNeeded();
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);
}); });
Loading…
Cancel
Save