Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name r/catalunya place bot
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author XXLuigiMario
- // @match https://www.reddit.com/r/place/*
- // @require https://cdn.jsdelivr.net/npm/toastify-js
- // @resource TOASTIFY_CSS https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css
- // @grant GM_getResourceText
- // @grant GM_addStyle
- // ==/UserScript==
- console.log(window.location.href);
- async function getAccessToken() {
- const usingOldReddit = window.location.href.includes("new.reddit.com");
- const url = usingOldReddit
- ? "https://new.reddit.com/r/place/"
- : "https://www.reddit.com/r/place/";
- const response = await fetch(url);
- const responseText = await response.text();
- // TODO: ew
- return responseText.split('"accessToken":"')[1].split('"')[0];
- }
- function place(x, y, color) {
- canvasIndex = Math.floor(x / 1000);
- x = x % 1000;
- return fetch("https://gql-realtime-2.reddit.com/query", {
- method: "POST",
- body: JSON.stringify({
- operationName: "setPixel",
- variables: {
- input: {
- actionName: "r/replace:set_pixel",
- PixelMessageData: {
- coordinate: {
- x: x,
- y: y,
- },
- colorIndex: color,
- canvasIndex: 0,
- },
- },
- },
- query:
- "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",
- }),
- headers: {
- origin: "https://hot-potato.reddit.com",
- referer: "https://hot-potato.reddit.com/",
- "apollographql-client-name": "mona-lisa",
- Authorization: `Bearer ${accessToken}`,
- "Content-Type": "application/json",
- },
- });
- }
- async function getNextPixel(channel) {
- const pixel = await fetch(`https://plum.duckdns.org/place/${channel}`, { method: "POST" });
- return await pixel.json();
- }
- function toast(text) {
- Toastify({
- text: text,
- duration: 10000,
- }).showToast();
- }
- let accessToken;
- (async function () {
- GM_addStyle(GM_getResourceText("TOASTIFY_CSS"));
- let channel = window.location.hash.substring(1);
- if (!channel) {
- toast("No channel specified");
- return;
- }
- setTimeout(window.location.reload, 300 + Math.random()*5);
- toast("Getting access token...");
- accessToken = await getAccessToken();
- toast("Access token fetched!");
- let pixel = await getNextPixel("senyera");
- toast(`Placing! x=${pixel.x} y=${pixel.y} color=${pixel.color}`);
- let r = await place(pixel.x, pixel.y, pixel.color);
- let data = await r.json();
- if (data.errors && data.errors.length) {
- toast(`Unable to place: ${data.errors[0].message}`);
- return;
- }
- toast("Place successful!");
- })();
Add Comment
Please, Sign In to add comment