MyAnimeList(MAL) - Preview BBCODE

This script will add the MAL BBCODE Editor where it is currently not enabled.

  1. // ==UserScript==
  2. // @name MyAnimeList(MAL) - Preview BBCODE
  3. // @version 1.0.4
  4. // @description This script will add the MAL BBCODE Editor where it is currently not enabled.
  5. // @author Cpt_mathix
  6. // @match https://myanimelist.net/*
  7. // @grant none
  8. // @run-at document-body
  9. // @namespace https://greasyfork.org/users/16080
  10. // ==/UserScript==
  11.  
  12. init();
  13.  
  14. function init() {
  15. if (document.location.href.includes("myanimelist.net/clubs.php?action=create")
  16. || document.location.href.includes("myanimelist.net/editclub.php")) {
  17. resizeDialog();
  18.  
  19. // Create/Edit Club Description
  20. transformTextArea('textarea[name="club_description"]');
  21. return;
  22. }
  23.  
  24. if (document.location.href.includes("myanimelist.net/clubs")) {
  25. // Club Comments
  26. transformTextArea("form.form-club-user-comment textarea");
  27. return;
  28. }
  29.  
  30. if (document.location.href.includes("myanimelist.net/blog.php")) {
  31. // Blog Comments
  32. transformTextArea(".blog_detail_comment_wrapper form textarea");
  33. return;
  34. }
  35.  
  36. if (document.location.href.includes("myanimelist.net/myblog.php")) {
  37. resizeDialog();
  38.  
  39. // Blog Entry
  40. transformTextArea("#blogForm textarea[name=\"entry_text\"");
  41. return;
  42. }
  43.  
  44. if (document.location.href.includes("myanimelist.net/editprofile.php")) {
  45. // Profile About Me
  46. transformTextArea("#content form textarea[name=\"profile_aboutme\"", (textarea) => {
  47. textarea.insertAdjacentHTML("afterend", "<small><b>You can also preview bbcode with: <a href='https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/'>https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/</a><b></small>");
  48. });
  49. return;
  50. }
  51.  
  52. if (document.location.href.includes("myanimelist.net/ownlist/manga")) {
  53. resizeDialog();
  54.  
  55. // Edit Manga Notes
  56. transformTextArea("#add_manga_comments");
  57. return;
  58. }
  59.  
  60. if (document.location.href.includes("myanimelist.net/ownlist/anime")) {
  61. resizeDialog();
  62.  
  63. // Edit Anime Notes
  64. transformTextArea("#add_anime_comments");
  65. return;
  66. }
  67. }
  68.  
  69. function transformTextArea(selector, action) {
  70. var textarea = document.querySelector(selector);
  71. if (textarea) {
  72. textarea.classList.add("bbcode-message-editor");
  73. textarea.rows = 15;
  74.  
  75. if (action) {
  76. action(textarea);
  77. }
  78. }
  79. }
  80.  
  81. function resizeDialog() {
  82. var dialog = document.getElementById("dialog");
  83. if (dialog) {
  84. if (document.location.href.includes("hideLayout=1")){
  85. var clientWidth = document.body.clientWidth;
  86. dialog.style.width = clientWidth + "px";
  87. } else {
  88. dialog.style.width = "804px";
  89. }
  90. }
  91. }