-
Notifications
You must be signed in to change notification settings - Fork 0
/
yandexBot2.js
95 lines (89 loc) · 3.25 KB
/
yandexBot2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ==UserScript==
// @name Bot for Yandex
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author Arseny
// @match https://yandex.ru/*
// @match https://xn----7sbab5aqcbiddtdj1e1g.xn--p1ai/*
// @match https://crushdrummers.ru/*
// @grant none
// ==/UserScript==
function getRandom(min,max){
return Math.floor(Math.random()*(max-min)+min);
}
let btnNextPage = document.evaluate ("//a[@aria-label='Следующая страница']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
let pager = document.evaluate ("//span[@class='pager__item pager__item_current_yes pager__item_kind_page']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
let logo = document.evaluate ("//body/header/div/div/div/a[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
let text = document.getElementById('text');
let links = document.links;
let site = location.host;
if (location.host == "yandex.ru"){
let sites = {
"xn----7sbab5aqcbiddtdj1e1g.xn--p1ai":["Гобой","Саксофон","Валторна","Фагот","Флейта","Как звучит флейта","Скрипка"],
"crushdrummers.ru":["Барабанное шоу","Шоу барабанщиков москва","Заказать барабанное шоу"]
}
let submit = document.querySelector("button[type='submit']")
if (text != null){
site = Object.keys(sites)[getRandom(0,Object.keys(sites).length)];
let keywords = sites[site];
let keyword = keywords[getRandom(0,keywords.length)];
document.cookie = 'site='+site;
writeWord(keyword);
}
else {
site = getCookie('site');
}
getYandexPage();
}
else {
if (getRandom(0,100)>20){
let index = getRandom(0,links.length);
if(links[index].href.indexOf(site)!=-1 && links[index].href.indexOf('#')== -1 && links[index].href.indexOf('.jpg')== -1) {
setTimeout(()=>{links[index].click();}, getRandom(3000, 5000));
}
else location.href = `https://${site}/`;
}
else location.href = "https://yandex.ru";
}
function writeWord(keyword){
let i = 0;
let timerId = setInterval(()=>{
setTimeout(()=>{
text.value += keyword[i]==undefined?'':keyword[i];
i++;
if (i==keyword.length) {
clearInterval(timerId);
submit.click();
}
},getRandom(0,1000));
},300);
}
function getYandexPage() {
let goNextPage = true;
for (let i=0;i<links.length;i++){
if (links[i].href.indexOf(site) != -1){
let link = links[i];
setTimeout(()=>{link.scrollIntoView(true);},2000);
goNextPage = false;
links[i].removeAttribute('target');
setTimeout(()=>link.click(), getRandom(3000,5000));
break;
}
}
if (goNextPage) { setTimeout(()=>{
if (pager.singleNodeValue.innerText == "10") {
logo.singleNodeValue.click();
}
else {
btnNextPage.singleNodeValue.click()
};
}, getRandom(3000,10000));
}
}
function getCookie(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}