Better MxRP

An enhancement suite for MxRP

安装此脚本
作者推荐脚本

您可能也喜欢MxRP Felt

安装为用户样式
  1. // ==UserScript==
  2. // @name Better MxRP
  3. // @namespace http://oxeff.xyz/
  4. // @version 0.4.4
  5. // @description An enhancement suite for MxRP
  6. // @author 0xEFF <dez@oxeff.xyz> (https://github.com/hecksadecimal)
  7. // @match https://mxrp.chat/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var $ = window.jQuery;
  14.  
  15. // The lists at /chats
  16. var group_chats = $("#group_chats");
  17. if (group_chats.length) {
  18. $("#group_chats li").each(function() {
  19. // Contains everything we need.
  20. var meta_info = $(this).find("p:nth-child(2) > a:nth-child(1)");
  21. if (meta_info.html() == "Searched" || window.location.pathname == "/chats/searched"){
  22. // Searched chat IDs follow a predictable schema.
  23. var chat_id = $(this).find("h3:nth-child(1) > a:nth-child(1)").html();
  24. console.log("Found Searched chat: " + chat_id);
  25.  
  26. // Button setup
  27. $(this).find("form").before('<button id="better_rename_' + chat_id +'" class="unsubscribe" style="float: left; margin-right: 5px;">Rename</button>');
  28. var searched_rename_button = $("#better_rename_" + chat_id);
  29. searched_rename_button.after('<button id="better_description_' + chat_id + '" class="unsubscribe" style="float: left;">Set Description</button>');
  30. var searched_description_button = $("#better_description_" + chat_id);
  31.  
  32. // Can't use $(this) in the context of a button press event to achieve the desired results. Need a mirror of the current $(this).
  33. var current_item = $(this);
  34. searched_rename_button.click(function() {
  35. var rename_value = prompt("Name (Empty to reset)", current_item.find("h3:nth-child(1) > a:nth-child(1)").html());
  36. if (rename_value) {
  37. window.localStorage.setItem("name_" + chat_id, rename_value);
  38. current_item.find("h3:nth-child(1) > a:nth-child(1)").html(rename_value);
  39. } else if (rename_value === "") {
  40. window.localStorage.removeItem("name_" + chat_id);
  41. current_item.find("h3:nth-child(1) > a:nth-child(1)").html(chat_id);
  42. } else {
  43. return;
  44. }
  45. });
  46. searched_description_button.click(function() {
  47. var desc_value = prompt("Description (Empty to reset)", current_item.find(".desc").html());
  48. if (desc_value) {
  49. window.localStorage.setItem("desc_" + chat_id, desc_value);
  50. current_item.find(".desc").html(desc_value);
  51. } else if (desc_value === "" ){
  52. window.localStorage.removeItem("desc_" + chat_id);
  53. current_item.find(".desc").html("");
  54. } else {
  55. return;
  56. }
  57. });
  58. var chat_name = window.localStorage.getItem("name_" + chat_id);
  59. if (chat_name) {
  60. $(this).find("h3:nth-child(1) > a:nth-child(1)").html(chat_name);
  61. }
  62. var chat_desc = window.localStorage.getItem("desc_" + chat_id);
  63. if (chat_desc) {
  64. $(this).find(".desc").html(chat_desc);
  65. }
  66. }
  67. });
  68. }
  69.  
  70. // The lists that shows up when you're currently in a chat page.
  71. var group_chats_mini = $("#my_chats_list");
  72. if (group_chats_mini.length) {
  73. // Have to do it this way because the list is not populated by the time the page is loaded.
  74. group_chats_mini.bind('DOMSubtreeModified', function(e) {
  75. for (var i=0; i < e.target.children.length; i++) {
  76. if (e.target.children[i].classList.contains("searched")){
  77. var chat_id = e.target.children[i].children[0].children[0].innerHTML;
  78. console.log("Found Searched chat: " + chat_id);
  79. var chat_name = window.localStorage.getItem("name_" + chat_id);
  80. if (chat_name) {
  81. e.target.children[i].children[0].children[0].innerHTML = chat_name;
  82. }
  83. }
  84. }
  85. });
  86. }
  87.  
  88. function paraInputHandler(e) {
  89. if (e.keyCode == 13 && !e.shiftKey) {
  90. $("#button_wrap > button:nth-child(1)").click();
  91. $("#chat_line_input > input[type=text]").keydown();
  92. $("#parainput").val("");
  93. $("#chat_line_input > input[type=text]").val("");
  94. $("#chat_line_input > input[type=text]").keyup();
  95. } else {
  96. var unclean_str = $("#parainput").val();
  97. unclean_str = unclean_str.replace(/(?:\r\n|\r|\n){2}/g, '[br] [br]');
  98. unclean_str = unclean_str.replace(/(?:\r\n|\r|\n)/g, '[br]');
  99. $("#chat_line_input > input[type=text]").keydown();
  100. $("#chat_line_input > input[type=text]").val(unclean_str);
  101. $("#chat_line_input > input[type=text]").keyup();
  102. }
  103. }
  104. var paragraph_mode_saved = window.localStorage.getItem("paramode_" + $(location).attr('pathname'));
  105. if (!paragraph_mode_saved) {
  106. paragraph_mode_saved = "script"
  107. }
  108.  
  109.  
  110. function toggleTextbox() {
  111. console.log("smart_quirk_mode: " + paragraph_mode_saved);
  112. if (paragraph_mode_saved == "paragraph") {
  113. $("#chat_line_input > input[type=text]").hide();
  114. $("#parainput").show();
  115. } else if (paragraph_mode_saved == "script") {
  116. $("#chat_line_input > input[type=text]").show();
  117. $("#parainput").hide();
  118. $("#conversation").css({"bottom": "59px"});
  119. } else {
  120. $("#chat_line_input > input[type=text]").show();
  121. $("#parainput").hide();
  122. $("#conversation").css({"bottom": "59px"});
  123. }
  124. try {
  125. $("#chat_line_input > input[type=text]").keydown();
  126. $("#chat_line_input > input[type=text]").keyup();
  127. } catch(err) {
  128. console.log("Likely error due to unready websocket. Ignore.")
  129. }
  130. }
  131.  
  132. function setupTextbox() {
  133. $("#chat_line_input > input[type=text]").after('<textarea id="parainput" name="text" autocomplete="off" maxlength="10000">');
  134. $("#parainput").css({"min-height": "5em", "max-height": "100vh", "margin": "0 -2px 5px"});
  135. $("#conversation").css({"bottom": "59px"});
  136. $("#parainput").on("change keyup paste", paraInputHandler);
  137. toggleTextbox();
  138. }
  139.  
  140. var mode_selector = $("#smart_quirk_select");
  141. if (mode_selector.length) {
  142. $("#settings > div > div:nth-child(4) > div:nth-child(9) > p").after('<p><input type="checkbox" id="chat_better_entry" class="chat_settings" name="chat_better_entry"><label for="chat_better_entry"> BMXrP: Enable paragraph box</label></p>');
  143. paragraph_mode_saved = window.localStorage.getItem("paramode_" + $(location).attr('pathname'));
  144. console.log(paragraph_mode_saved)
  145. if (paragraph_mode_saved == "paragraph") {
  146. $('#chat_better_entry').prop('checked', true);
  147. } else {
  148. $('#chat_better_entry').prop('checked', false);
  149. }
  150.  
  151. setupTextbox();
  152. $("#chat_better_entry").change(function() {
  153. console.log($('#chat_better_entry').is(":checked"))
  154. paragraph_mode_saved = ($('#chat_better_entry').is(":checked") ? "paragraph" : "script");
  155. window.localStorage.setItem("paramode_" + $(location).attr('pathname'), paragraph_mode_saved);
  156. $("#chat_line_input input").trigger( "keyup" );
  157. toggleTextbox();
  158. });
  159. }
  160.  
  161. var abscond_button = $("#abscond_button");
  162. if (abscond_button.length) {
  163. var might_abscond = false;
  164. var did_abscond = false;
  165. // The confirmation dialogue is both ugly and slow.
  166. window.confirm = function() { return true; };
  167.  
  168. // We can create our own button to add functionality and delegate the vanilla behavior of disconnects to the original button
  169. // since we can't directly interact with any function that's a part of mxrp's scripts.
  170. abscond_button.hide();
  171. abscond_button.after( '<button type="button" id="better_abscond_button">Abscond</button>' );
  172. var better_abscond_button = $("#better_abscond_button");
  173. $(document).keydown(function(e) {
  174. if (e.key === "Escape") {
  175. better_abscond_button.trigger("click");
  176. }
  177. });
  178. better_abscond_button.click(function() {
  179. if (!might_abscond){
  180. might_abscond = true;
  181. better_abscond_button.html("[5] Abscond?");
  182. better_abscond_button.css('background-color','red');
  183. var seconds = 5;
  184. $('input[name="text"]').css("width", "97%");
  185. better_abscond_button.html("[" + seconds + "] Abscond?");
  186. var countdown = window.setInterval(function() {
  187. seconds = seconds - 1;
  188. better_abscond_button.html("[" + seconds + "] Abscond?");
  189. if (seconds === 0 && !did_abscond) {
  190. window.clearInterval(countdown);
  191. might_abscond = false;
  192. better_abscond_button.html("Abscond");
  193. better_abscond_button.removeAttr("style");
  194. $('input[name="text"]').removeAttr("style");
  195. }
  196. }, 1000);
  197. } else {
  198. did_abscond = true;
  199. abscond_button.trigger("click");
  200. abscond_button.show();
  201. better_abscond_button.hide();
  202. window.clearInterval(countdown);
  203. }
  204. });
  205. }
  206. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址