# Discourse close & archive topic userscript

**URL:** <https://meta.discourse.org/t/discourse-close-archive-topic-userscript/352211>\
**Category:** General\
**Created:** [February 14, 2025, 4:23am UTC](https://meta.discourse.org/t/discourse-close-archive-topic-userscript/352211 "2025-02-14T04:23:57Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [February 14, 2025, 6:07pm UTC](https://meta.discourse.org/t/discourse-close-archive-topic-userscript/352211/8 "2025-02-14T18:07:45Z")

</div>

Are you an admin or only a moderator? If you are admin, you could probably create a theme component instead of relying on a userscript.

That said, for sites on which you can’t edit the code, userscripts are still an interesting solution for various improvements.

I use them for many websites.

On [meta.discourse.org](http://meta.discourse.org), I have one that adds a Ctrl+Shift+k shortcut to wrap my selected text with `<kbd>` tags inside the composer 🙂

```js
// ==UserScript==
// @name <kbd> shortcut for meta.discourse.org
// @namespace Violentmonkey Scripts
// @version 1.0
// @description Insert <kbd> tags into textareas on meta.discourse.org with Ctrl + Shift + k
// @author chatGPT
// @match https://meta.discourse.org/*
// @grant none
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(event) {
        if (event.ctrlKey && event.shiftKey && event.key === 'K') {
            const activeElement = document.activeElement;
            if (activeElement.tagName === 'TEXTAREA' && activeElement.classList.contains('ember-text-area')) {
                const start = activeElement.selectionStart;
                const end = activeElement.selectionEnd;
                const text = activeElement.value;
                const insertText = '<kbd>';
                const closeText = '</kbd>';

                const selectedText = text.slice(start, end);
                activeElement.value = text.slice(0, start) + insertText + selectedText + closeText + text.slice(end);

                const cursorPosition = end === start
                    ? start + insertText.length
                    : start + insertText.length + selectedText.length + closeText.length;

                activeElement.selectionStart = activeElement.selectionEnd = cursorPosition;

                event.preventDefault();
            }
        }
    });
})();

```

Also, I don’t user Tampermonkey as it’s closed source, I prefer using open source software, and there are several contender (they all look the same and the scripts are cross-compatibles). I think the most used is [Violentmonkey](https://violentmonkey.github.io/).

---

_[View the full topic](https://meta.discourse.org/t/discourse-close-archive-topic-userscript/352211)._
