|
|
@ -1,6 +1,6 @@ |
|
|
|
// ==UserScript==
|
|
|
|
// @name AlwaysWin-ntsmhf
|
|
|
|
// @namespace http://tampermonkey.net/
|
|
|
|
// @namespace https://git.qhrei.com/steven/alwayswin-ntsmhf/
|
|
|
|
// @version 0.1
|
|
|
|
// @description Make sure you are positioned where you want to be in the bidding for each county.
|
|
|
|
// @author Steven Allen
|
|
|
@ -132,6 +132,11 @@ function autoLoginIsEnabled(){ |
|
|
|
return retVal; |
|
|
|
} |
|
|
|
|
|
|
|
function getBidCap(countyId) { |
|
|
|
//Get the default bidcap from settings
|
|
|
|
var bidCap = alwaysWinSettings.bidCap; |
|
|
|
return bidCap; |
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Always win code to find and take the highest/tie bid
|
|
|
@ -148,8 +153,11 @@ function getCountyInfo(countyId){ |
|
|
|
//<button class="btn btn-outline-primary bid-controller-btn bid-controller-btn--increment" data-operation="increment" type="button"><i class="icon ion-plus-round"></i></button>
|
|
|
|
//<button class="btn btn-primary btn-sm bid-controller-btn bid-controller-btn--save" type="button" data-operation="save" disabled="disabled">Save</button>
|
|
|
|
//</div></div></td></tr>
|
|
|
|
|
|
|
|
var county = document.querySelector('[data-subscription_id="'+ countyId +'"].subscription-status') |
|
|
|
var county = document.querySelector('[data-subscription_id="'+ countyId +'"].subscription-status'); |
|
|
|
if(county === null) { |
|
|
|
console.log("county "+ countyId +" row not found"); |
|
|
|
return; |
|
|
|
} |
|
|
|
let countyRow = county.closest("tr"); |
|
|
|
let bidController = {}; |
|
|
|
bidController.countyRow = countyRow; |
|
|
@ -167,6 +175,11 @@ function getCountyInfo(countyId){ |
|
|
|
num_clicksToMinWin = (winGap + bidIncriment) / bidIncriment; |
|
|
|
} |
|
|
|
|
|
|
|
let num_bidCap = getBidCap(countyId); |
|
|
|
let num_clicksToBidCap = num_clicksToMinWin; |
|
|
|
|
|
|
|
let oversightAction = "win"; //TODO: implement oversight actions per county and persist
|
|
|
|
|
|
|
|
bidController.readTimestamp = new Date(); |
|
|
|
bidController.isEnabled = county.checked; |
|
|
|
bidController.id = county.dataset.subscription_id; |
|
|
@ -179,6 +192,9 @@ function getCountyInfo(countyId){ |
|
|
|
bidController.isWinning = (num_bid > num_tieBid); |
|
|
|
bidController.isWinningByTooMuch = (num_bid > num_winningBid); |
|
|
|
bidController.clicksToMinWin = num_clicksToMinWin; |
|
|
|
bidController.bidCap = num_bidCap; |
|
|
|
bidController.clicksToBidCap = num_clicksToBidCap; |
|
|
|
bidController.oversightAction = oversightAction; |
|
|
|
bidController.btnSave = countyRow.querySelector('.bid-controller-btn--save'); |
|
|
|
bidController.btnBidUp = countyRow.querySelector('.bid-controller-btn--increment'); |
|
|
|
bidController.btnBidDown = countyRow.querySelector('.bid-controller-btn--decrement'); |
|
|
@ -292,6 +308,65 @@ function loginIfNeeded(){ |
|
|
|
return loginIsNeeded; |
|
|
|
} |
|
|
|
|
|
|
|
function renderOption(value, selectedValue) { |
|
|
|
var optionHtml = '<option value="'+ value +'"'; |
|
|
|
if(value == selectedValue) { |
|
|
|
optionHtml += ' selected'; |
|
|
|
} |
|
|
|
optionHtml += '>'+ value +'</option>'; |
|
|
|
return optionHtml; |
|
|
|
} |
|
|
|
|
|
|
|
function getOversightOptions(countyId, selectedAction) { |
|
|
|
var optionsHtml = ""; |
|
|
|
optionsHtml += renderOption("win", selectedAction); |
|
|
|
optionsHtml += renderOption("tie", selectedAction); |
|
|
|
optionsHtml += renderOption("watch",selectedAction); |
|
|
|
optionsHtml += renderOption("ignore",selectedAction); |
|
|
|
return optionsHtml; |
|
|
|
} |
|
|
|
|
|
|
|
function injectOversight(countyId, action) { |
|
|
|
countyId += ""; //cast into string incase number was passed in
|
|
|
|
//console.log("injecting oversight into county "+countyId);
|
|
|
|
var countyJson = getCountyInfo(countyId); |
|
|
|
countyJson.oversightAction = action; //TODO stop overwriting this and have getCountyInfo read the stored value.
|
|
|
|
if(countyJson === null || countyJson === undefined) { |
|
|
|
console.log(" could not find the county row "+countyId); |
|
|
|
return; |
|
|
|
} |
|
|
|
let countyRow = countyJson.countyRow; |
|
|
|
|
|
|
|
var oversightCountyDiv = document.createElement('div'); |
|
|
|
oversightCountyDiv.id = "oversight-county-"+countyId; |
|
|
|
oversightCountyDiv.style = "border: 1px dotted gray; padding: 0; margin: 0; font-size: 12px; overflow-x: visible"; |
|
|
|
|
|
|
|
var countyDivHtml =''; |
|
|
|
countyDivHtml += ''+ countyJson.id +''; |
|
|
|
countyDivHtml += ' | <label>tie:'+ countyJson.tieBid +'</label>'; |
|
|
|
countyDivHtml += ' | <label>margin:'+ countyJson.clicksToMinWin +'</label>'; |
|
|
|
|
|
|
|
oversightCountyDiv.innerHTML = countyDivHtml; |
|
|
|
var targetContainerCounty = countyRow.firstElementChild; |
|
|
|
targetContainerCounty.appendChild(oversightCountyDiv); |
|
|
|
|
|
|
|
|
|
|
|
var oversightPriceDiv = document.createElement('div'); |
|
|
|
oversightPriceDiv.id = "oversight-price-"+countyId; |
|
|
|
oversightPriceDiv.style = "border: 1px dotted gray; padding: 0; margin: 0; font-size: 12px; overflow-x: visible"; |
|
|
|
|
|
|
|
var priceDivHtml =''; |
|
|
|
//priceDivHtml += ''+ countyJson.id +'';
|
|
|
|
priceDivHtml += '<label><input disabled type="checkbox" style="transform:scale(.5);" name="enableBidCap-'+countyId+'" />cap:<input disabled type="text" name="bidCap-'+ countyId +'" id="bidCap-'+ countyId +'" style="font-size:10px; width:40px; height:12px;" value="'+ countyJson.bidCap +'" /></label>'; |
|
|
|
priceDivHtml += ' | <label for="oversightAction-'+countyId+'">act:</label><select disabled name="oversightAction-'+ countyId +'" id="oversightAction-'+ countyId +'">'+ getOversightOptions(countyId, countyJson.oversightAction) +'</select>'; |
|
|
|
priceDivHtml += '<button disabled id="oversightSave-'+countyId+'" style="font-size:9px;background-color:#aaaaaa;color:#FFFFFF;padding:1px;border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px;margin:0px;">Apply</button>'; |
|
|
|
oversightPriceDiv.innerHTML = priceDivHtml; |
|
|
|
|
|
|
|
var targetContainer = countyRow.lastElementChild; |
|
|
|
targetContainer.appendChild(oversightPriceDiv); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const sleep = ms => new Promise(res => setTimeout(res, ms)) |
|
|
|
|
|
|
|
jQuery(window).on('load',function() { |
|
|
@ -344,6 +419,13 @@ jQuery(window).on('load',function() { |
|
|
|
return; //don't execute any more code until we are logged in.
|
|
|
|
} |
|
|
|
|
|
|
|
//Inject our bits into the page for oversight
|
|
|
|
injectOversight("84035","win"); //washington, OR
|
|
|
|
injectOversight("87833","win"); //marion, OR
|
|
|
|
injectOversight("84034","tie"); //cascade, MT
|
|
|
|
injectOversight("84037","watch"); //clackamas, OR
|
|
|
|
injectOversight("84038","watch"); //benton, OR
|
|
|
|
|
|
|
|
//// Now do the winning
|
|
|
|
var countiesToWin = []; |
|
|
|
countiesToWin.push("84035"); //washington, OR
|
|
|
|