Browse Source

Added autologin functionality. WIP

main
Steven 1 year ago
parent
commit
8bbce42e41
  1. 107
      tampermonkey.js

107
tampermonkey.js

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @name AlwaysWin -ntsmhf // @name AlwaysWin-ntsmhf
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 0.1 // @version 0.1
// @description Make sure you are positioned where you want to be in the bidding for each county. // @description Make sure you are positioned where you want to be in the bidding for each county.
// @author Steven Allen // @author Steven Allen
// @match https://leads.needtosellmyhousefast.com/app // @match https://leads.needtosellmyhousefast.com/*
// @require https://code.jquery.com/jquery-3.7.1.min.js // @require https://code.jquery.com/jquery-3.7.1.min.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=needtosellmyhousefast.com // @icon https://www.google.com/s2/favicons?sz=64&domain=needtosellmyhousefast.com
// @grant none // @grant none
@ -19,7 +19,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, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300}; const defaultSettings = {"isReloadEnabled":true, "isAutoLoginEnabled":false, "minSecondsBetweenReloads": 60, "maxSecondsBetweenReloads":300};
const defaultSettingsString = JSON.stringify(defaultSettings); const defaultSettingsString = JSON.stringify(defaultSettings);
localStorage.setItem('alwayswin_settings',defaultSettingsString); localStorage.setItem('alwayswin_settings',defaultSettingsString);
alwaysWinSettingsString = defaultSettingsString; alwaysWinSettingsString = defaultSettingsString;
@ -37,11 +37,16 @@ function getRandomNumberBetween(min, max) {
return Math.floor(Math.random() * (max - min) + min); return Math.floor(Math.random() * (max - min) + min);
} }
function getCheckedValue() { function getCheckedValue(fieldName) {
if(reloadIsEnabled()) { switch (fieldName) {
return "checked"; case "isReloadEnabled":
return reloadIsEnabled() ? "checked": "";
case "isAutoLoginEnabled":
return autoLoginIsEnabled() ? "checked": "";
default:
return "";
} }
return; return "";
} }
function addAlwaysWinStyle(css) { function addAlwaysWinStyle(css) {
@ -56,11 +61,13 @@ function addAlwaysWinStyle(css) {
function saveSettings() { function saveSettings() {
let isReloadEnabledValue = document.querySelector("[name='isReloadEnabled']").checked; let isReloadEnabledValue = document.querySelector("[name='isReloadEnabled']").checked;
let isAutoLoginEnabledValue = document.querySelector("[name='isAutoLoginEnabled']").checked;
let minSecondsBetweenReloadsValue = document.querySelector("[name='minSecondsBetweenReloads']").value; let minSecondsBetweenReloadsValue = document.querySelector("[name='minSecondsBetweenReloads']").value;
let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value; let maxSecondsBetweenReloadsValue = document.querySelector("[name='maxSecondsBetweenReloads']").value;
const latestSettings = { const latestSettings = {
"isReloadEnabled": isReloadEnabledValue, "isReloadEnabled": isReloadEnabledValue,
"isAutoLoginEnabled": isAutoLoginEnabledValue,
"minSecondsBetweenReloads": minSecondsBetweenReloadsValue, "minSecondsBetweenReloads": minSecondsBetweenReloadsValue,
"maxSecondsBetweenReloads": maxSecondsBetweenReloadsValue "maxSecondsBetweenReloads": maxSecondsBetweenReloadsValue
}; };
@ -108,6 +115,13 @@ function reloadIsEnabled(){
return false; return false;
} }
function autoLoginIsEnabled(){
var checkedValue = alwaysWinSettings.isAutoLoginEnabled ?? false;
var retVal = (checkedValue == true);
return retVal;
}
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
// Always win code to find and take the highest/tie bid // Always win code to find and take the highest/tie bid
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
@ -169,11 +183,11 @@ function winCounty(countyJson, saveChanges) {
if(countyJson.clicksToMinWin == 0) { if(countyJson.clicksToMinWin == 0) {
//if we made it here no changes were needed to win by just the right amount //if we made it here no changes were needed to win by just the right amount
//Nothing else to do to win optimally //Nothing else to do to win optimally
console.log(countyInfo +" is already winning by just the right amount"); //console.log(countyInfo +" is already winning by just the right amount");
//awLog(countyInfo +" is already winning by just the right amount"); awLog(countyInfo +" is already winning by just the right amount");
} else if(countyJson.clicksToMinWin > 0) { } else if(countyJson.clicksToMinWin > 0) {
console.log(countyInfo +" is currently loosing. Increasing bid now"); //console.log(countyInfo +" is currently loosing. Increasing bid now");
//awLog(countyInfo +" is currently loosing. Increasing bid now"); awLog(countyInfo +" is currently loosing. Increasing bid now");
for(var i = 0; i < countyJson.clicksToMinWin; i++) { for(var i = 0; i < countyJson.clicksToMinWin; i++) {
console.log("calling btnBidUp.click() for "+ countyInfo); console.log("calling btnBidUp.click() for "+ countyInfo);
countyJson.btnBidUp.click(); countyJson.btnBidUp.click();
@ -183,8 +197,8 @@ function winCounty(countyJson, saveChanges) {
countyJson.btnSave.click(); countyJson.btnSave.click();
} }
} else if (countyJson.clicksToMinWin < 0) { } else if (countyJson.clicksToMinWin < 0) {
console.log(countyInfo +" is winning by too much. Decreasing bid now"); //console.log(countyInfo +" is winning by too much. Decreasing bid now");
//awLog(countyInfo +" is winning by too much. Decreasing bid now"); awLog(countyInfo +" is winning by too much. Decreasing bid now");
let clicksRemaining = Math.abs(countyJson.clicksToMinWin); let clicksRemaining = Math.abs(countyJson.clicksToMinWin);
while(clicksRemaining > 0) { while(clicksRemaining > 0) {
console.log("calling btnBidDown.click() for "+ countyInfo); console.log("calling btnBidDown.click() for "+ countyInfo);
@ -204,26 +218,74 @@ function tieCounty(countyJson, saveChanges) {
function awLog(message) { function awLog(message) {
console.log(message); console.log(message);
//const currentContent = document.getElementById("awLog").innerHTML; const currentContent = document.getElementById("awLog").innerHTML;
document.getElementById("awLog").innerHTML = currentContent + message; document.getElementById("awLog").innerHTML = currentContent +"<br/>"+ message;
} }
function loginIfNeeded(){
var div_signin = document.querySelector('.signin-box');
var loginIsNeeded = false;
if(div_signin != undefined && div_signin != null) {
loginIsNeeded = true;
if(!alwaysWinSettings.isAutoLoginEnabled) {
console.log("AutoLogin is turned off.");
awLog("AutoLogin is turned off.");
return loginIsNeeded;
}
console.log("A signin dialog exists");
const user = "xxx";
const pass = "xxx";
var txt_email = div_signin.querySelector("[id='email']");
var txt_password = div_signin.querySelector("[id='inputPassword']");
var btn_signin = div_signin.querySelector('.btn-signin'); //btn btn-primary btn-block btn-signin
txt_email.value = user;
txt_password.value = pass;
btn_signin.click();
}
return loginIsNeeded;
}
const sleep = ms => new Promise(res => setTimeout(res, ms))
jQuery(window).on('load',function() { jQuery(window).on('load',function() {
console.log("Page loaded at: "+ new Date()); console.log("Page loaded at: "+ new Date());
let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30; let minSecondsBetweenReloads = alwaysWinSettings.minSecondsBetweenReloads ?? 30;
let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 60; let maxSecondsBetweenReloads = alwaysWinSettings.maxSecondsBetweenReloads ?? 60;
let isReloadEnabled = alwaysWinSettings.isReloadEnabled ?? false; let isReloadEnabled = alwaysWinSettings.isReloadEnabled ?? false;
let isAutoLoginEnabled = alwaysWinSettings.isAutoLoginEnabled ?? false;
let secondsBetweenReloads = getRandomNumberBetween(minSecondsBetweenReloads, maxSecondsBetweenReloads); let secondsBetweenReloads = getRandomNumberBetween(minSecondsBetweenReloads, maxSecondsBetweenReloads);
console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds"); console.log("Next reload should occur in "+ secondsBetweenReloads +" seconds");
//Inject our controls //Inject our controls
var newHTML = document.createElement ('div'); var newDiv = document.createElement ('div');
newHTML.innerHTML = '<div id="alwaysWin-ntsmhf"><label for="isReloadEnabled">AlwaysWin:</label><input type="checkbox" name="isReloadEnabled" '+ getCheckedValue() +'/><br/><label for="minSecondsBetweenReloads">Reload Every</label>:<input id="minSecondsBetweenReloads" type="text" size="3" name="minSecondsBetweenReloads" value="'+minSecondsBetweenReloads+'" /> to <input id="maxSecondsBetweenReloads" type="text" size="3" name="maxSecondsBetweenReloads" value="'+maxSecondsBetweenReloads+'" /> seconds <br/><div id="reloaderData"><div id="countdown"></div><progress value="0" max="100" id="progressBar" style="width: 100%;"></progress></div><div id="awLog" style="width:100%; border-style:ridge; background-color:#FEFEFE;" ">Log:</div></div>'; var newHtml = '<div id="alwaysWin-ntsmhf">';
newHtml += '<input type="checkbox" name="isReloadEnabled" '+ getCheckedValue("isReloadEnabled") +'/><label for="isReloadEnabled">AlwaysWin</label> | ';
newHtml += '<input type="checkbox" name="isAutoLoginEnabled" '+ getCheckedValue("isAutoLoginEnabled") +'/><label for="isAutoLoginEnabled">Auto Login</label><br/>';
newHtml += '<label for="minSecondsBetweenReloads">Reload Every</label>:<input id="minSecondsBetweenReloads" type="text" size="3" name="minSecondsBetweenReloads" value="'+minSecondsBetweenReloads+'" /> to <input id="maxSecondsBetweenReloads" type="text" size="3" name="maxSecondsBetweenReloads" value="'+maxSecondsBetweenReloads+'" /> seconds <br/>';
newHtml += '<div id="reloaderData"><div id="countdown"></div><progress value="0" max="100" id="progressBar" style="width: 100%;"></progress></div><div id="awLog" style="width:100%; border-style:ridge; background-color:#FEFEFE;" ">Log:</div>';
newHtml += '</div>';
newDiv.innerHTML = newHtml;
addAlwaysWinStyle('#alwaysWin-ntsmhf { position: fixed; top: 0px; left: 0px; background-color: #DDDDDD; border-radius: 5px; padding:2px; box-shadow: 5px 5px 3px #777777;}'); addAlwaysWinStyle('#alwaysWin-ntsmhf { position: fixed; top: 0px; left: 0px; background-color: #DDDDDD; border-radius: 5px; padding:2px; box-shadow: 5px 5px 3px #777777;}');
document.body.appendChild (newHTML); document.body.appendChild (newDiv);
//Only run our code on certain pages
//console.log(window.location.pathname);
switch (window.location.pathname) {
case "/app":
case "/signin":
break;
default:
return;
}
//Are we logged in?
var logWasNeeded = loginIfNeeded();
if (logWasNeeded) {
return; //don't execute any more code until we are logged in.
}
//// Now do the winning //// Now do the winning
var countiesToWin = []; var countiesToWin = [];
@ -241,6 +303,7 @@ jQuery(window).on('load',function() {
let okToSaveChanges = true; let okToSaveChanges = true;
let countiesToWinCount = countiesToWin.length; let countiesToWinCount = countiesToWin.length;
awLog("Checking "+ countiesToWinCount +" countiesToWin");
for(let i = 0; i < countiesToWinCount; i++) { for(let i = 0; i < countiesToWinCount; i++) {
let currentEntity = getCountyInfo(countiesToWin[i]) let currentEntity = getCountyInfo(countiesToWin[i])
winCounty(currentEntity,okToSaveChanges); winCounty(currentEntity,okToSaveChanges);
@ -249,6 +312,7 @@ jQuery(window).on('load',function() {
okToSaveChanges = true; okToSaveChanges = true;
let countiesToTieCount = countiesToTie.length; let countiesToTieCount = countiesToTie.length;
awLog("Checking "+ countiesToTieCount +" countiesToTie");
for(let i = 0; i < countiesToTieCount; i++) { for(let i = 0; i < countiesToTieCount; i++) {
let currentEntity = getCountyInfo(countiesToTie[i]) let currentEntity = getCountyInfo(countiesToTie[i])
tieCounty(currentEntity,okToSaveChanges); tieCounty(currentEntity,okToSaveChanges);
@ -257,6 +321,7 @@ jQuery(window).on('load',function() {
okToSaveChanges = false; okToSaveChanges = false;
let countiesToWatchCount = countiesToWatch.length; let countiesToWatchCount = countiesToWatch.length;
awLog("Checking "+ countiesToWatchCount +" countiesToWatch");
for(let i = 0; i < countiesToWatchCount; i++) { for(let i = 0; i < countiesToWatchCount; i++) {
let currentEntity = getCountyInfo(countiesToWatch[i]) let currentEntity = getCountyInfo(countiesToWatch[i])
tieCounty(currentEntity,okToSaveChanges); tieCounty(currentEntity,okToSaveChanges);
@ -279,6 +344,4 @@ jQuery(window).on('load',function() {
} }
reloadTimeleft -= 1; reloadTimeleft -= 1;
}, 1000); }, 1000);
}); });
Loading…
Cancel
Save