123123123redditor

soyddit

Nov 2nd, 2024
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const plebbit = `<span name="upvote" class="flex mx-xs text-16">
  2.  <!--?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">
  3.  <!--?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><!--?-->
  4.  </svg>
  5.  </span><span name="votes">Loading...</span><span name="downvote" class="flex mx-xs text-16">
  6.  <!--?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">
  7.  <!--?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><!--?-->
  8.  </svg>
  9.  </span>`;
  10. const ThreadsWithPlebbitBar = [];
  11. const PostsWithPlebbitBar = [];
  12.  
  13. function GetElementByXpath(path) {
  14.     return document.evaluate(
  15.         path,
  16.         document,
  17.         null,
  18.         XPathResult.FIRST_ORDERED_NODE_TYPE,
  19.         null
  20.     ).singleNodeValue;
  21. }
  22.  
  23. function CreateRandomString(length) {
  24.     const chars =
  25.         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  26.     let result = "";
  27.     for (let i = 0; i < length; i++) {
  28.         result += chars.charAt(Math.floor(Math.random() * chars.length));
  29.     }
  30.     return result;
  31. }
  32.  
  33. async function AddRedditBar(post, postOrReply) {
  34.     if (postOrReply === "thread") {
  35.         ThreadsWithPlebbitBar.push(post);
  36.     } else if (postOrReply === "reply") {
  37.         PostsWithPlebbitBar.push(post);
  38.     }
  39.     const intro = post.getElementsByClassName("intro")[0];
  40.     const plebbitElement = document.createElement("span");
  41.     plebbitElement.name = "reddit";
  42.     plebbitElement.innerHTML = plebbit;
  43.     intro.appendChild(plebbitElement);
  44.     const downvote = plebbitElement.querySelector("[name=downvote]");
  45.     downvote.onclick = () => {
  46.         const postReply = GetElementByXpath(
  47.             "/html/body/form[1]/table/tbody/tr[1]/td/input[2]"
  48.         );
  49.         if (postReply.value !== "New Reply") {
  50.             alert(
  51.                 "to downvote a thread/reply you need to enter the thread then press downvote"
  52.             );
  53.         } else {
  54.             if (postOrReply === "reply") {
  55.                 GetElementByXpath('//*[@id="body"]').value =
  56.                     intro.getElementsByClassName("post_no")[1].textContent +
  57.                     "\nYour downvote, xir.\n" +
  58.                     CreateRandomString(6);
  59.             } else {
  60.                 GetElementByXpath(
  61.                     "/html/body/form[1]/table/tbody/tr[1]/td/input[1]"
  62.                 ).value = "sage";
  63.                 GetElementByXpath('//*[@id="body"]').value =
  64.                     "Your downvote, xir.\n" + CreateRandomString(6);
  65.             }
  66.             scrollTo(0, 0);
  67.         }
  68.     };
  69.     const upvote = plebbitElement.querySelector("[name=upvote]");
  70.     upvote.onclick = () => {
  71.         const postReply = GetElementByXpath(
  72.             "/html/body/form[1]/table/tbody/tr[1]/td/input[2]"
  73.         );
  74.         if (postReply.value !== "New Reply") {
  75.             alert(
  76.                 "to upvote a thread/reply you need to enter the thread then press upvote"
  77.             );
  78.         } else {
  79.             if (postOrReply === "reply") {
  80.                 GetElementByXpath('//*[@id="body"]').value =
  81.                     intro.getElementsByClassName("post_no")[1].textContent +
  82.                     "\nYour upvote, xir.\n" +
  83.                     CreateRandomString(6);
  84.             } else {
  85.                 GetElementByXpath(
  86.                     "/html/body/form[1]/table/tbody/tr[1]/td/input[1]"
  87.                 ).value = "bump";
  88.                 GetElementByXpath('//*[@id="body"]').value =
  89.                     "Your upvote, xir.\n" + CreateRandomString(6);
  90.             }
  91.             scrollTo(0, 0);
  92.         }
  93.     };
  94. }
  95.  
  96. async function UpdateVotes() {
  97.     for (const v of ThreadsWithPlebbitBar) {
  98.         let votes = 0;
  99.         const id = v.parentElement.id.replace("thread_", "");
  100.         const url = `${location.protocol}//${
  101.             location.hostname
  102.         }/${v.parentElement.getAttribute("data-board")}/thread/${id}.json`;
  103.         const result = await (await fetch(url)).json();
  104.         const posts = result.posts;
  105.         posts.shift();
  106.         for (const v of posts) {
  107.             if (v.email === "supersage") {
  108.                 votes -= 3;
  109.             } else if (v.email === "sage") {
  110.                 votes -= 1;
  111.             } else if (v.email === "bump") {
  112.                 votes += 2;
  113.             } else {
  114.                 votes += 1;
  115.             }
  116.         }
  117.         const votesElement = v.querySelector('[name="votes"]');
  118.         votesElement.textContent = votes;
  119.     }
  120.     for (const v of PostsWithPlebbitBar) {
  121.         let votes = 0;
  122.         const id = v.parentElement.id.replace("thread_", "");
  123.         const url = `${location.protocol}//${
  124.             location.hostname
  125.         }/${v.parentElement.getAttribute("data-board")}/thread/${id}.json`;
  126.         const result = await (await fetch(url)).json();
  127.         const posts = result.posts;
  128.         posts.shift();
  129.         for (const r of posts) {
  130.             if (
  131.                 r.com.includes(v.id.replace("reply_", "")) &&
  132.                 r.com.includes("downvote")
  133.             ) {
  134.                 votes -= 1;
  135.             } else if (
  136.                 r.com.includes(v.id.replace("reply_", "")) &&
  137.                 r.com.includes("upvote")
  138.             ) {
  139.                 votes += 1;
  140.             }
  141.         }
  142.         const votesElement = v.querySelector('[name="votes"]');
  143.         votesElement.textContent = votes;
  144.     }
  145. }
  146.  
  147. setInterval(async () => {
  148.     const threads = [...document.getElementsByClassName("post op")];
  149.     const posts = [...document.getElementsByClassName("post reply")];
  150.     for (const thread of threads) {
  151.         if (!ThreadsWithPlebbitBar.includes(thread)) {
  152.             await AddRedditBar(thread, "thread");
  153.         }
  154.     }
  155.     for (const post of posts) {
  156.         if (!PostsWithPlebbitBar.includes(post)) {
  157.             await AddRedditBar(post, "reply");
  158.         }
  159.     }
  160.     await UpdateVotes();
  161. }, 2000);
  162.  
Advertisement
Add Comment
Please, Sign In to add comment