const isUserMessages = location.href.startsWith("https://forum.arizona-rp.com/search/") && document.querySelector("#top > div.p-body-header > div > div > div > h1") && document.querySelector("#top > div.p-body-header > div > div > div > h1").innerText === "Результаты поиска"
const csrf = document.querySelector("html").getAttribute('data-csrf')
function LikePage(gonext, errored, IDREACT) {
function getPosts() {
const posts = document.querySelectorAll("#top > div.p-body > div > div.uix_contentWrapper > div > div > div > div > div.block-container > ol > li > div > div > h3 > a")
if (!posts) return []
return Array.from(posts).map(e => {
const urlPost = /\/threads\/(\d+)\/post-(\d+)/
const urlProfilePost = /\/(profile-posts\/comments|profile-posts)\/(\d+)/
if (
urlPost.test(e.href)
) {
const [, thread, postId] = urlPost.exec(e.href)
return { type: "posts", id: postId }
}
if (
urlProfilePost.test(e.href)
) {
const [, type, postId] = urlProfilePost.exec(e.href)
return { type, id: postId }
}
return {}
})
}
function sendReact(typepost, postid, id = 1) {
const form = new FormData()
form.append("_xfToken", csrf)
form.append("reaction_id", id)
return fetch(`/${typepost}/${postid}/react`, {
method: "POST",
body: form
})
}
Promise.all(getPosts().map(
post => {
if (!post.id) return new Promise(res => res("negr"));
return sendReact(post.type, post.id, IDREACT).then(res => res !== "negr" ? res.text() : res).then(res => console.log(`[post] [react] [liked]`)).catch(err => console.error(`[post] [react error] ${err}`))
}
)).then(gonext).catch(errored)
}
function NextPage(lastpagecb) {
const nextbutton = document.querySelector("#top > div.p-body > div > div.uix_contentWrapper > div > div > div > div > div.block-outer.block-outer--after > div.block-outer-main > nav > div.pageNav > a.pageNav-jump.pageNav-jump--next")
const loadold = document.querySelector("#top > div.p-body > div > div.uix_contentWrapper > div > div > div > div > div.block-container > div > span > a")
if (nextbutton) return location.href = nextbutton.href
if (loadold) return location.href = loadold.href
return lastpagecb && lastpagecb()
}
(async a => {
if (isUserMessages) {
LikePage(() => NextPage(() => alert("Это последняя страница, работа бота окончена!\nНе забудьте выключить скрипт!")), () => console.error("бебра ошибка произошла при фетче..."), 2)
} else {
console.log("не страница сообщений пользователя!")
}
})(1)