diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e8f0d29..bfa46adf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,55 @@ +# Contributing -Please do not make changes to the .js files at the root directory! -Only make changes to the change the files inside the `src/` folder, otherwise I can't merge your changes back to the project. +# Before making any changes ✋ +## Do not edit files at top -If you're unfamilliar with compiled Javascript: +Please do not make changes to the `.js` files in the top directory! +Only make changes to the files inside the `src/` folder, otherwise I can't merge your changes back to the project. + +Also, do not commit changes to the `deleteDiscordMessages.user.js` file! + +Do not alter the version, because I may have to change this depending on the order of things that get merged into main. So please leave it as is to avoid conflicts. + +## Oddities about this project + +> This is NOT your typical javascript App, so this project has a few oddities: + +- Do NOT add external dependencies or libraries. + The only allowed dependencies are related things that run during build and testing. + The script itself should't import or load anything external. + The reason for this is security, if the user has to audit external packages we're doomed. + +- Do NOT use Prettier. + This project has to stay fairly short in order to be auditable in a short amount of time. + For that reason some parts of the code favor compactness instead of consistency of indentation. + + +------------------------------------------------------------------------------- + +# Building the project +# Now that you read that, this is what you do + +#### Click to watch video (45 seconds): +[![Video Instructions](https://img.youtube.com/vi/AKTCvzvcPig/0.jpg)](https://www.youtube.com/watch?v=AKTCvzvcPig) +https://www.youtube.com/watch?v=AKTCvzvcPig + + +If you're unfamilliar with compiled Javascript, this is how you do it: 1. Clone the repository to your computer 2. Open the terminal inside the cloned directory 3. Run `npm i` to download the project dependencies 4. Run `npm start` it will automatically compile the project, when you make changes + +## Testing locally + +Open the URL that shows up in your console when you run `npm start` it will ask you to install a development version of Undiscord. +You need to click the update button every time you make changes in TamperMonkey, or reinstall it by opening the URL again. + +You can alternatively test manually: + +Copy the contents of the `deleteDiscordMessages.user.js` at the top of the repository, +and paste it directly into your browser console. + +---------------------------------------------------------------- + diff --git a/readme.md b/README.md similarity index 98% rename from readme.md rename to README.md index 56778fb4..14c5ac9c 100644 --- a/readme.md +++ b/README.md @@ -54,6 +54,8 @@ Is prefered that _issues_ follow a certain format. If you're not familiar with b If you believe you found a bug please file an [issue](https://github.com/victornpb/undiscord/issues), but please fill the issue template. +If you are looking to contribute please read the [CONTRIBUTING](./CONTRIBUTING.md) first. + ### Copy paste version Looking for the old Copy/Paste version? [here](https://github.com/victornpb/undiscord/wiki/Copy-paste-method) diff --git a/build/metadata.js b/build/metadata.mjs similarity index 71% rename from build/metadata.js rename to build/metadata.mjs index 67802d80..42654c9b 100644 --- a/build/metadata.js +++ b/build/metadata.mjs @@ -1,5 +1,6 @@ -// const pkg = require('../package.json'); -import pkg from '../package.json'; +import fs from 'fs'; +const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url))); + // // Generate metadata block with information from package.json @@ -25,11 +26,13 @@ function generateComment(manifest) { ].join('\n'); } -export default () => { +export default function userScriptMetadataBlock() { + const pkg = loadJSON('../package.json'); + const metadata = { name: pkg.nameFull, description: pkg.description, - version: pkg.version, + version: process.env.VERSION, author: pkg.author, homepageURL: pkg.homepage, supportURL: pkg.bugs.url, @@ -39,12 +42,15 @@ export default () => { }; if (!production) { + metadata.name = metadata.name + ' [DEV]'; + metadata.namespace = metadata.namespace + '_DEV'; + delete metadata.downloadURL; delete metadata.updateURL; delete metadata.homepageURL; - metadata.version = new Date().toISOString(); - // metadata.namespace = 'foobar'; + + metadata.downloadURL = metadata.updateURL = metadata.homepageURL = 'http://localhost:10001/deleteDiscordMessages.user.js'; } return generateComment(metadata); -}; +} \ No newline at end of file diff --git a/build/strings-plugin.js b/build/strings-plugin.mjs similarity index 77% rename from build/strings-plugin.js rename to build/strings-plugin.mjs index f0bc8ed1..1aa3cb2a 100644 --- a/build/strings-plugin.js +++ b/build/strings-plugin.mjs @@ -1,4 +1,4 @@ -const { createFilter } = require('rollup-pluginutils'); +import { createFilter } from 'rollup-pluginutils'; export function string(opts = {}) { if (!opts.include) { @@ -12,6 +12,7 @@ export function string(opts = {}) { transform(code, id) { if (filter(id)) { + if (opts.transform) code = opts.transform(code, id, opts); return { code: 'export default (`\n'+ code + '\n`);', map: { mappings: '' } diff --git a/deleteDiscordMessages.user.js b/deleteDiscordMessages.user.js index bb939e95..fda6a86f 100644 --- a/deleteDiscordMessages.user.js +++ b/deleteDiscordMessages.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Undiscord // @description Delete all messages in a Discord channel or DM (Bulk deletion) -// @version 5.0.3 +// @version 5.1.0 // @author victornpb // @homepageURL https://github.com/victornpb/undiscord // @supportURL https://github.com/victornpb/undiscord/issues @@ -10,455 +10,130 @@ // @match https://*.discord.com/login // @license MIT // @namespace https://github.com/victornpb/deleteDiscordMessages +// @icon https://github.com/victornpb/undiscord/images/icon128.png // @downloadURL https://raw.githubusercontent.com/victornpb/deleteDiscordMessages/master/deleteDiscordMessages.user.js // @contributionURL https://www.buymeacoffee.com/vitim // @grant none // ==/UserScript== (function () { - 'use strict'; + 'use strict'; - var version = "5.0.3"; + /* rollup-plugin-baked-env */ + const VERSION = "5.1.0"; - var discordStyles = (` + var themeCss = (` /* undiscord window */ -#undiscord.browser { - box-shadow: var(--elevation-stroke), var(--elevation-high); - overflow: hidden; -} - +#undiscord.browser { box-shadow: var(--elevation-stroke), var(--elevation-high); overflow: hidden; } #undiscord.container, -#undiscord .container { - background-color: var(--background-secondary); - border-radius: 8px; - box-sizing: border-box; - cursor: default; - flex-direction: column; -} - -#undiscord .header { - background-color: var(--background-tertiary); - height: 48px; - align-items: center; - min-height: 48px; - padding: 0 16px; - display: flex; - color: var(--header-secondary); -} - -#undiscord .header .icon { - color: var(--interactive-normal); - margin-right: 8px; - flex-shrink: 0; - width: 24; - height: 24; -} - -#undiscord .header .icon:hover { - color: var(--interactive-hover); -} - -#undiscord .header h3 { - font-size: 16px; - line-height: 20px; - font-weight: 500; - font-family: var(--font-display); - color: var(--header-primary); - flex-shrink: 0; - margin-right: 16px; -} - -#undiscord .header .spacer { - flex-grow: 1; -} - -#undiscord .header .vert-divider { - width: 1px; - height: 24px; - background-color: var(--background-modifier-accent); - margin-right: 16px; - flex-shrink: 0; -} - +#undiscord .container { background-color: var(--background-secondary); border-radius: 8px; box-sizing: border-box; cursor: default; flex-direction: column; } +#undiscord .header { background-color: var(--background-tertiary); height: 48px; align-items: center; min-height: 48px; padding: 0 16px; display: flex; color: var(--header-secondary); cursor: grab; } +#undiscord .header .icon { color: var(--interactive-normal); margin-right: 8px; flex-shrink: 0; width: 24; height: 24; } +#undiscord .header .icon:hover { color: var(--interactive-hover); } +#undiscord .header h3 { font-size: 16px; line-height: 20px; font-weight: 500; font-family: var(--font-display); color: var(--header-primary); flex-shrink: 0; margin-right: 16px; } +#undiscord .spacer { flex-grow: 1; } +#undiscord .header .vert-divider { width: 1px; height: 24px; background-color: var(--background-modifier-accent); margin-right: 16px; flex-shrink: 0; } #undiscord legend, -#undiscord label { - display: block; - width: 100%; - color: var(--header-secondary); - font-size: 12px; - line-height: 16px; - font-weight: 500; - text-transform: uppercase; - cursor: default; - font-family: var(--font-display); - margin-bottom: 8px; -} - -#undiscord .multiInput { - display: flex; - align-items: center; - font-size: 16px; - box-sizing: border-box; - width: 100%; - border-radius: 3px; - color: var(--text-normal); - background-color: var(--input-background); - border: none; - transition: border-color 0.2s ease-in-out 0s; -} - -#undiscord .multiInput :first-child { - flex-grow: 1; -} - -#undiscord .multiInput button:last-child { - margin-right: 4px; -} - -#undiscord .input { - font-size: 16px; - box-sizing: border-box; - width: 100%; - border-radius: 3px; - color: var(--text-normal); - background-color: var(--input-background); - border: none; - transition: border-color 0.2s ease-in-out 0s; - - padding: 10px; - height: 40px; -} - -#undiscord fieldset { - margin-top: 16px; -} - -#undiscord .input-wrapper { - display: flex; - align-items: center; - font-size: 16px; - box-sizing: border-box; - width: 100%; - border-radius: 3px; - color: var(--text-normal); - background-color: var(--input-background); - border: none; - transition: border-color 0.2s ease-in-out 0s; -} - +#undiscord label { color: var(--header-secondary); font-size: 12px; line-height: 16px; font-weight: 500; text-transform: uppercase; cursor: default; font-family: var(--font-display); margin-bottom: 8px; } +#undiscord .multiInput { display: flex; align-items: center; font-size: 16px; box-sizing: border-box; width: 100%; border-radius: 3px; color: var(--text-normal); background-color: var(--input-background); border: none; transition: border-color 0.2s ease-in-out 0s; } +#undiscord .multiInput :first-child { flex-grow: 1; } +#undiscord .multiInput button:last-child { margin-right: 4px; } +#undiscord .input { font-size: 16px; box-sizing: border-box; width: 100%; border-radius: 3px; color: var(--text-normal); background-color: var(--input-background); border: none; transition: border-color 0.2s ease-in-out 0s; padding: 10px; height: 40px; } +#undiscord fieldset { margin-top: 16px; } +#undiscord .input-wrapper { display: flex; align-items: center; font-size: 16px; box-sizing: border-box; width: 100%; border-radius: 3px; color: var(--text-normal); background-color: var(--input-background); border: none; transition: border-color 0.2s ease-in-out 0s; } #undiscord input[type="text"], #undiscord input[type="search"], #undiscord input[type="password"], #undiscord input[type="datetime-local"], -#undiscord input[type="number"] { - font-size: 16px; - box-sizing: border-box; - width: 100%; - border-radius: 3px; - color: var(--text-normal); - background-color: var(--input-background); - border: none; - transition: border-color 0.2s ease-in-out 0s; - padding: 10px; - height: 40px; -} - +#undiscord input[type="number"], +#undiscord input[type="range"] { font-size: 16px; box-sizing: border-box; width: 100%; border-radius: 3px; color: var(--text-normal); background-color: var(--input-background); border: none; transition: border-color 0.2s ease-in-out 0s; padding: 10px; height: 40px; } #undiscord .divider, -#undiscord hr { - border: none; - margin-bottom: 24px; - padding-bottom: 4px; - border-bottom: 1px solid var(--background-modifier-accent); -} - -#undiscord .sectionDescription { - margin-bottom: 16px; - color: var(--header-secondary); - font-size: 14px; - line-height: 20px; - font-weight: 400; -} - -#undiscord a { - color: var(--text-link); - text-decoration: none; -} - +#undiscord hr { border: none; margin-bottom: 24px; padding-bottom: 4px; border-bottom: 1px solid var(--background-modifier-accent); } +#undiscord .sectionDescription { margin-bottom: 16px; color: var(--header-secondary); font-size: 14px; line-height: 20px; font-weight: 400; } +#undiscord a { color: var(--text-link); text-decoration: none; } #undiscord .btn, -#undiscord button { - position: relative; - display: flex; - -webkit-box-pack: center; - justify-content: center; - -webkit-box-align: center; - align-items: center; - box-sizing: border-box; - background: none; - border: none; - border-radius: 3px; - font-size: 14px; - font-weight: 500; - line-height: 16px; - padding: 2px 16px; - user-select: none; - - /* sizeSmall */ - width: 60px; - height: 32px; - min-width: 60px; - min-height: 32px; - - /* lookFilled colorPrimary */ - color: rgb(255, 255, 255); - background-color: var(--button-secondary-background); -} - -#undiscord .sizeMedium { - width: 96px; - height: 38px; - min-width: 96px; - min-height: 38px; -} - +#undiscord button { position: relative; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; box-sizing: border-box; background: none; border: none; border-radius: 3px; font-size: 14px; font-weight: 500; line-height: 16px; padding: 2px 16px; user-select: none; /* sizeSmall */ width: 60px; height: 32px; min-width: 60px; min-height: 32px; /* lookFilled colorPrimary */ color: rgb(255, 255, 255); background-color: var(--button-secondary-background); } +#undiscord .sizeMedium { width: 96px; height: 38px; min-width: 96px; min-height: 38px; } +#undiscord .sizeMedium.icon { width: 38px; min-width: 38px; } +#undiscord sup { vertical-align: top; } /* lookFilled colorPrimary */ -#undiscord .accent { - background-color: var(--brand-experiment); -} - -#undiscord .danger { - background-color: var(--button-danger-background); -} - -#undiscord .positive { - background-color: var(--button-positive-background); -} - - -#undiscord .info { - font-size: 12px; - line-height: 16px; - padding: 8px 10px; - color: var(--text-muted); -} - +#undiscord .accent { background-color: var(--brand-experiment); } +#undiscord .danger { background-color: var(--button-danger-background); } +#undiscord .positive { background-color: var(--button-positive-background); } +#undiscord .info { font-size: 12px; line-height: 16px; padding: 8px 10px; color: var(--text-muted); } /* Scrollbar */ -#undiscord .scroll::-webkit-scrollbar { - width: 8px; - height: 8px; -} - -#undiscord .scroll::-webkit-scrollbar-corner { - background-color: transparent; -} - -#undiscord .scroll::-webkit-scrollbar-thumb { - background-clip: padding-box; - border: 2px solid transparent; - border-radius: 4px; - background-color: var(--scrollbar-thin-thumb); - min-height: 40px; -} - -#undiscord .scroll::-webkit-scrollbar-track { - border-color: var(--scrollbar-thin-track); - background-color: var(--scrollbar-thin-track); - border: 2px solid var(--scrollbar-thin-track); -} - +#undiscord .scroll::-webkit-scrollbar { width: 8px; height: 8px; } +#undiscord .scroll::-webkit-scrollbar-corner { background-color: transparent; } +#undiscord .scroll::-webkit-scrollbar-thumb { background-clip: padding-box; border: 2px solid transparent; border-radius: 4px; background-color: var(--scrollbar-thin-thumb); min-height: 40px; } +#undiscord .scroll::-webkit-scrollbar-track { border-color: var(--scrollbar-thin-track); background-color: var(--scrollbar-thin-track); border: 2px solid var(--scrollbar-thin-track); } /* fade scrollbar */ #undiscord .scroll::-webkit-scrollbar-thumb, -#undiscord .scroll::-webkit-scrollbar-track { - visibility: hidden; -} - +#undiscord .scroll::-webkit-scrollbar-track { visibility: hidden; } #undiscord .scroll:hover::-webkit-scrollbar-thumb, -#undiscord .scroll:hover::-webkit-scrollbar-track { - visibility: visible; -} +#undiscord .scroll:hover::-webkit-scrollbar-track { visibility: visible; } +/**** functional classes ****/ +#undiscord.redact .priv { display: none !important; } +#undiscord.redact x:not(:active) { color: transparent !important; background-color: var(--primary-700) !important; cursor: default; } +#undiscord.redact x:hover { position: relative; } +#undiscord.redact x:hover::after { content: "Redacted information (Streamer mode: ON)"; position: absolute; display: inline-block; top: -32px; left: -20px; padding: 4px; width: 150px; font-size: 8pt; text-align: center; white-space: pre-wrap; background-color: var(--background-floating); -webkit-box-shadow: var(--elevation-high); box-shadow: var(--elevation-high); color: var(--text-normal); border-radius: 5px; pointer-events: none; } +#undiscord.redact [priv] { -webkit-text-security: disc !important; } +#undiscord :disabled { display: none; } +/**** layout and utility classes ****/ +#undiscord, +#undiscord * { box-sizing: border-box; } +#undiscord .col { display: flex; flex-direction: column; } +#undiscord .row { display: flex; flex-direction: row; align-items: center; } +#undiscord .mb1 { margin-bottom: 8px; } +#undiscord .log { margin-bottom: 0.25em; } +#undiscord .log-debug { color: inherit; } +#undiscord .log-info { color: #00b0f4; } +#undiscord .log-verb { color: #72767d; } +#undiscord .log-warn { color: #faa61a; } +#undiscord .log-error { color: #f04747; } +#undiscord .log-success { color: #43b581; } `); - var undiscordStyles = (` + var mainCss = (` /**** Undiscord Button ****/ -#undicord-btn { - position: relative; - width: auto; - height: 24px; - margin: 0 8px; - cursor: pointer; - color: var(--interactive-normal); - flex: 0 0 auto; -} - -#undicord-btn progress { - position: absolute; - top: 7px; - left: 5px; - width: 14px; - height: 14px; -} - +#undicord-btn { position: relative; width: auto; height: 24px; margin: 0 8px; cursor: pointer; color: var(--interactive-normal); flex: 0 0 auto; } +#undicord-btn progress { position: absolute; top: 23px; left: -4px; width: 32px; height: 12px; display: none; } +#undicord-btn.running { color: var(--button-danger-background) !important; } +#undicord-btn.running progress { display: block; } /**** Undiscord Interface ****/ -#undiscord { - position: fixed; - z-index: 99; - top: 44px; - right: 10px; - display: flex; - flex-direction: column; - width:800px; - height: 80vh; - min-width: 610px; - max-width: 100vw; - min-height: 448px; - max-height: 100vh; - color: var(--text-normal); - border-radius: 4px; - background-color: var(--background-secondary); - box-shadow: var(--elevation-stroke), var(--elevation-high); - will-change: top, left, width, height; -} - -#undiscord .header .icon { - cursor: pointer; -} - -#undiscord .window-body { - height: calc(100% - 48px); -} - -#undiscord .sidebar { - overflow: hidden scroll; - overflow-y: auto; - width: 270px; - min-width: 250px; - height: 100%; - max-height: 100%; - padding: 8px; - background: var(--background-secondary); -} - -#undiscord .main { - display: flex; - max-width: calc(100% - 250px); - background-color: var(--background-primary); - flex-grow: 1; -} - -#undiscord #logArea { - font-family: Consolas, Liberation Mono, Menlo, Courier, monospace; - font-size: .75rem; - overflow: auto; - padding: 10px; - user-select: text; - flex-grow: 1; - flex-grow: 1; -} - -#undiscord .tbar { - padding: 8px; - background-color: var(--background-secondary-alt); -} - -#undiscord .tbar button { - margin-right: 4px; - margin-bottom: 4px; -} - -#undiscord .footer { - cursor: se-resize; -} - +#undiscord { position: fixed; z-index: 99; top: 44px; right: 10px; display: flex; flex-direction: column; width: 800px; height: 80vh; min-width: 610px; max-width: 100vw; min-height: 448px; max-height: 100vh; color: var(--text-normal); border-radius: 4px; background-color: var(--background-secondary); box-shadow: var(--elevation-stroke), var(--elevation-high); will-change: top, left, width, height; } +#undiscord .header .icon { cursor: pointer; } +#undiscord .window-body { height: calc(100% - 48px); } +#undiscord .sidebar { overflow: hidden scroll; overflow-y: auto; width: 270px; min-width: 250px; height: 100%; max-height: 100%; padding: 8px; background: var(--background-secondary); } +#undiscord .sidebar legend, +#undiscord .sidebar label { display: block; width: 100%; } +#undiscord .main { display: flex; max-width: calc(100% - 250px); background-color: var(--background-primary); flex-grow: 1; } +#undiscord.hide-sidebar .sidebar { display: none; } +#undiscord.hide-sidebar .main { max-width: 100%; } +#undiscord #logArea { font-family: Consolas, Liberation Mono, Menlo, Courier, monospace; font-size: 0.75rem; overflow: auto; padding: 10px; user-select: text; flex-grow: 1; flex-grow: 1; cursor: auto; } +#undiscord .tbar { padding: 8px; background-color: var(--background-secondary-alt); } +#undiscord .tbar button { margin-right: 4px; margin-bottom: 4px; } +#undiscord .footer { cursor: se-resize; padding-right: 30px; } +#undiscord .footer #progressPercent { padding: 0 1em; font-size: small; color: var(--interactive-muted); flex-grow: 1; } +.resize-handle { position: absolute; bottom: -15px; right: -15px; width: 30px; height: 30px; transform: rotate(-45deg); background: repeating-linear-gradient(0, var(--background-modifier-accent), var(--background-modifier-accent) 1px, transparent 2px, transparent 4px); cursor: nwse-resize; } /**** Elements ****/ - -#undiscord summary { - font-size: 16px; - font-weight: 500; - line-height: 20px; - position: relative; - overflow: hidden; - margin-bottom: 2px; - padding: 6px 10px; - cursor: pointer; - white-space: nowrap; - text-overflow: ellipsis; - color: var(--interactive-normal); - border-radius: 4px; - flex-shrink: 0; -} - -#undiscord fieldset { - padding-left: 8px; -} - -/* help link */ -#undiscord legend a { - float: right; - text-transform: initial; -} - -#undiscord progress { - height: 8px; - margin-top: 4px; - flex-grow: 1; - /* background-color: var(--background-primary); - border-radius: 3px; */ -} - -/* #undiscord progress::-webkit-progress-value{ - background-color: var(--brand-experiment); -} */ - -/**** functional classes ****/ - -#undiscord.redact .priv { - display: none !important; -} - -#undiscord:not(.redact) .mask { - display: none !important; -} - -#undiscord.redact [priv] { - -webkit-text-security: disc !important; -} - -#undiscord :disabled { - display: none; -} - -/**** layout misc ****/ - -#undiscord, -#undiscord * { - box-sizing: border-box; -} - -#undiscord .col { - display: flex; - flex-direction: column; -} - -#undiscord .row { - display: flex; - flex-direction: row; - align-items: center; -} - -#undiscord .mb1 { - margin-bottom: 8px; -} +#undiscord summary { font-size: 16px; font-weight: 500; line-height: 20px; position: relative; overflow: hidden; margin-bottom: 2px; padding: 6px 10px; cursor: pointer; white-space: nowrap; text-overflow: ellipsis; color: var(--interactive-normal); border-radius: 4px; flex-shrink: 0; } +#undiscord fieldset { padding-left: 8px; } +#undiscord legend a { float: right; text-transform: initial; } +#undiscord progress { height: 8px; margin-top: 4px; flex-grow: 1; } +#undiscord .importJson { display: flex; flex-direction: row; } +#undiscord .importJson button { margin-left: 5px; width: fit-content; } `); - var buttonHtml = (` + var buttonHtml = (`
- +
`); - var undiscordTemplate = (` + var undiscordTemplate = (`