Skip to content

Instantly share code, notes, and snippets.

@sdennler
Last active October 12, 2023 13:37
Show Gist options
  • Save sdennler/49ca431b9b5c5b72ef0d to your computer and use it in GitHub Desktop.
Save sdennler/49ca431b9b5c5b72ef0d to your computer and use it in GitHub Desktop.
Script to win the GeoCacher Lotto for the Chancenlos GeoCaches GC3JN6W, GC3JN7G, GC3JN84 and GC3JN8J
// ==UserScript==
// @name Chancenlos GeoCacher Lotto Gambler
// @namespace https://gist.github.com/sdennler/
// @version 10
// @description Script to win the GeoCacher Lotto for the Chancenlos GeoCaches GC3JN6W, GC3JN7G, GC3JN84 and GC3JN8J
// @author Sdennler
// @match https://www.navikatzen.com/lotto_neu/*
// @exclude *winner.php*
// @grant none
// ==/UserScript==
var minHit = 6;
var timeout = randomIntFromInterval(2000, 5000); 3000;
var controlTimeout = 30000;
var hit = 0;
var initialCount = 0;
var lottoURL = 'https://www.navikatzen.com/lotto_neu/';
// Makre sure popups are not blocked in the browser!
console.log('Chancenlos GeoCacher Lotto Gambler whit minHit: '+minHit+' timeout: '+timeout+' stopped: '+localStorage.stop);
console.log('Running on '+location.href);
switch(true) {
case /refresh.html/.test(location.href):
location.href = lottoURL;
break;
case !inFrame():
startControl();
break;
default:
startGambling();
if(localStorage.stop != 'yes') doGambling();
else console.log('Gambling is stopped');
break;
}
var controlFrame, controlButton, lastControlTries = -1;
function randomIntFromInterval(min, max){
return Math.floor(Math.random()*(max-min+1)+min);
}
function inFrame () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
function startControl(){
console.log('Starting Control Frame');
document.body.innerHTML = '';
document.body.style.margin = 0;
controlFrame = document.createElement('iframe');
controlFrame.src = window.location.href;
controlFrame.width = window.innerWidth;
controlFrame.height = window.innerHeight - 60;
controlFrame.style.borderWidth = 0;
document.body.appendChild(controlFrame);
controlButton = document.createElement('button');
controlButton.innerHTML = 'Stop';
controlButton.style.margin = 5;
controlButton.onclick = doControlStartStop;
document.body.appendChild(controlButton);
doControl();
}
function doControl(){
if(typeof lastControlTries === 'undefined') lastControlTries = -1;
console.log('Controling... '+lastControlTries+' - '+localStorage.tries+' stopped: '+localStorage.stop);
if(lastControlTries == localStorage.tries) {
console.log('Gambling again');
controlFrame.window.stop();
controlFrame.src = lottoURL;
}
lastControlTries = localStorage.tries;
if(localStorage.stop != 'yes') setTimeout(doControl, controlTimeout);
}
function doControlStartStop(){
if(localStorage.stop == 'yes'){
localStorage.stop = 'no';
doControl();
controlButton.innerHTML = 'Stop';
}
else {
localStorage.stop = 'yes';
controlButton.innerHTML = 'Start';
}
}
function ClickTheButton(obj) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cancelled = !obj.dispatchEvent(evt);
console.log('clicked');
/*
if(cancelled) {
// A handler called preventDefault
alert("cancelled");
} else {
// None of the handlers called preventDefault
alert("not cancelled");
}
*/
}
function ClickTheButtonIfExists(buttonName){
var button = document.querySelector('input[type="submit"][name="'+buttonName+'"]');
if(button) setTimeout(ClickTheButton, timeout, button);
}
function startGambling(){
// Set win notification level
var messageFrom = document.getElementById('popup');
if(messageFrom) {
if(minHit >= 3 && minHit <=6) messageFrom.value = minHit;
}
// Counting
if(localStorage.allTries == undefined) localStorage.allTries = initialCount;
if(localStorage.tries == undefined) localStorage.tries = 0;
var tryCount = document.querySelector('body > center > table > tbody > tr:nth-child(16) > td > div > strong > font:nth-child(2)');
if(tryCount){
var tries = Number(tryCount.innerHTML) || 0;
if(Number(localStorage.tries) > tries){
localStorage.allTries = Number(localStorage.allTries) + Number(localStorage.tries);
}
localStorage.tries = tries;
console.log("This is try "+tries+" of this session and you made "+localStorage.allTries+" tries before.");
tryCount.innerHTML += ' + '+localStorage.allTries;
}
// Checking
var hitString = document.querySelector('#Layer1 > form > p > b');
if(hitString){
hit = hitString.innerHTML.match(/^Du hast (\d) Treffer gelandet!$/)[1];
// Save password
var passwordScript = document.querySelector('form > script');
if(passwordScript) {
if(localStorage.passwords == undefined) var passwords = {};
else var passwords = JSON.parse(localStorage.passwords);
passwords[new Date().toISOString()] = passwordScript.innerHTML.match(/'(.*?)'/)[1];
localStorage.passwords = JSON.stringify(passwords);
console.log(passwords);
}
}
}
function doGambling(){
// Clicking
if(hit < minHit){
console.log('try to load next');
var buttons = ['kukukrandom', 'botschutz', 'makroschutz'];
buttons.map(ClickTheButtonIfExists);
}
}
@sbec67
Copy link

sbec67 commented Dec 6, 2016

Hi,
I face the following Pbl.
in FF with GreasyMonkey 3.9 i get Message
"Chancenlos GeoCacher Lotto Gambler whit minHit: 6 timeout: 7605 stopped: no" ChancenlosGeoCacherLottoGambler.user.js:21:0
"Running on http://gahq.hopto.org/lotto/lotto.php" ChancenlosGeoCacherLottoGambler.user.js:22:0
"Starting Control Frame" ChancenlosGeoCacherLottoGambler.user.js:55:4
"Controling... -1 - undefined stopped: no"
It doesnt start to gamble
nothing else... where do i have a Problem ?

Regards

@Gruemscheler
Copy link

I have no experience with Javascript and would like to familiarize myself with it. I'm looking for a way to determine the 6 lottery numbers myself because I think the chance of a higher hit is greater if you always play the same numbers.
I guess you have to do this in the function ClickTheButton. Is that correct?

@sdennler
Copy link
Author

sdennler commented Oct 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment