Last active
August 9, 2019 13:52
-
-
Save si294r/e3a37f7d48aed79a57e3af7c09a07a6e 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 Auto Spin Diruna Slot Machine | |
// @namespace https://diruna.org/slot_machine | |
// @version 0.4.6 | |
// @description Automate SPIN Diruna Slot Machine | |
// @author You | |
// @match https://diruna.org/slot_machine* | |
// @match https://oauth.telegram.org/embed/DirunaCommunityBot* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var _winnings = 0; // winnings of single spin | |
var _totalWinnings = 0; // total winnings | |
var _winningSymbols = []; // array of winning symbols | |
//var _audio = new Audio('sound/sound.mp3'); // init spin sound | |
//var _winAudio = new Audio('sound/win.wav'); // init win sound | |
var _glowTimer; // init glow timer - if win, the reel glows | |
var isRunningSpinNoAnimation = 'stop'; | |
var isTMautospin = false; | |
var html = `<div style="margin: 5px;"> | |
<button id="autospin-btn" style="display:none;"><b>AUTO SPIN</b></button> | |
<span>AUTO SPIN v0.4.6 : </span> | |
<span id="autospin-desc" style="display: inline-block; width: 150px;">...</span> | |
</div>`; | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function autospinSlot(status) { | |
if (status == 'stop') { | |
isTMautospin = false; | |
$('#autospin-desc').html('spin stopped'); | |
await sleep(15000); // tunggu 15 detik, supaya tidak di block | |
location.reload(); | |
return; | |
} | |
if (status == 'error') { | |
$('#autospin-desc').html('error... retrying...'); | |
await sleep(6000); // tunggu 6 detik sebelum coba lagi, supaya tidak di block | |
} | |
await sleep(1000); | |
while (isRunningSpinNoAnimation != 'stop') { | |
await sleep(500); | |
} | |
if (parseInt($('#credits').html()) < 1) { | |
$('#autospin-desc').html('...'); | |
return; | |
} | |
await sleep(500); | |
if (!$('#spin-btn').is(':disabled')) { | |
//$('#spin-btn').click(); | |
$('#autospin-desc').html('Spinning...'); | |
callSlotMachineSpin(); | |
} | |
} | |
async function spinNoAnimation(output) { | |
isRunningSpinNoAnimation = 'running'; | |
//$('#spin-btn').prop("disabled", true); // disable SPIN button | |
//$('.reel').addClass('active'); // add glow to reel | |
$('img.winning').removeClass('winning'); | |
$('#credits').html(output.Credits); // display remaining credits | |
$('#winnings').html('0'); // reset winnings to 0 for each spin | |
_winnings = output.Winnings; // assign to property values. | |
_totalWinnings = output.TotalWinnings | |
_winningSymbols = output.WinningSymbols; | |
//_audio.play(); // play the spin sound | |
//_audio.volume = 0.33; | |
var spinTime = 5000; // total spin time (ms) | |
await sleep(spinTime + 1000); | |
// show images | |
$('#symbol1').attr('src','/assets/slot/symbols/' + output.Symbol[output.Result[0]].image); | |
$('#symbol2').attr('src','/assets/slot/symbols/' + output.Symbol[output.Result[1]].image); | |
$('#symbol3').attr('src','/assets/slot/symbols/' + output.Symbol[output.Result[2]].image); | |
$('#winnings').html(_winnings); // display winnings | |
$('#total-winnings').html(_totalWinnings); // display total winnings | |
//_audio.pause(); // stop the audio | |
//_audio.currentTime = 0; // rewind audio to beginning | |
if (_winnings > 0) { // if it's a WIN! glow and play sound | |
//_winAudio.play(); | |
//_winAudio.volume = 0.33; | |
// method: glow effect for winning symbols | |
var wins = _winningSymbols; | |
if (wins[0] !== 'a') | |
$('#symbol1').addClass('winning'); | |
if (wins[1] !== 'a') | |
$('#symbol2').addClass('winning'); | |
if (wins[2] !== 'a') | |
$('#symbol3').addClass('winning'); | |
await sleep(1000); | |
} | |
else { // if it's not a win, stop glow. | |
$('.reel').removeClass('active'); | |
} | |
//$('#spin-btn').prop("disabled", false); // enable SPIN button | |
isRunningSpinNoAnimation = 'stop'; | |
} | |
function callSlotMachineSpin() { | |
$.get("/slot_machine/spin", function(output) { | |
spinNoAnimation(output); | |
}, "json"); | |
} | |
async function logoutSpin(value) { | |
await sleep(value); | |
location.href = '/slot_machine/logout'; | |
} | |
async function loginSpin() { | |
await sleep(5000); | |
document.getElementsByClassName('tgme_widget_login_button')[0].click(); | |
} | |
async function reloadPage(value) { | |
await sleep(value); | |
location.reload(); | |
} | |
if (typeof $ != 'undefined' && $('#slot') != null) { | |
$('#slot p:first').append(html); | |
$( document ).ajaxComplete(function(event, xhr, settings) { | |
console.log(xhr); | |
if (isTMautospin == false) { | |
return; | |
} | |
if (xhr.status == 403 || document.simulateSessionExpired == true) { | |
// asumsi session telegram expired.. | |
logoutSpin(10000); | |
} else if (document.simulateUnknownError == true) { | |
// unknown error, stop auto spin to prevent banned by server | |
autospinSlot('stop'); | |
} else if (xhr.status == 200 && typeof xhr.responseText == 'string' && xhr.responseText.search('TotalWinnings') > -1) { | |
// server normal, spin again... | |
autospinSlot(null); | |
//} else if (xhr.status == 200 && typeof xhr.responseText == 'string' && xhr.responseText.search('"type":"channel"') > -1) { | |
// ignore notify... | |
} else if (xhr.status == 502 || xhr.status == 500) { | |
// server overload, try again a few moment later... | |
autospinSlot('error'); | |
} else { | |
// unknown error, stop auto spin to prevent banned by server | |
autospinSlot('stop'); | |
} | |
}); | |
$('#autospin-btn').click(function(e) { | |
isTMautospin = true; | |
e.preventDefault(); | |
autospinSlot(); | |
}); | |
setTimeout(function(){ | |
$('#autospin-btn').click(); | |
}, 4000); | |
setInterval(function() { | |
if (isTMautospin) { | |
var message = 'auto spin ' + $('img[src*="https://t.me"]').parent().text().trim() + ' is running'; | |
console.log(message); | |
//$.get("http://165.22.57.31/notify.php?message=" + encodeURIComponent(message), function(output) { | |
//}, "json"); | |
} | |
}, 2*60000); | |
} else { | |
// jika page login, maka... | |
if (document.getElementsByClassName('tgme_widget_login_button').length > 0) { | |
loginSpin(); // coba login setelah 5 detik | |
} // jika error 502 | |
else if (document.body.innerText.search('502') > -1) { | |
logoutSpin(10000); // coba logoutSpin setelah 10 detik | |
} // kemungkinan lain : | |
else { | |
// - maintenis | |
// - error 500 // SCRIPT AKAN BERHENTI TOTAL | |
// | |
// coba reloadPage setelah 3 menit | |
reloadPage(3*60000); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment