MyAnimeList(MAL) - Com-to-Com Links

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

当前为 2015-10-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MyAnimeList(MAL) - Com-to-Com Links
  3. // @version 1.1.0
  4. // @description Add Com-to-Com link between user and comment user for every comment.
  5. // @author Cpt_mathix & N_Ox
  6. // @include http://myanimelist.net/profile*
  7. // @include http://myanimelist.net/comments*
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/16080
  10. // ==/UserScript==
  11.  
  12. if (document.location.href.indexOf('profile') > -1) {
  13. var element = document.getElementById('lastcomment').getElementsByTagName('a');
  14. for(var i = 0; i < element.length; i++) {
  15. if (element[i].innerHTML.indexOf("All Comments") > -1) {
  16. comtocom(element[i].href);
  17. break;
  18. }
  19. }
  20. } else
  21. comtocom(document.location.href);
  22.  
  23. function comtocom(url) {
  24. if (typeof jQuery == 'undefined') $ = unsafeWindow.$;
  25.  
  26. var i = url.indexOf('id=');
  27. if (i == -1) return;
  28. url = 'http://myanimelist.net/comtocom.php?id1=' + url.substr(i + 3) + '&id2=';
  29.  
  30. if (document.location.href.indexOf('profile') == -1) {
  31. $('div[id^=comBox] > table > tbody > tr').each(function () {
  32. var avatar = $('.picSurround img', this);
  33. if (!avatar.length) return;
  34.  
  35. var com = $('div[id^=com]:not([id^=comtext])', this);
  36. if (!com.length) return;
  37. if (com.children().length == 3) return;
  38.  
  39. var id = avatar.attr('src');
  40. var i = id.indexOf('thumbs/');
  41. if (i == -1) return;
  42. id = id.substr(i + 7, id.indexOf('_') - i - 7);
  43.  
  44. com.append(
  45. $('<div style="margin-top:10px" align="right"/>').append(
  46. $('<a title="Comment-to-Comment">Conversation</a>').attr('href', url + id)));
  47. });
  48. } else {
  49. $('div[id^=comBox]').each(function () {
  50. if (this.getElementsByClassName('postActions ar mt4').length != 0)
  51. return;
  52. var avatar = $('img', this);
  53. if (!avatar.length) return;
  54. var id = avatar.attr('src');
  55. var i = id.indexOf('userimages/');
  56. if (i == -1) return;
  57. id = id.substr(i + 11, id.indexOf('.jpg') - i - 11);
  58. var div = document.createElement('div');
  59. div.className = 'postActions ar mt4 mr12';
  60. var link = document.createElement('a');
  61. link.href = url + id;
  62. link.innerHTML = "Conversation";
  63. div.appendChild(link);
  64. this.appendChild(div);
  65. });
  66. }
  67. }