MyAnimeList(MAL) - Com-to-Com Links

Add Com-to-Com link between user and comment user for every comment.

目前為 2023-06-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name MyAnimeList(MAL) - Com-to-Com Links
  3. // @version 1.2.0
  4. // @description Add Com-to-Com link between user and comment user for every comment.
  5. // @author Cpt_mathix & N_Ox
  6. // @match *://myanimelist.net/profile*
  7. // @match *://myanimelist.net/comments*
  8. // @exclude *://myanimelist.net/profile/*/*
  9. // @grant none
  10. // @namespace https://greasyfork.org/users/16080
  11. // ==/UserScript==
  12.  
  13. if (document.location.href.indexOf('profile') > -1) {
  14. var element = document.getElementById('lastcomment').getElementsByTagName('a');
  15. for (var i = 0; i < element.length; i++) {
  16. if (element[i] && element[i].innerHTML.indexOf("All Comments") > -1) {
  17. comtocom(element[i].href);
  18. break;
  19. }
  20. }
  21. } else {
  22. comtocom(document.location.href);
  23. }
  24.  
  25. function goToConversation(profile, url) {
  26. fetch(profile)
  27. .then(response => response.text())
  28. .then(text => {
  29. const parser = new DOMParser();
  30. const htmlDocument = parser.parseFromString(text, "text/html");
  31. const section = htmlDocument.documentElement.querySelector("#contentWrapper").innerHTML;
  32.  
  33. const regex = new RegExp(/type=profile&amp;id=(\d+)/g);
  34. const id = regex.exec(section)[1];
  35.  
  36. window.location.href = url + id;
  37. });
  38. }
  39.  
  40. function comtocom(url) {
  41. url = url.replace(/&*show=\d*/g, "");
  42. var i = url.indexOf('id=');
  43. if (i == -1) return;
  44. url = '/comtocom.php?id1=' + url.substr(i + 3) + '&id2=';
  45.  
  46. if (document.location.href.indexOf('profile') > -1) {
  47. document.querySelectorAll('div[id^=comBox]').forEach(function (el) {
  48. if (el.getElementsByClassName('postActions ar mt4').length !== 0) {
  49. return;
  50. }
  51.  
  52. var profile = el.querySelector('.image').href;
  53. if (!profile) return;
  54.  
  55. var div = document.createElement('div');
  56. div.className = 'postActions ar mt4 mr12';
  57. var link = document.createElement('a');
  58. link.innerHTML = "Conversation";
  59. link.href="#";
  60. link.onclick = (event) => {
  61. event.preventDefault();
  62. link.innerHTML = "Loading Conversation...";
  63.  
  64. goToConversation(profile, url);
  65. };
  66.  
  67. div.appendChild(link);
  68. el.appendChild(div);
  69. });
  70. } else {
  71. // console.log(document.querySelectorAll('div[id^=comBox] > table > tbody > tr'));
  72. // console.log(document.querySelectorAll('div[id^=comBox]'));
  73. document.querySelectorAll('div[id^=comBox] > table > tbody > tr').forEach(function (el) {
  74. var com = el.querySelector('div[id^=com]:not([id^=comtext])');
  75. if (!com) return;
  76. if (com.children.length == 3) return;
  77.  
  78. var profile = el.querySelector('.picSurround > a').href;
  79. if (!profile) return;
  80.  
  81. com.insertAdjacentHTML("beforeend", '<div style="margin-top:10px" align="right"><a href="#" class="conversation">Conversation</a></div>');
  82.  
  83. const link = com.querySelector(".conversation");
  84. link.onclick = (event) => {
  85. event.preventDefault();
  86. link.innerHTML = "Loading Conversation...";
  87.  
  88. goToConversation(profile, url);
  89. };
  90. });
  91. }
  92. }