luogu-chat-delete

洛谷删除私信脚本。

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         luogu-chat-delete
// @match        https://www.luogu.com.cn/chat
// @description  洛谷删除私信脚本。
// @require      https://cdn.luogu.com.cn/js/jquery-2.1.1.min.js
// @version 0.0.1.20230528045348
// @namespace https://greatest.deepsurf.us/users/1085576
// ==/UserScript==
function delete_chat(id, csrf) {
    $.ajax({
        url: 'https://www.luogu.com.cn/api/chat/delete',
        type: 'post',
        dataType: 'json',
        data: JSON.stringify({id: id}),
        cache: false,
        headers: {
            'Content-Type': 'application/json',
            'x-csrf-token': csrf
        },
        xhrFields: {
      withCredentials: true
    }
    });
}

function do_delete(uid, csrf) {
    $.get('https://www.luogu.com.cn/api/chat/record?user=' + uid, {}, function (res) {
        console.log(res);
        var t = res['messages']['result'];
        for (var i = 0; i < t.length; i++) {
            console.log(t[i].id + ' ' + t[i].content);
            delete_chat(t[i].id, csrf);
        }
    })
}

(function() {
    'use strict';
    window.onload = function () {
        var csrf = document.getElementsByName('csrf-token')[0].content;
        console.log(csrf);
        if (csrf == null || csrf == undefined) {
            alert('获取x-csrf-token失败!');
            return;
        }
        var name = prompt('请输入要删除私信的uid或用户名:');
        if (name == null || name == undefined) return;
        $.get('https://www.luogu.com.cn/api/user/search?keyword=' + name, {}, function (res) {
            var users = res['users'];
            for (var i = 0; i < users.length; i++) {
                if (users[i] != null) {
                    console.log(users[i]['uid'] + ' ' + users[i]['name']);
                    do_delete(users[i]['uid'], csrf);
                }
            }
        })
    }
})();