Raw Source
jasdkasdasdads / Автоматическое участие на форуме lolz

// ==UserScript==
// @name      Автоматическое участие на форуме lolz
// @namespace    https://vk.com/george.vetrov
// @version      0.6
// @description:ru  Автоматическое участие в розыгрышах на форуме lolz. Если розыгрышей, где пользователь может участвовать, не осталось, скрипт ждет определенное количество времени (timeDelay, 1000 единиц = 1 сек, по умолчанию указано 100000 единиц = 100 сек) и обновляет страницу, после чего повторно проверяет наличие розыгрышей. Для корректной работы скрипта следует перейти на форум в раздел розыгрышей (https://lolz.org/forums/contests/) и ждать. Скорость обработки каждого розыгрыша ≈1 участие в 2.5 сек. Благодаря ручному управлению всех событий, возможность отследить бота встроенными средствами форума исключается.
// @author       Respirant <respiranto@gmail.com>
// @include        http*://lolz.guru*/forums/contests/*
// @include        http*://lolz.guru*/threads/*
// @grant        none
// @license        MIT
// @updateURL   https://openuserjs.org/meta/Respirant/Автоматическое_участие_на_форуме_lolz.meta.js
// @downloadURL   https://openuserjs.org/install/Respirant/Автоматическое_участие_на_форуме_lolz.user.js
// @copyright   2019, Respirant (https://openuserjs.org/users/Respirant)
// ==/UserScript==
var timeDelay = 100000; //Время задержки перед цикличным обновлением страницы. 100000 единиц - 100 секунд (1000 единиц - 1 секунда).
var linkForum = document.location.protocol + "//" + window.location.hostname + "/"; //Ссылка на форум, генерируется автоматически
'use strict';
var timeFormat = (function() {
	function num(val) {
		val = Math.floor(val);
		return val < 10 ? '0' + val : val;
	}
	return function(ms /**number*/ ) {
		var sec = ms / 1000,
			hours = sec / 3600 % 24,
			minutes = sec / 60 % 60,
			seconds = sec % 60;
		return num(hours) + ":" + num(minutes) + ":" + num(seconds);
	};
})();

function sleep(ms) {
	ms += new Date().getTime();
	while(new Date() < ms) {}
}
window.onload = function() {
	if(!document.getElementsByClassName("lastPost listBlock")[0]) {




        let timerId = setTimeout(function tick() {
  $(document).scrollTop(99999999);
  timerId = setTimeout(tick, 2000); // (*)
}, 2000);

		document.getElementsByClassName("primaryContent")[0].innerHTML = "Отсутствуют темы для автоматического участия в розыгрышах.";
		setTimeout(function() {
			window.location.reload(1);
		}, timeDelay);
	}
	if(window.location.href.indexOf("forums/contests/") != -1) {
		document.getElementsByClassName("titleBar")[0].innerHTML = "Розыгрыши. Время задержки цикла - " + timeFormat(timeDelay) + " (ч:м:с).";
	}
	if(window.location.href.indexOf("forums/contests/") != -1 && document.getElementsByClassName("listBlock main PreviewTooltip")[0]) {
		setTimeout($(document).scrollTop($(document).height()), 500);
		if($('.discussionListItem--Wrapper:not(:has(i)):first a.listBlock').attr('href') === "undefined" || !$('.discussionListItem--Wrapper:not(:has(i)):first a.listBlock').attr('href') || $('.discussionListItem--Wrapper:not(:has(i)):first a.listBlock').attr('href') == "undefined") {
			document.getElementsByClassName("primaryContent")[0].innerHTML = "Отсутствуют темы для автоматического участия в розыгрышах.";
			setTimeout(function() {
				window.location.reload(1);
			}, timeDelay);
		} else {
			//setTimeout(document.location.href = document.getElementsByClassName("discussionListItem--Wrapper")[0].getElementsByClassName("listBlock main PreviewTooltip")[0], 1000);
			setTimeout(document.location.href = linkForum + $('.discussionListItem--Wrapper:not(:has(i)):first a.listBlock').attr('href'), 1000);
		}
	}
}
try {
	$(function() {
		sleep(1000);
		if(window.location.href.indexOf("lolz") != -1) {
			if(document.querySelector(".LztContest--Participate").classList.contains("marginBlock")) {
				grecaptcha.ready(function() {
					grecaptcha.execute('6LdAh8YUAAAAACraj__ZkvtB6l3ZDpa0AUNgaOLj', {
						action: 'Index'
					}).then(function(token) {
						console.log('insert');
						$('.Captcha--XenForo_ControllerPublic_Thread').prepend('<input type="hidden" name="g-recaptcha-response" class="captchaResponseInput" value="' + token + '">');
						sleep(100);
						setTimeout(document.getElementsByClassName("button primary marginBlock LztContest--Participate")[0].click(), 1000);
						sleep(2000);
						setTimeout(window.location.replace(linkForum + "forums/contests/"), 1000);
					});
				});
			}
		}
	});
} catch(err) {}