XXLuigiMario

catalunya_placebot.user.js

Apr 3rd, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. // ==UserScript==
  2. // @name r/catalunya place bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author XXLuigiMario
  7. // @match https://www.reddit.com/r/place/*
  8. // @require https://cdn.jsdelivr.net/npm/toastify-js
  9. // @resource TOASTIFY_CSS https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css
  10. // @grant GM_getResourceText
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. console.log(window.location.href);
  15. async function getAccessToken() {
  16. const usingOldReddit = window.location.href.includes("new.reddit.com");
  17. const url = usingOldReddit
  18. ? "https://new.reddit.com/r/place/"
  19. : "https://www.reddit.com/r/place/";
  20. const response = await fetch(url);
  21. const responseText = await response.text();
  22.  
  23. // TODO: ew
  24. return responseText.split('"accessToken":"')[1].split('"')[0];
  25. }
  26.  
  27. function place(x, y, color) {
  28. canvasIndex = Math.floor(x / 1000);
  29. x = x % 1000;
  30. return fetch("https://gql-realtime-2.reddit.com/query", {
  31. method: "POST",
  32. body: JSON.stringify({
  33. operationName: "setPixel",
  34. variables: {
  35. input: {
  36. actionName: "r/replace:set_pixel",
  37. PixelMessageData: {
  38. coordinate: {
  39. x: x,
  40. y: y,
  41. },
  42. colorIndex: color,
  43. canvasIndex: 0,
  44. },
  45. },
  46. },
  47. query:
  48. "mutation setPixel($input: ActInput!) {\n act(input: $input) {\n data {\n ... on BasicMessage {\n id\n data {\n ... on GetUserCooldownResponseMessageData {\n nextAvailablePixelTimestamp\n __typename\n }\n ... on SetPixelResponseMessageData {\n timestamp\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n",
  49. }),
  50. headers: {
  51. origin: "https://hot-potato.reddit.com",
  52. referer: "https://hot-potato.reddit.com/",
  53. "apollographql-client-name": "mona-lisa",
  54. Authorization: `Bearer ${accessToken}`,
  55. "Content-Type": "application/json",
  56. },
  57. });
  58. }
  59.  
  60. async function getNextPixel(channel) {
  61. const pixel = await fetch(`https://plum.duckdns.org/place/${channel}`, { method: "POST" });
  62. return await pixel.json();
  63. }
  64.  
  65. function toast(text) {
  66. Toastify({
  67. text: text,
  68. duration: 10000,
  69. }).showToast();
  70. }
  71.  
  72. let accessToken;
  73. (async function () {
  74. GM_addStyle(GM_getResourceText("TOASTIFY_CSS"));
  75. let channel = window.location.hash.substring(1);
  76. if (!channel) {
  77. toast("No channel specified");
  78. return;
  79. }
  80. setTimeout(window.location.reload, 300 + Math.random()*5);
  81. toast("Getting access token...");
  82. accessToken = await getAccessToken();
  83. toast("Access token fetched!");
  84. let pixel = await getNextPixel("senyera");
  85. toast(`Placing! x=${pixel.x} y=${pixel.y} color=${pixel.color}`);
  86. let r = await place(pixel.x, pixel.y, pixel.color);
  87. let data = await r.json();
  88. if (data.errors && data.errors.length) {
  89. toast(`Unable to place: ${data.errors[0].message}`);
  90. return;
  91. }
  92. toast("Place successful!");
  93. })();
  94.  
Add Comment
Please, Sign In to add comment