|
// ==UserScript== |
|
// @name Кнопка симпатии в розыгрышах |
|
// @version 1.1.1 |
|
// @description Прям как хотел огузок |
|
// @author MALWARE |
|
// @match https://zelenka.guru/forums/contests* |
|
// @match https://lolz.guru/forums/contests* |
|
// @match https://lolz.live/forums/contests* |
|
// @grant none |
|
// @icon https://zelenka.guru/favicon.ico |
|
// ==/UserScript== |
|
|
|
function like(post_id, xftoken) { |
|
const r = new XMLHttpRequest(); |
|
r.open("POST", "https://lolz.live/posts/"+post_id+"/like?_xfNoRedirect=1&_xfToken="+xftoken+"&_xfResponseType=json"); |
|
r.send(); |
|
} |
|
|
|
(function() { |
|
'use strict'; |
|
const xftoken = document.querySelector('input[name="_xfToken"]').value; |
|
const discussionList = document.querySelector("div.discussionListItems"); |
|
const addLikeButton = function(discussionListItem) { |
|
const likeButtonElement = document.createElement("a"); |
|
likeButtonElement.className = "threadControl Tooltip OverlayTrigger far fa-heart"; |
|
likeButtonElement.addEventListener("click", function() { |
|
like(new URLSearchParams(new URL(discussionListItem.querySelector('a[data-cachedtitle="Пожаловаться"]').href).search).get("post_id"), xftoken); |
|
likeButtonElement.className = "threadControl Tooltip OverlayTrigger fa fa-heart"; |
|
XenForo.stackAlert('Симпатия поставлена!', 1000); |
|
}); |
|
try { |
|
discussionListItem.querySelector("span.controls").appendChild(likeButtonElement); |
|
} |
|
catch(e) { |
|
console.log(discussionListItem); |
|
console.log(e); |
|
} |
|
}; |
|
const discussionListItems = document.querySelectorAll("div.discussionListItem"); |
|
for (let i = 0; i < discussionListItems.length; i++) { |
|
addLikeButton(discussionListItems[i]); |
|
} |
|
const observer = new MutationObserver(function(mutations) { |
|
mutations.forEach(function(mutation) { |
|
if (mutation.type === "childList") { |
|
mutation.addedNodes.forEach(function(node) { |
|
if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains("discussionListItem")) { |
|
addLikeButton(node); |
|
} |
|
}); |
|
} |
|
}); |
|
}); |
|
observer.observe(document.body, { childList: true, subtree: true }); |
|
})(); |