-
-
Save webworker01/866f75c0af24eab87d29423bf63f61ba to your computer and use it in GitHub Desktop.
Revisions
-
Carleton Stuberg revised this gist
Jun 26, 2017 . 1 changed file with 26 additions and 52 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,58 +1,32 @@ // Turn on Developer Mode under User Settings > Appearance > Developer Mode (at the bottom) // Then open the channel you wish to delete all of the messages (could be a DM) and click the three dots on the far right. // Click "Copy ID" and paste that instead of LAST_MESSAGE_ID. // Copy / paste the below script into the JavaScript console. // If you're in a DM you will receive a 403 error for every message the other user sent (you don't have permission to delete their messages). var before = 'LAST_MESSAGE_ID'; clearMessages = function(){ const authToken = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/"/g, ""); const channel = window.location.href.split('/').pop(); const baseURL = `https://discordapp.com/api/channels/${channel}/messages`; const headers = {"Authorization": authToken }; let clock = 0; let interval = 500; function delay(duration) { return new Promise((resolve, reject) => { setTimeout(() => resolve(), duration); }); } fetch(baseURL + '?before=' + before + '&limit=100', {headers}) .then(resp => resp.json()) .then(messages => { return Promise.all(messages.map((message) => { before = message.id; return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'})); })); }).then(() => clearMessages()); } clearMessages(); -
Carleton Stuberg revised this gist
Feb 23, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // VARIABLES var channelid = 'CHANGE_TO_CHANNEL_ID'; var authorization = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/"/g, ""); // FUNCTIONS Object.size = function(obj) { -
Carleton Stuberg revised this gist
Feb 21, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // VARIABLES var channelid = 'CHANGE_TO_CHANNEL_ID'; var authorization = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token; // FUNCTIONS Object.size = function(obj) { -
Carleton Stuberg revised this gist
Feb 15, 2017 . 1 changed file with 53 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,58 @@ // VARIABLES var channelid = 'CHANGE_TO_CHANNEL_ID'; var authorization = 'CHANGE_TO_AUTH_TOKEN'; // FUNCTIONS Object.size = function(obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }; function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function deleteOneMessage(id) { var xhr = new XMLHttpRequest(); xhr.open("DELETE", "https://discordapp.com/api/v6/channels/"+channelid+"/messages/"+id, true); xhr.setRequestHeader("authorization", authorization); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { console.log("deleted: "+id+" "+xhr.status); } } xhr.send(); } async function deleteAllMessages(ids) { for (var i=0; i<ids.length; i++) { deleteOneMessage(ids[i]); await sleep(200); } getId(); } function getId() { var xhr = new XMLHttpRequest(); xhr.open("GET", "https://discordapp.com/api/v6/channels/"+channelid+"/messages?limit=100", true); xhr.setRequestHeader("authorization", authorization); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { var obj = JSON.parse(xhr.responseText); var size = Object.size(obj); var ids = new Array(); for (var i=0; i<size; i++) { ids[i] = obj[i].id; } deleteAllMessages(ids); } } xhr.send(); } getId(); -
Carleton Stuberg revised this gist
Nov 7, 2016 . 2 changed files with 23 additions and 62 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,26 @@ var before = CHANGE_THIS_TO_LAST_MSG_ID; clearMessages = function(){ const authToken = JSON.parse(localStorage.token); const channel = window.location.href.split('/').pop(); const baseURL = `https://discordapp.com/api/channels/${channel}/messages`; const headers = {"Authorization": authToken }; let clock = 0; let interval = 500; function delay(duration) { return new Promise((resolve, reject) => { setTimeout(() => resolve(), duration); }); } fetch(baseURL + '?before=' + before + '&limit=100', {headers}) .then(resp => resp.json()) .then(messages => { return Promise.all(messages.map((message) => { before = message.id; return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'})); })); }).then(() => clearMessages()); } clearMessages(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,31 +0,0 @@ -
niahoo osef revised this gist
May 3, 2016 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,3 @@ var authToken = 'MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk' This script will only delete the messages that are visible. So, if you want to delete more messages, you should scroll top to show more of them **before** launch. If you do not have the permissions to delete some messages, the script should still work with yours (not tested). Copy the full code that you have edited, paste it into the browser javascript console and watch your messages being deleted. -
niahoo osef revised this gist
May 3, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ var authToken = 'MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk' ### 4. Launch This script will only delete the messages that are visible. So, if you want to delete more messages, you should scroll top to show more of them **before** launch. If you do not have the permissions to delete some messages, the script should still work with yours (not tested). Copy the full code that you have edited, paste it into the browser javascript console and watch your messages being deleted. -
niahoo osef created this gist
May 3, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ (function(){ // Paste your token between the quotes : var authToken = '________________________________________' // https://github.com/yanatan16/nanoajax !function(t,e){function n(t){return t&&e.XDomainRequest&&!/MSIE 1/.test(navigator.userAgent)?new XDomainRequest:e.XMLHttpRequest?new XMLHttpRequest:void 0}function o(t,e,n){t[e]=t[e]||n}var r=["responseType","withCredentials","timeout","onprogress"];t.ajax=function(t,a){function s(t,e){return function(){c||(a(void 0===f.status?t:f.status,0===f.status?"Error":f.response||f.responseText||e,f),c=!0)}}var u=t.headers||{},i=t.body,d=t.method||(i?"POST":"GET"),c=!1,f=n(t.cors);f.open(d,t.url,!0);var l=f.onload=s(200);f.onreadystatechange=function(){4===f.readyState&&l()},f.onerror=s(null,"Error"),f.ontimeout=s(null,"Timeout"),f.onabort=s(null,"Abort"),i&&(o(u,"X-Requested-With","XMLHttpRequest"),e.FormData&&i instanceof e.FormData||o(u,"Content-Type","application/x-www-form-urlencoded"));for(var p,m=0,v=r.length;v>m;m++)p=r[m],void 0!==t[p]&&(f[p]=t[p]);for(var p in u)f.setRequestHeader(p,u[p]);return f.send(i),f},e.nanoajax=t}({},function(){return this}()); var regexReactId = /\$[0-9]+/g var ids = $$('[data-reactid*=":$"].message-text').map(function getMessageId(el) { var reactid = el.getAttribute('data-reactid') var match = reactid.match(regexReactId) var id = match.pop().substr(1) return id }).filter(function(id){ return !!id }) var channel = window.location.href.split('/').pop() var base_url = 'https://discordapp.com/api/channels/' + channel + '/messages/' var deleteLoop = function(){ if (! ids.length) { return } var id = ids.pop() nanoajax.ajax({ url: base_url + id, method: 'DELETE', headers: { authorization: authToken } }, function(){ setTimeout(deleteLoop, 500) }) } deleteLoop() }()) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ # Delete all messages in a Discord channel You have to know how to use your browser developer tools to use this thechnique. ### 1. Open your channel The URL must be like `https://discordapp.com/channels/XXXXXXX` and not `https://discordapp.com/channels/XXXXXXXXX/YYYYYYYY`. If so, change it manually. Once on the right page, you must not reload or navigate. ### 2. Get your authorization token - Open the dev tools (F12), open the Network tab. (You should clear all requests for better readability if you see some.) - Delete one message manually. In the request log, you will see a request with a `DELETE` method. - Click on the request to open the details, and on the Headers tab, copy the 'authorization' thoken. It's a long text with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`. ### 3. Get the script Edit the javascript code from this tutorial in a text editor. Find the line starting with with `var authToken = ` and paste the token. Pay attention to the quotes. The code should read like this : ```javascript // Paste your token between the quotes : var authToken = 'MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk' ``` ### 4. Launch This script will only delete the messages that are visible. So, if you want to delete more messages, you should scroll top to show more of them. If you do not have the permissions to delete some messages, the script should still work with yours (not tested). Copy the full code that you have edited, paste it into the browser javascript console and watch your messages being deleted. ### This is too slow ? You can change the `setTimeout` time value if you want. Please be gentle with Discord's free servers.