// ==UserScript==
// @name debianforum.de-quickmod-additions
// @namespace org.free.for.all
-// @include https://debianforum.de/forum/viewtopic.php.*
+// @include https://debianforum.de/forum/viewtopic.php*
+// @match https://debianforum.de/forum/viewtopic.php*
// @author Thorsten Sperber
-// @version 1.0
+// @author JTH
+// @version 1.1
// ==/UserScript==
-ARCHIVFORUMID = 35;
-boardurl = "/forum/";
+const ARCHIVFORUMID = 35;
+const boardurl = "/forum/";
-mod_user_id = "18865";
+let mod_user_id;
+
+function ellipsify(str, maxlen) {
+ let ell = str.length > maxlen ? " […]" : "";
+ return str.substring(0, maxlen - ell.length) + ell;
+}
function get_thread_id() {
return document.querySelector('a[href*="t="').getAttribute('href').match(/t=([0-9]+)/)[1];
function remove_post_handler(event) {
- var post_id = event.currentTarget.closest('.post').getAttribute('id').slice(1);
- var thread_title = document.querySelector('.topic-title a').text;
- send_mcp_request_archival(post_id, get_thread_id(), thread_title);
+ let post = event.currentTarget.closest('.post');
+ let post_id = post.getAttribute('id').slice(1);
+ let username = post.querySelector(".author .username,.author .username-coloured").text;
+ let thread_title = document.querySelector('.topic-title a').text;
+ let content = ellipsify(post.querySelector(".content").innerText, 250);
+ if (localStorage.getItem("deleteWithoutConfirmation") || window.confirm(`Folgenden Beitrag von „${username}“ im Thema „${ellipsify(thread_title, 100)}“ wirklich als Spam archivieren?\n\n„${content}“`)) {
+ send_mcp_request_archival(post_id, get_thread_id(), thread_title);
+ }
}
function send_mcp_request_confirmation(confirm_key, sess, sid, post_id, thread_id, thread_title) {
"sess": sess,
"sid": sid,
"start": "0",
- "subject": "[spam] " + thread_title,
+ "subject": thread_title.toLowerCase().includes("spam") ? thread_title : "[spam] " + thread_title,
"t": thread_id,
"to_forum_id": ARCHIVFORUMID
};
function send_mcp_request_archival(post_id, thread_id, thread_title) {
var req = new XMLHttpRequest();
+ // confirm when page has loaded
req.addEventListener("load", function() {
- // extract the confirmation ID, proceed
- // console.log(this.responseText);
var confirm_key = this.responseText.match(/confirm_key=([A-Z0-9]+)/)[1];
var sess = this.responseText.match(/name="sess" value="([a-z0-9]+)"/)[1];
var sid = this.responseText.match(/name="sid" value="([a-z0-9]+)"/)[1];
"sk": "t",
"sd": "a",
"icon": "1",
- "subject": "[spam] " + thread_title,
+ "subject": thread_title.toLowerCase().includes("spam") ? thread_title : "[spam] " + thread_title,
"to_forum_id": ARCHIVFORUMID,
"to_topic_id": "0",
"st_old": "0",
});
}
-add_buttons();
\ No newline at end of file
+function find_mod_user_id() {
+ let profile_link = document.querySelector("#username_logged_in a[title^='Profil']");
+ return Number.parseInt(new URLSearchParams(profile_link?.search).get("u"));
+}
+
+mod_user_id ??= find_mod_user_id();
+if (Number.isInteger(mod_user_id)) {
+ add_buttons();
+} else {
+ console.error("mod_user_id unset and could not find user ID");
+}
\ No newline at end of file