Roblox Friend Remover

Remove all of your friends on Roblox

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Roblox Friend Remover
// @namespace    https://spin.rip/
// @version      3000
// @description  Remove all of your friends on Roblox
// @author       Spinfal
// @match        https://www.roblox.com/users/*/profile*
// @icon         https://www.google.com/s2/favicons?domain=roblox.com
// @grant        none
// @license      AGPL-3.0 License
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    const params = new URLSearchParams(window.location.search);
    const rmf = params.get('rmf') === 'true';

    // first‑pass: ask & reload
    if (!rmf) {
        setTimeout(() => {
          const userID = Roblox?.CurrentUser?.userId || prompt('Your Roblox user ID (must be yours):');
          if (!userID) return alert('No Roblox user ID was available. Try reloading the page.');
          if (!confirm('Remove all friends?')) return;
          sessionStorage.setItem("csrfToken", Roblox?.XsrfToken?.getToken());
          params.set('rmf', 'true');
          params.set('userId', userID);
          window.location.search = params.toString();
          return;
        }, 3000);
    }

    // second‑pass: rmf=true -> we already reloaded, now fetch CSRF + headers and unfriend
    (async function() {
        'use strict';
        const userId = params.get('userId');
        if (!userId) return;

        // 1. GET to grab response headers & friend list
        let resp;
        try {
            resp = await fetch(
                `https://friends.roblox.com/v1/users/${userId}/friends?sortOrder=Desc`,
                { method: 'GET', credentials: 'include' }
            );
        } catch (e) {
            console.error('[Friend Remover] Error fetching friends:', e);
            return alert('Error fetching friends. See console.');
        }

        // collect all response headers
        const responseHeaders = {};
        resp.headers.forEach((v, k) => { responseHeaders[k] = v; });

        // parse friend list from GET response
        let list;
        try {
            list = await resp.json();
        } catch (e) {
            console.error('[Friend Remover] Error parsing friend list:', e);
            return alert('Error parsing friend list. See console.');
        }

        // 2. check fresh CSRF token
        const csrfToken = sessionStorage.getItem("csrfToken");
        if (!csrfToken) return alert('failed to get fresh csrf token. try refreshing the page.');

        // merge captured headers + fresh CSRF
        const headers = {
            ...responseHeaders,
            'x-csrf-token': csrfToken
        };

        // 3. loop and unfriend
        for (const u of list.data) {
            fetch(
                `https://friends.roblox.com/v1/users/${u.id}/unfriend`,
                {
                    method: 'POST',
                    credentials: 'include',
                    headers: headers
                }
            ).then(r => {
                if (!r.ok) console.warn('[Friend Remover] Failed to unfriend', u.id, r.statusText);
            });
        }
        alert('Friend removal initiated. Check console for status.');
    })();
})();