Discord Conceals Filenames

Replace the names of files you upload to Discord.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Advertisement:

// ==UserScript==
// @name         Discord Conceals Filenames
// @description  Replace the names of files you upload to Discord.
// @version      1
// @grant        none
// @match        https://discord.com/*
// @author       piousdeer
// @namespace https://greasyfork.org/users/749016
// ==/UserScript==

// Which string to replace filename with.
const REPLACE_WITH = "unknown";
// Set to "whitelist" to only affect files with selected extensions, "blacklist" to affect all files but those ones.
const MODE = "blocklist";
// E.g. ["mp4", "gif"] will make the script ignore these files in blacklist mode.
const EXTENSIONS = [];

const _getFilename = Object.getOwnPropertyDescriptor(File.prototype, "name").get;

Object.defineProperty(File.prototype, "name", {
  get() {
    const filename = _getFilename.call(this);
    const extension = filename.split(".").slice(-1)[0];
    const isListed = EXTENSIONS.includes(extension);

    if (
      (MODE === "blacklist" && isListed) ||
      (MODE === "whitelist" && !isListed)
    ) {
      return filename;
    }

    return [REPLACE_WITH, extension].join(".");
  },
});