Last active
March 21, 2025 06:00
-
-
Save Eibwen/08fab2f3fe2f10ca25ae96433c7ecc9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Ebay Motherufcker | |
// @namespace https://gist.github.com/Eibwen/ | |
// @version 0.5 | |
// @description Bid at the last moment | |
// @updateURL https://gist.github.com/Eibwen/08fab2f3fe2f10ca25ae96433c7ecc9b/raw/ebay-bid-sniper.user.js | |
// @author Greg Walker | |
// @match https://www.ebay.com/itm/* | |
// @grant none | |
// ==/UserScript== | |
const bidAtTimeMatch = [/*"7s", "6s",*/ "5s", "4s", "3s", "2s"]; // "9h 12m 45s" | |
var lastBidButtonState = {}; | |
const watchForBidButton = () => { | |
const buttonState = placeBidInOpenBidWindow(true); | |
//Hard code these properties since there are so few right now | |
if (lastBidButtonState === null | |
|| lastBidButtonState.bidButton !== buttonState.bidButton | |
|| lastBidButtonState.confirmButton !== buttonState.confirmButton | |
|| lastBidButtonState.mainBidButton !== buttonState.mainBidButton) { | |
console.log('Button state changed!'); | |
console.log(buttonState); | |
lastBidButtonState = buttonState; | |
} | |
else { | |
//console.log('No change'); | |
//console.log(lastBidButtonState); | |
} | |
} | |
(function() { | |
'use strict'; | |
console.log('Creating observer'); | |
const textElement = document.getElementById('vi-cdown_timeLeft'); | |
const triggerElement = document.getElementById('vi-time-wrapperSection'); | |
console.log(textElement); | |
if (triggerElement) { | |
//MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | |
var observer = new MutationObserver(function(mutations, observer) { | |
// fired when a mutation occurs | |
var text = textElement.innerText.trim(); | |
//console.log('DEBUG', `'${text}'`, `'${bidAtTimeMatch}'`); | |
console.log('mutation'); | |
if (bidAtTimeMatch.indexOf(text) >= 0) { | |
console.log("OMG BID NOW"); | |
placeBidInOpenBidWindow(); | |
} | |
}); | |
// define what element should be observed by the observer | |
// and what types of mutations trigger the callback | |
observer.observe(triggerElement, { | |
subtree: true, | |
attributes: true, // works at least once the text turns red | |
//characterData: true, | |
childList: true, // works on normal auction pages? | |
}); | |
triggerElement.style = `background-color: limegreen; | |
padding: 3px; | |
border-radius: 8px;`; | |
console.log('Created observer'); | |
console.log('Creating button searcher...'); | |
setInterval(watchForBidButton, 5000); | |
console.log('Created button searcher'); | |
} | |
else { | |
console.log('INFO: Auction countdown not found... doing nothing'); | |
} | |
})(); | |
let confirmButtonPushLoop = null; | |
const placeBidInOpenBidWindow = (onlyTest = false) => { | |
//const bidTimer = document.getElementById('_counter_itemEndDate'); | |
//TODO add a test functionality? where it checks the values that I care about... | |
// or maybe tell the user to put a LOW value, and then test that it errors on that | |
// BUT does this make it easier to develop or just more work for no benefits? | |
const output = {}; | |
//const bidAmountField = document.getElementById('MaxBidId'); | |
// This is the case of only clicking on the "Bid" button on the auction, then entering the value | |
// there shouldn't be a confirm stage, on this, but TODO TEST | |
const bidPromptButton = document.querySelector('.app-bidlayer-bidsection-custombid > button'); | |
if (bidPromptButton) { | |
output.bidButton = true; | |
if (!onlyTest) { | |
clearInterval(confirmButtonPushLoop); | |
console.log('Found bid button, pressing now!'); | |
bidPromptButton.click(); | |
} | |
} | |
// This case is if you enter the value in the main page, then it just shows a confirm button | |
const confirmButton = document.getElementById('confirm_button'); | |
if (confirmButton) { | |
output.confirmButton = true; | |
if (!onlyTest) { | |
clearInterval(confirmButtonPushLoop); | |
console.log('Found confirm button, pressing now!'); | |
confirmButton.click(); | |
} | |
} | |
//TODO this version is trying to smiplify the state to what already existed | |
// BUT it kinda looks like it made it more complicated | |
// Button on the main page, need to use this to avoid timeout issues | |
const bidMainButton = document.getElementById('bidBtn_btn'); | |
if (bidMainButton) { | |
const shouldOpenModal = !onlyTest | |
&& !confirmButtonPushLoop | |
&& !output.confirmButton | |
&& !output.bidButton; | |
//console.log(`shouldOpenModal = ${!onlyTest} && ${!confirmButtonPushLoop} && ${!output.confirmButton} && ${!output.bidButton}`); | |
output.mainBidButton = true; | |
//output.mainButtonVisible = isVisible(bidMainButton); | |
if (shouldOpenModal) { | |
console.log('Opening new bid prompt window...'); | |
bidMainButton.click(); | |
// wait for a time period, then push confirm | |
console.log('Waiting time to click confirm button...'); | |
confirmButtonPushLoop = setInterval(() => { | |
console.log('Confirm push loop'); | |
placeBidInOpenBidWindow(); | |
}, 200); | |
} | |
} | |
return output; | |
}; | |
//// https://stackoverflow.com/a/33456469/356218 | |
//function isVisible(elem) { | |
// return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment