Adds a button to allow you to deny all friend requests
目前為
// ==UserScript==
// @name Geoguessr Deny All
// @description Adds a button to allow you to deny all friend requests
// @version 1.0.0
// @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/received";
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`);
};
function doit() {
fetchWithCors(friend_reqs_api, "GET")
.then(ans => ans.json())
.then(list => {
for (let item of list) {
denyPlayer(item.userId);
}
});
};
document.doit = doit;
new MutationObserver(async (mutations) => {
if (document.getElementById("nuke-friend-reqs") != null) return;
const notifications = document.querySelector('ul[class*="notification-list_notifications__"]') || document.querySelector('div[class*="notification-list_noNotifications__"]');
if (notifications != null) {
const denyAllButton = document.createElement("li");
denyAllButton.classList.add("notification-list_notification__i0DH2");
denyAllButton.style = "display: flex; justify-content: center; padding: 0 0; padding-bottom: 15px;";
denyAllButton.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()" id="nuke-friend-reqs">
<div class="button_wrapper__NkcHZ">
<span>Deny all friend requests</span>
</div>
</button>
</div>`;
notifications.insertBefore(denyAllButton, notifications.childNodes[0]);
}
}).observe(document.body, { subtree: true, childList: true });