Sonarr & Radarr Link Adder

Adds links to specified series on the table view

当前为 2021-02-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Sonarr & Radarr Link Adder
  3. // @namespace https://greasyfork.org/en/users/814-bunta
  4. // @version 2.0
  5. // @description Adds links to specified series on the table view
  6. // @author Bunta
  7. // @include http://billy:8989/*
  8. // @include http://billy:7878/*
  9. // @include http://localhost:8989/*
  10. // @include http://localhost:7878/*
  11. // @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // define what links to add to series/movie on the table list
  19. // these links will appear as icons to the right of the specified series' or movies' names
  20. // syntax: [Title, URL, icon] Note: Title must match the series/movie title in the list
  21. let tableLinks = [
  22. ['Attack on Titan', 'https://animekaizoku.com/attack-on-titan-the-final-season-40028/', 'https://animekaizoku.com/favicon.ico'],
  23. ['Black Clover', 'https://animekaizoku.com/black-clover-34572/', 'https://animekaizoku.com/favicon.ico'],
  24. ['Dr. Stone', 'https://animekaizoku.com/dr-stone-stone-wars-40852/', 'https://animekaizoku.com/favicon.ico'],
  25. ['Fire Force', 'https://animekaizoku.com/fire-force-season-2-40956/', 'https://animekaizoku.com/favicon.ico'],
  26. ['Jujutsu Kaisen', 'https://animekaizoku.com/jujutsu-kaisen-40748/', 'https://animekaizoku.com/favicon.ico'],
  27. ['One Piece', 'https://animekaizoku.com/one-piece-21/', 'https://animekaizoku.com/favicon.ico'],
  28. ['That Time I Got Reincarnated as a Slime', 'https://animekaizoku.com/that-time-i-got-reincarnated-as-a-slime-season-2-39551/', 'https://animekaizoku.com/favicon.ico'],
  29. ['The Promised Neverland', 'https://animekaizoku.com/the-promised-neverland-season-2-39617/', 'https://animekaizoku.com/favicon.ico']
  30. ];
  31.  
  32. // define what links to add to the "Links" menu for all series/movies
  33. // syntax: [Link Title, URL]
  34. // URL can use following substitutions:
  35. // {title} - Link Title
  36. let menuLinks = [
  37. ['Kaizoku', 'https://animekaizoku.com/?s={title}'],
  38. ['AniDB', 'https://anidb.net/perl-bin/animedb.pl?show=animelist&adb.search={title}&do.search=search']
  39. ];
  40.  
  41. var tableArray = [];
  42. tableLinks.forEach(item => {tableArray.push(item[0])});
  43.  
  44. var menuArray = [];
  45. menuLinks.forEach(item => {menuArray.push(item[0])});
  46.  
  47. // Options for the observer (which mutations to observe: attributes, childList, subtree, characterData)
  48. const config = { attributes: true, childList: true, subtree: true };
  49.  
  50. // Callback function to execute when mutations are observed
  51. const callback = function(mutationsList, observer) {
  52.  
  53. // Use traditional 'for loops' for IE 11
  54. for(const mutation of mutationsList) {
  55. if (mutation.type === 'childList') {
  56. //console.log('A child node has been added or removed.');
  57. //console.log(mutation)
  58. //console.log(mutation.target.classList)
  59. if (mutation.target.classList.length > 0) {
  60. // Adding links to titles on series table view
  61. if (tableLinks.length > 0 && (mutation.target.classList[0].startsWith('MovieIndex-contentBodyContainer') || mutation.target.classList[0].startsWith('SeriesIndex/contentBodyContainer') || mutation.target.classList[0].startsWith('VirtualTableRow') || mutation.target.classList[0].startsWith('ReactVirtualized__Grid__innerScrollContainer')) ) {
  62. $(mutation.target).find('a').filter(function() { return tableArray.includes($(this).text()) && $(this).parent().find('a').length < 2 }).each( function(index) {
  63. //console.log( $( this ).text() );
  64. tableLinks.forEach(item => {
  65. if (item[0] == $(this).text())
  66. $( '<a href="' + item[1] + '" target="_blank"><img src="' + item[2] + '" width=30 height=20 style="padding:0 0 0 10px;">' ).insertAfter(this);
  67. });
  68. });
  69.  
  70. }
  71.  
  72. // Adding links to "Links" shortcuts on series view
  73. if (menuLinks.length > 0 && (mutation.target.classList[0].contains('Tooltip/tooltipContainer/2693s') || mutation.target.classList[0].contains('Tooltip-tooltipContainer-2693s'))) {
  74. var linkClass = 'SeriesDetailsLinks/link/me2eE Link/link/1rgM9 Link/to/6fmSq'
  75. var spanClass = 'SeriesDetailsLinks/linkLabel/2GpRK Label/label/30Bqv Label/info/3YD3Y Label/large/1wO3D'
  76. var links = $(mutation.target).find('div.SeriesDetailsLinks\\/links\\/qbTXN');
  77. if (links.length === 0) {
  78. linkClass = 'MovieDetailsLinks-link-e075L Link-link-1rgM9 Link-to-6fmSq'
  79. spanClass = 'MovieDetailsLinks-linkLabel-3_j9I Label-label-30Bqv Label-danger-1NOw3 Label-large-1wO3D'
  80. links = $(mutation.target).find('div.MovieDetailsLinks-links-ao5yb');
  81. }
  82. if (links.length === 0) continue;
  83. if (links.find('a').filter(function() { return menuArray.includes($(this).text()) }).length > 0) continue;
  84. var itemTitle = $('div.SeriesDetails\\/title\\/1yGfe,div.MovieDetails-title-2QKaN span').text();
  85. if (!itemTitle) continue;
  86. menuLinks.forEach(item => {
  87. links.append( '<a target="_blank" href="'+item[1].replace('{title}', itemTitle)+'" class="'+linkClass+'"><span class="'+spanClass+'">'+item[0]+'</span></a>');
  88. });
  89. }
  90. }
  91. }
  92. }
  93. };
  94.  
  95. // Create an observer instance linked to the callback function
  96. const observer = new MutationObserver(callback);
  97.  
  98. // Start observing the target node for configured mutations
  99. observer.observe(document.body, config);
  100.  
  101. // Later, you can stop observing
  102. //observer.disconnect();
  103.  
  104. })();