Geoguessr Deny All

Adds 2 buttons to allow you to accept or deny all friend requests at once

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         Geoguessr Deny All
// @description  Adds 2 buttons to allow you to accept or deny all friend requests at once
// @version      1.0.2
// @author       victheturtle#5159
// @license      MIT
// @match        https://www.geoguessr.com/*
// @icon         https://www.geoguessr.com/images/auto/48/48/ce/0/plain/pin/99358f9464f5a7e8aa43826ed4d41a29.png
// @namespace    https://greasyfork.org/users/967692-victheturtle
// ==/UserScript==

async function fetchWithCors(url, method, body) {
    return await fetch(url, {
        "headers": {
            "accept": "*/*",
            "accept-language": "en-US,en;q=0.8",
            "content-type": "application/json",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-site",
            "sec-gpc": "1",
            "x-client": "web"
        },
        "referrer": "https://www.geoguessr.com/",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": (method == "GET") ? null : JSON.stringify(body),
        "method": method,
        "mode": "cors",
        "credentials": "include"
    });
};

let friend_reqs_api = "https://www.geoguessr.com/api/v3/social/friends/summary?page=0&fast=true";
let delete_friend_req_api = (id) => `https://www.geoguessr.com/api/v3/social/friends/${id}`;

async function denyPlayer(id) {
    await fetchWithCors(delete_friend_req_api(id), "DELETE", {});
    console.log(`${id} denied`);
};

async function acceptPlayer(id) {
    await fetchWithCors(delete_friend_req_api(id), "PUT", {});
    console.log(`${id} accepted`);
};

function doit(accept) {
    fetchWithCors(friend_reqs_api, "GET")
    .then(ans => ans.json())
    .then(json => {
        for (let item of json.requests) {
            accept ? acceptPlayer(item.userId) : denyPlayer(item.userId);
        }
    });
};

document.acceptAll = () => doit(true);
document.denyAll = () => doit(false);
document.doit = doit;

function makeButtons() {
    const button = document.createElement("li");
    button.classList.add("notification-list_notification__i0DH2");
    button.style = "display: flex; justify-content: center; padding: 0 0; padding-bottom: 15px;";
    button.innerHTML = `
        <div class="notification-list_notificationActions__9JEe6" style="margin: auto;">
            <button type="button" class="button_button__CnARx button_variantPrimary__xc8Hp button_sizeSmall__POheY" onclick="doit(true)" id="friend-reqs-true">
                <div class="button_wrapper__NkcHZ">
                    <span>Accept everyone</span>
                </div>
            </button>
            <button type="button" class="button_button__CnARx button_variantSecondary__lSxsR button_sizeSmall__POheY" onclick="doit(false)" id="friend-reqs-false">
                <div class="button_wrapper__NkcHZ">
                    <span>Deny everyone</span>
                </div>
            </button>
        </div>`;
   return button;
}

new MutationObserver(async (mutations) => {
    if (document.getElementById("friend-reqs-true") != null) return;
    const notifications = document.querySelector('ul[class*="notification-list_notifications__"]') || document.querySelector('div[class*="notification-list_noNotifications__"]');
    if (notifications != null) {
        const buttons = makeButtons();
        notifications.insertBefore(buttons, notifications.childNodes[0]);
    }
}).observe(document.body, { subtree: true, childList: true });