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