您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Send DM messages via Discord API
当前为
- // ==UserScript==
- // @name Discord DM Sender with Input Box
- // @namespace http://tampermonkey.net/
- // @version 1
- // @description Send DM messages via Discord API
- // @author Your Name
- // @match https://discord.com/*
- // @grant GM_xmlhttpRequest
- // @grant GM_setValue
- // @grant GM_getValue
- // @license You can modify as long as you credit me
- // ==/UserScript==
- (function() {
- 'use strict';
- const channelId = '1312547211074211943';
- const initialWidth = '280px';
- const initialHeight = '200px';
- const container = document.createElement('div');
- container.style.position = 'fixed';
- container.style.bottom = '10px';
- container.style.left = '10px';
- container.style.backgroundColor = '#2f3136';
- container.style.color = '#ffffff';
- container.style.padding = '10px';
- container.style.borderRadius = '5px';
- container.style.zIndex = '1000';
- container.style.width = initialWidth;
- container.style.height = initialHeight;
- document.body.appendChild(container);
- makeElementDraggable(container);
- const tokenBox = document.createElement('textarea');
- tokenBox.placeholder = 'Enter your token';
- tokenBox.style.width = '100%';
- tokenBox.style.height = '40px';
- tokenBox.style.resize = 'none';
- tokenBox.style.backgroundColor = '#000000';
- tokenBox.style.color = '#00FF00';
- container.appendChild(tokenBox);
- const inputBox = document.createElement('textarea');
- inputBox.placeholder = 'Enter your secret message to aarr';
- inputBox.style.width = '100%';
- inputBox.style.height = '100px';
- inputBox.style.resize = 'none';
- inputBox.style.backgroundColor = '#000000';
- inputBox.style.color = '#00FF00';
- container.appendChild(inputBox);
- const button = document.createElement('button');
- button.innerText = 'Send DM';
- button.style.marginTop = '10px';
- button.style.width = '100%';
- button.style.backgroundColor = '#7289da';
- button.style.color = '#ffffff';
- button.style.border = 'none';
- button.style.borderRadius = '3px';
- button.style.cursor = 'pointer';
- container.appendChild(button);
- inputBox.value = GM_getValue('inputBoxValue', '');
- tokenBox.value = GM_getValue('tokenBoxValue', '');
- async function sendDM() {
- const token = tokenBox.value.trim();
- if (!token) {
- alert('Token is required');
- return;
- }
- const message = inputBox.value.trim();
- if (!message) {
- alert('Message cannot be empty');
- return;
- }
- tokenBox.style.display = 'none';
- GM_setValue('tokenBoxValue', token);
- const success = await sendMessage(channelId, message, token);
- if (success) {
- inputBox.value = '';
- GM_setValue('inputBoxValue', '');
- } else {
- alert('Failed to send message');
- }
- }
- button.addEventListener('click', sendDM);
- inputBox.addEventListener('keydown', (event) => {
- if (event.key === 'Enter' && !event.shiftKey) {
- event.preventDefault();
- sendDM();
- } else if (event.key === 'Enter' && event.shiftKey) {
- event.preventDefault();
- const cursorPos = inputBox.selectionStart;
- const textBefore = inputBox.value.substring(0, cursorPos);
- const textAfter = inputBox.value.substring(cursorPos);
- inputBox.value = `${textBefore}\n${textAfter}`;
- inputBox.selectionStart = cursorPos + 1;
- inputBox.selectionEnd = cursorPos + 1;
- }
- });
- inputBox.addEventListener('input', () => {
- GM_setValue('inputBoxValue', inputBox.value);
- });
- tokenBox.addEventListener('input', () => {
- GM_setValue('tokenBoxValue', tokenBox.value);
- });
- function makeElementDraggable(el) {
- el.onmousedown = function(event) {
- if (event.target === inputBox || event.target === tokenBox) {
- return;
- }
- event.preventDefault();
- let shiftX = event.clientX - el.getBoundingClientRect().left;
- let shiftY = event.clientY - el.getBoundingClientRect().top;
- function moveAt(pageX, pageY) {
- el.style.left = pageX - shiftX + 'px';
- el.style.top = pageY - shiftY + 'px';
- }
- function onMouseMove(event) {
- moveAt(event.pageX, event.pageY);
- }
- document.addEventListener('mousemove', onMouseMove);
- el.onmouseup = function() {
- document.removeEventListener('mousemove', onMouseMove);
- el.onmouseup = null;
- };
- };
- el.ondragstart = function() {
- return false;
- };
- }
- async function sendMessage(channelId, message, token) {
- const nonce = generateNonce();
- return new Promise((resolve) => {
- GM_xmlhttpRequest({
- method: 'POST',
- url: `https://discord.com/api/v9/channels/${channelId}/messages`,
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': token
- },
- data: JSON.stringify({
- content: message,
- flags: 0,
- mobile_network_type: "unknown",
- nonce: nonce,
- tts: false
- }),
- onload: (response) => {
- resolve(response.status === 200);
- },
- onerror: () => resolve(false)
- });
- });
- }
- function generateNonce() {
- const now = Date.now();
- return `${now}${Math.floor(Math.random() * 1000)}`;
- }
- })();