Auto leveling - discord.com

Bare bone tool to auto level up on Discord servers, send messages automatically

目前為 2025-06-30 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Auto leveling - discord.com
// @namespace   https://github.com/Thibb1
// @match       https://*.discord.com/*
// @grant       none
// @version     1.1
// @author      Thibb1
// @description Bare bone tool to auto level up on Discord servers, send messages automatically
// @require     https://cdn.jsdelivr.net/npm/[email protected]/dist/lil-gui.umd.min.js
// @license     GPL
// @run-at      document-start
// ==/UserScript==


(function() {
  'use strict';
  function getToken() {
    window.dispatchEvent(new Event('beforeunload'));
    const LS = document.body.appendChild(document.createElement('iframe')).contentWindow.localStorage;
    return JSON.parse(LS.token);
  }

  let __localStorage = localStorage;
  let token = getToken();
  let lastMessageId = null;

  const gui = new lil.GUI();

  const settings = {
    autoSendText: false,
    autoRemoveLast: true,
    randomText: true,
    myString: 'hello',
    autoInterval: 60,
    randomTextLen: 5,
    testSendText: sendText
  };
  gui.add(settings, 'autoSendText');
  gui.add(settings, 'autoRemoveLast');
  gui.add(settings, 'randomText');
  gui.add(settings, 'myString');
  gui.add(settings, 'randomTextLen', 1, 25, 1);

  function autoSend() {
    if (!settings.autoSendText) return;
    sendText();
  }

  async function discordApi(method, route, body) {
    return await fetch(route, {
      method,
      headers: {
        "Content-Type": "application/json",
        "Authorization": token,
      },
      ...(body != null && { body: JSON.stringify(body) })
    });
  }

  async function sendText() {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    let randomString = '';
    for (let i = 0; i < settings.randomTextLen; i++) {
      randomString += characters.charAt(Math.floor(Math.random() * characters.length));
    }
    const text = settings.randomText ? randomString : settings.myString;
    const channelStore = JSON.parse(__localStorage.getItem("SelectedChannelStore"));
    const channelId = channelStore.selectedChannelId;
    if (settings.autoRemoveLast && lastMessageId) {
      await discordApi('DELETE', `/api/v9/channels/${channelId}/messages/${lastMessageId}`)
        .then(response => {
          if (!response.ok) {
            console.error('Error deleting message:', response.statusText);
          }
        })
        .catch(error => {
          console.error('Error deleting message:', error);
        });
    }
    await discordApi('POST', `/api/v9/channels/${channelId}/messages`, { content: text, tts: false })
      .then(response => {
        if (!response.ok) {
          console.error('Error sending message:', response.statusText);
        } else {
          response.json().then(data => {lastMessageId = data.id; });
        }
      })
      .catch(error => {
        console.error('Error sending message:', error);
      });
  }

  let autoSendInterval;
  function startAutoSend() {
    if (autoSendInterval) {
      clearInterval(autoSendInterval);
    }
    if (settings.autoInterval > 0) {
      autoSendInterval = setInterval(autoSend, settings.autoInterval * 1000);
    }
  }
  gui.add(settings, 'autoInterval', 0, 120, 5).onChange(startAutoSend);
  gui.add(settings, 'testSendText');
  startAutoSend();
})();