Advertisement
RobbiRobb

RelationFixer.js

May 25th, 2024 (edited)
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         RelationFixer
  3. // @namespace    https://myanimelist.net/profile/RobbiRobb
  4. // @version      0.4
  5. // @description  displays relations on anime and manga in a more classical layout because the official one sucks
  6. // @author       RobbiRobb
  7. // @match        https://myanimelist.net/anime/*
  8. // @match        https://myanimelist.net/manga/*
  9. // @match        https://myanimelist.net/anime.php?id=*
  10. // @match        https://myanimelist.net/manga.php?id=*
  11. // @icon         https://www.google.com/s2/favicons?sz=64&domain=myanimelist.net
  12. // @grant        none
  13. // @require      https://code.jquery.com/jquery-3.7.1.min.js
  14. // @updateURL    https://pastebin.com/raw/MTcrX0uZ
  15. // @downloadURL  https://pastebin.com/raw/MTcrX0uZ
  16. // ==/UserScript==
  17.  
  18. (function() {
  19.     'use strict';
  20.    
  21.     function appendList(relations, listElement) {
  22.         for(const key of Object.keys(relations).sort().reverse()) {
  23.             const row = $("<tr></tr>");
  24.             const typeTD = $('<td class="ar fw-n borderClass nowrap" valign="top"></td>').text(key + ":");
  25.             const listTD = $('<td class="borderClass" width="100%">');
  26.             const entryList = $('<ul class="entries"></ul>');
  27.            
  28.             for(const entry of relations[key]) {
  29.                 entryList.append($("<li></li>").html(entry.title.html() + entry.type));
  30.             }
  31.            
  32.             listTD.append(entryList);
  33.             row.append(typeTD);
  34.             row.append(listTD);
  35.            
  36.             $(listElement).prepend(row);
  37.         }
  38.     }
  39.  
  40.     if($(".entries-tile").length !== 0) {
  41.         const relations = {};
  42.        
  43.         $(".entries-tile .entry").each((index, el) => {
  44.             const type = $(el).find(".content .relation").text().trim();
  45.            
  46.             if(type == "") return;
  47.             if(relations[type.split("\n")[0].trim()] == undefined) relations[type.split("\n")[0].trim()] = [];
  48.            
  49.             relations[type.split("\n")[0].trim()].push({
  50.                 title: $(el).find(".content .title"),
  51.                 type: type.split("\n")[1].trim()
  52.             });
  53.         });
  54.        
  55.         if($(".entries-table > tbody").length == 0) {
  56.             const tbody = $('<tbody></tbody>');
  57.             appendList(relations, tbody);
  58.             const table = $('<table class="entries-table"></table>').append(tbody);
  59.            
  60.             $(".related-entries").each((index, el) => {
  61.                 $(el).append(table);
  62.             })
  63.         } else {
  64.             $(".entries-table > tbody").each((index, el) => {
  65.                 appendList(relations, el);
  66.             });
  67.         }
  68.     }
  69.    
  70.     const style = $("<style></style>").text(`
  71.         .related-entries .ar.mt4,
  72.         .entries-tile {
  73.             display: none !important;
  74.         }
  75.        
  76.         .entries-table .hide-entry {
  77.             display: table-row !important;
  78.         }
  79.     `);
  80.    
  81.     $(document.head).append(style);
  82. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement