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