Skip to content

Instantly share code, notes, and snippets.

@intelligenced
Last active April 27, 2022 09:22
Show Gist options
  • Save intelligenced/921ae2fdf317dda0a4e21e7e142ba561 to your computer and use it in GitHub Desktop.
Save intelligenced/921ae2fdf317dda0a4e21e7e142ba561 to your computer and use it in GitHub Desktop.
Cinema Bot
/ ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://www.cinema.mv/movie/310
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
var seats = [];
var showTimes = [];
var phone = [];
//------------BOOKING SETINGS--------------//
var ENABLEBOTBOOKING = false;
var numberOfShows = 1;
var withoutMidnight = false;
seats[0] = new Array (["F8", "F9","F10", "F11"]);
phone[0] = new Array([9898989]);
var named = "Name";
var email = "[email protected]";
var locationID = 1; //0 is male' //1 is hulhumale
//----------------------------------------//
(function() {
'use strict';
var locationName = "Male'";
if(locationID === 1){ locationName = "HulhuMale"; }
$('header').append('<h3> Name: ' + named + '. Email: ' + email + '. Location: ' + locationName + '. No of Shows: ' + numberOfShows + '. Without Midnight? : '+ withoutMidnight+'</h3>');
for (var t = 0; t < seats.length; t++) {
$('header').append('<h3> Seats: ' + seats[t] + '. Phone: ' + phone[t] + '</h3>');
}
var error = $('.error');
var movieName = $(".name")[0].innerText;
if (movieName !== ""){
console.log('movie available');
TelegramBotMessage(movieName);
GetID(locationID);
BookForShowTimes();
}
else
{
$('header').append('<h3> Movie not available! Will refresh in 30 seconds</h3>');
console.log('Movie not available! Will refresh in 30 seconds');
setTimeout(function(){
location.reload();
}, 30000);
}
})();
function GetID(locationId){
//h2 0 is male'
//h2 1 is hulhumale
var h2 = $("h2")[locationId].nextSibling;
var items = h2.getElementsByTagName("li");
var countOfShowTimes = 0;
for (var i = 0; i < items.length; i++) {
var atag = items[i].getElementsByTagName("a")[0];
var href = atag.href;
var id = href.substring(href.lastIndexOf('/') + 1);
var movieDate = items[i].getElementsByClassName("date")[0].innerText;
var movieTime = items[i].getElementsByClassName("time")[0].innerText;
if(numberOfShows !== countOfShowTimes && id !== ""){
if((withoutMidnight === true && movieTime !== "23:30") || withoutMidnight === false){
showTimes[countOfShowTimes] = new Array(id, movieDate, movieTime);
countOfShowTimes++;
}
}
}
$('header').append('<h3> Shows: ' + showTimes+ '</h3>');
}
function BookForShowTimes(){
var formCount = 1;
for (var s = 0, len = seats.length; s < len; s++) {
for (var i = 0; i < showTimes.length; i++) {
BookMovie(showTimes[i][0], seats[s], named, email, phone[s], showTimes[i][1], showTimes[i][2], formCount);
formCount++;
}
}
}
function BookMovie (id, seats, named, email, phone, date, time, formCount) {
var path = "http://www.cinema.mv/book/"+ id;
//var path = "http://localhost/"+ id;
var form = document.createElement("form");
form.setAttribute("method", "Post");
form.setAttribute("action", path);
form.setAttribute("id", "form"+formCount);
for (var i = 0, len = seats[0].length; i < len; i++) {
var seat = seats[0][i];
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "seat[" + i + "]");
hiddenField.setAttribute("value", seat);
form.appendChild(hiddenField);
}
var hiddenField2 = document.createElement("input");
hiddenField2.setAttribute("type", "hidden");
hiddenField2.setAttribute("name", "name");
hiddenField2.setAttribute("value", named);
form.appendChild(hiddenField2);
var hiddenField3 = document.createElement("input");
hiddenField3.setAttribute("type", "hidden");
hiddenField3.setAttribute("name", "email");
hiddenField3.setAttribute("value", email);
form.appendChild(hiddenField3);
var hiddenField4 = document.createElement("input");
hiddenField4.setAttribute("type", "hidden");
hiddenField4.setAttribute("name", "phone");
hiddenField4.setAttribute("value", phone);
form.appendChild(hiddenField4);
document.body.appendChild(form);
//console.log($("#form"+formCount));
if(ENABLEBOTBOOKING){
$.ajax({
type: 'POST',
url: $("#form"+formCount).attr("action"),
data: $("#form"+formCount).serialize(),
success: function(response) {
console.log('form submit success');
},
});
}
//alert('booked for: ' + named + '. phone: ' + phone + '. seats: ' + seats + '. date: ' + date + '. time: ' + time);
}
function TelegramBotMessage(movieName){
var message = movieName + " is available to book, hooray!";
var telUrl = "https://api.telegram.org/bot" +
"489383716:AAGe9YF9tTatl5A9sB4pjqrTrzw2XP6vWeU" +
"/sendMessage?chat_id=" +
"-1001128738997" +
"&text=" +
message;
$.ajax({
type: 'GET',
url: telUrl,
success: function(response) {
console.log('telegram bot message success');
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment