# 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:** 1

<div class="post-metadata">

**Author:** ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)\
**Post date:** [February 14, 2025, 4:23am UTC](https://meta.discourse.org/t/discourse-close-archive-topic-userscript/352211/1 "2025-02-14T04:23:57Z")

</div>

(Maybe could fit in #Development, but shoved it here since I wasn’t sure)

While cleaning up my inbox on forum I manage a bit by closing and archiving old group membership request PMs, I got annoyed with doing it manually.

I hereby present the userscript to do it for you! You just right click, go to the “Tampermonkey” option, then run the “Close and Archive” script!

Code:

```javascript
// ==UserScript==
// @name Close and Archive
// @namespace http://tampermonkey.net/
// @version 2025-02-14
// @description Closes and Archives the currently open topic/private message when run
// @author Firepup Sixfifty
// @match https://=hostname=/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=amcforum.wiki
// @grant none
// @run-at context-menu
// ==/UserScript==

(function() {
    'use strict';

    fetch(`https://${window.location.hostname}/t/${window.location.pathname.split('/')[3]}/status`, {
        "headers": {
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "accept": "application/json",
            "x-csrf-token": document.querySelector("[name='csrf-token']").content
        },
        "body": "status=closed&enabled=true",
        "method": "PUT"
    }).then((r)=>{
        fetch(`https://${window.location.hostname}/t/${window.location.pathname.split('/')[3]}/status`, {
            "headers": {
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "accept": "application/json",
                "x-csrf-token": document.querySelector("[name='csrf-token']").content
            },
            "body": "status=archived&enabled=true",
            "method": "PUT"
        }).then((r)=>{
            fetch(`https://${window.location.hostname}/t/${window.location.pathname.split('/')[3]}/archive-message`, {
                "headers": {
                    "accept": "application/json",
                    "x-csrf-token": document.querySelector("[name='csrf-token']").content
                },
                "method": "PUT"
            });
        })
    })
})();

```

---

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