Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const plebbit = `<span name="upvote" class="flex mx-xs text-16">
- <!--?lit$622545441$--><svg rpl="" fill="currentColor" height="16" icon-name="upvote-outline" viewBox="0 0 20 20" width="16" xmlns="http://www.w3.org/2000/svg">
- <!--?lit$622545441$--><!--?lit$622545441$--><path d="M10 19c-.072 0-.145 0-.218-.006A4.1 4.1 0 0 1 6 14.816V11H2.862a1.751 1.751 0 0 1-1.234-2.993L9.41.28a.836.836 0 0 1 1.18 0l7.782 7.727A1.751 1.751 0 0 1 17.139 11H14v3.882a4.134 4.134 0 0 1-.854 2.592A3.99 3.99 0 0 1 10 19Zm0-17.193L2.685 9.071a.251.251 0 0 0 .177.429H7.5v5.316A2.63 2.63 0 0 0 9.864 17.5a2.441 2.441 0 0 0 1.856-.682A2.478 2.478 0 0 0 12.5 15V9.5h4.639a.25.25 0 0 0 .176-.429L10 1.807Z"></path><!--?-->
- </svg>
- </span><span name="votes">Loading...</span><span name="downvote" class="flex mx-xs text-16">
- <!--?lit$622545441$--><svg rpl="" fill="currentColor" height="16" icon-name="downvote-outline" viewBox="0 0 20 20" width="16" xmlns="http://www.w3.org/2000/svg">
- <!--?lit$622545441$--><!--?lit$622545441$--><path d="M10 1c.072 0 .145 0 .218.006A4.1 4.1 0 0 1 14 5.184V9h3.138a1.751 1.751 0 0 1 1.234 2.993L10.59 19.72a.836.836 0 0 1-1.18 0l-7.782-7.727A1.751 1.751 0 0 1 2.861 9H6V5.118a4.134 4.134 0 0 1 .854-2.592A3.99 3.99 0 0 1 10 1Zm0 17.193 7.315-7.264a.251.251 0 0 0-.177-.429H12.5V5.184A2.631 2.631 0 0 0 10.136 2.5a2.441 2.441 0 0 0-1.856.682A2.478 2.478 0 0 0 7.5 5v5.5H2.861a.251.251 0 0 0-.176.429L10 18.193Z"></path><!--?-->
- </svg>
- </span>`;
- const ThreadsWithPlebbitBar = [];
- const PostsWithPlebbitBar = [];
- function GetElementByXpath(path) {
- return document.evaluate(
- path,
- document,
- null,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null
- ).singleNodeValue;
- }
- function CreateRandomString(length) {
- const chars =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- let result = "";
- for (let i = 0; i < length; i++) {
- result += chars.charAt(Math.floor(Math.random() * chars.length));
- }
- return result;
- }
- async function AddRedditBar(post, postOrReply) {
- if (postOrReply === "thread") {
- ThreadsWithPlebbitBar.push(post);
- } else if (postOrReply === "reply") {
- PostsWithPlebbitBar.push(post);
- }
- const intro = post.getElementsByClassName("intro")[0];
- const plebbitElement = document.createElement("span");
- plebbitElement.name = "reddit";
- plebbitElement.innerHTML = plebbit;
- intro.appendChild(plebbitElement);
- const downvote = plebbitElement.querySelector("[name=downvote]");
- downvote.onclick = () => {
- const postReply = GetElementByXpath(
- "/html/body/form[1]/table/tbody/tr[1]/td/input[2]"
- );
- if (postReply.value !== "New Reply") {
- alert(
- "to downvote a thread/reply you need to enter the thread then press downvote"
- );
- } else {
- if (postOrReply === "reply") {
- GetElementByXpath('//*[@id="body"]').value =
- intro.getElementsByClassName("post_no")[1].textContent +
- "\nYour downvote, xir.\n" +
- CreateRandomString(6);
- } else {
- GetElementByXpath(
- "/html/body/form[1]/table/tbody/tr[1]/td/input[1]"
- ).value = "sage";
- GetElementByXpath('//*[@id="body"]').value =
- "Your downvote, xir.\n" + CreateRandomString(6);
- }
- scrollTo(0, 0);
- }
- };
- const upvote = plebbitElement.querySelector("[name=upvote]");
- upvote.onclick = () => {
- const postReply = GetElementByXpath(
- "/html/body/form[1]/table/tbody/tr[1]/td/input[2]"
- );
- if (postReply.value !== "New Reply") {
- alert(
- "to upvote a thread/reply you need to enter the thread then press upvote"
- );
- } else {
- if (postOrReply === "reply") {
- GetElementByXpath('//*[@id="body"]').value =
- intro.getElementsByClassName("post_no")[1].textContent +
- "\nYour upvote, xir.\n" +
- CreateRandomString(6);
- } else {
- GetElementByXpath(
- "/html/body/form[1]/table/tbody/tr[1]/td/input[1]"
- ).value = "bump";
- GetElementByXpath('//*[@id="body"]').value =
- "Your upvote, xir.\n" + CreateRandomString(6);
- }
- scrollTo(0, 0);
- }
- };
- }
- async function UpdateVotes() {
- for (const v of ThreadsWithPlebbitBar) {
- let votes = 0;
- const id = v.parentElement.id.replace("thread_", "");
- const url = `${location.protocol}//${
- location.hostname
- }/${v.parentElement.getAttribute("data-board")}/thread/${id}.json`;
- const result = await (await fetch(url)).json();
- const posts = result.posts;
- posts.shift();
- for (const v of posts) {
- if (v.email === "supersage") {
- votes -= 3;
- } else if (v.email === "sage") {
- votes -= 1;
- } else if (v.email === "bump") {
- votes += 2;
- } else {
- votes += 1;
- }
- }
- const votesElement = v.querySelector('[name="votes"]');
- votesElement.textContent = votes;
- }
- for (const v of PostsWithPlebbitBar) {
- let votes = 0;
- const id = v.parentElement.id.replace("thread_", "");
- const url = `${location.protocol}//${
- location.hostname
- }/${v.parentElement.getAttribute("data-board")}/thread/${id}.json`;
- const result = await (await fetch(url)).json();
- const posts = result.posts;
- posts.shift();
- for (const r of posts) {
- if (
- r.com.includes(v.id.replace("reply_", "")) &&
- r.com.includes("downvote")
- ) {
- votes -= 1;
- } else if (
- r.com.includes(v.id.replace("reply_", "")) &&
- r.com.includes("upvote")
- ) {
- votes += 1;
- }
- }
- const votesElement = v.querySelector('[name="votes"]');
- votesElement.textContent = votes;
- }
- }
- setInterval(async () => {
- const threads = [...document.getElementsByClassName("post op")];
- const posts = [...document.getElementsByClassName("post reply")];
- for (const thread of threads) {
- if (!ThreadsWithPlebbitBar.includes(thread)) {
- await AddRedditBar(thread, "thread");
- }
- }
- for (const post of posts) {
- if (!PostsWithPlebbitBar.includes(post)) {
- await AddRedditBar(post, "reply");
- }
- }
- await UpdateVotes();
- }, 2000);
Advertisement
Add Comment
Please, Sign In to add comment