luogu-chat-delete

洛谷删除私信脚本。

  1. // ==UserScript==
  2. // @name luogu-chat-delete
  3. // @match https://www.luogu.com.cn/chat
  4. // @description 洛谷删除私信脚本。
  5. // @require https://cdn.luogu.com.cn/js/jquery-2.1.1.min.js
  6. // @version 0.0.1.20230528045348
  7. // @namespace https://greatest.deepsurf.us/users/1085576
  8. // ==/UserScript==
  9. function delete_chat(id, csrf) {
  10. $.ajax({
  11. url: 'https://www.luogu.com.cn/api/chat/delete',
  12. type: 'post',
  13. dataType: 'json',
  14. data: JSON.stringify({id: id}),
  15. cache: false,
  16. headers: {
  17. 'Content-Type': 'application/json',
  18. 'x-csrf-token': csrf
  19. },
  20. xhrFields: {
  21.       withCredentials: true
  22.     }
  23. });
  24. }
  25.  
  26. function do_delete(uid, csrf) {
  27. $.get('https://www.luogu.com.cn/api/chat/record?user=' + uid, {}, function (res) {
  28. console.log(res);
  29. var t = res['messages']['result'];
  30. for (var i = 0; i < t.length; i++) {
  31. console.log(t[i].id + ' ' + t[i].content);
  32. delete_chat(t[i].id, csrf);
  33. }
  34. })
  35. }
  36.  
  37. (function() {
  38. 'use strict';
  39. window.onload = function () {
  40. var csrf = document.getElementsByName('csrf-token')[0].content;
  41. console.log(csrf);
  42. if (csrf == null || csrf == undefined) {
  43. alert('获取x-csrf-token失败!');
  44. return;
  45. }
  46. var name = prompt('请输入要删除私信的uid或用户名:');
  47. if (name == null || name == undefined) return;
  48. $.get('https://www.luogu.com.cn/api/user/search?keyword=' + name, {}, function (res) {
  49. var users = res['users'];
  50. for (var i = 0; i < users.length; i++) {
  51. if (users[i] != null) {
  52. console.log(users[i]['uid'] + ' ' + users[i]['name']);
  53. do_delete(users[i]['uid'], csrf);
  54. }
  55. }
  56. })
  57. }
  58. })();