Sonarr Link Adder

Adds links to specified series on the table view

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

  1. // ==UserScript==
  2. // @name Sonarr Link Adder
  3. // @namespace https://greasyfork.org/en/users/814-bunta
  4. // @version 0.2
  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 the page
  17. // [Series Title, URL, icon]
  18. let newlinks = [
  19. ['Attack on Titan', 'https://animekaizoku.com/attack-on-titan-the-final-season-40028/', 'https://animekaizoku.com/favicon.ico'],
  20. ['One Piece', 'https://animekaizoku.com/one-piece-21/', 'https://animekaizoku.com/favicon.ico'],
  21. ['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'],
  22. ['The Promised Neverland', 'https://animekaizoku.com/the-promised-neverland-season-2-39617/', 'https://animekaizoku.com/favicon.ico'],
  23. ['Fire Force', 'https://animekaizoku.com/fire-force-season-2-40956/', 'https://animekaizoku.com/favicon.ico']
  24. ];
  25.  
  26. var myarray = [];
  27. newlinks.forEach(item => {myarray.push(item[0])});
  28.  
  29. // Select the node that will be observed for mutations
  30. const targetNode = $('div[class^="PageContent"]')[0];
  31.  
  32. // Options for the observer (which mutations to observe)
  33. const config = { attributes: true, childList: true, subtree: true };
  34.  
  35. // Callback function to execute when mutations are observed
  36. const callback = function(mutationsList, observer) {
  37.  
  38. // Use traditional 'for loops' for IE 11
  39. for(const mutation of mutationsList) {
  40. if (mutation.type === 'childList') {
  41. //console.log('A child node has been added or removed.');
  42. //console.log(mutation.target)
  43. //console.log(mutation.target.classList)
  44. if (mutation.target.classList.length > 0) {
  45. if (mutation.target.classList[0].startsWith("SeriesIndex/contentBodyContainer") || mutation.target.classList[0].startsWith("VirtualTableRow/row") || mutation.target.classList[0].startsWith("ReactVirtualized__Grid__innerScrollContainer") ) {
  46. $(mutation.target).find("a").filter(function() { return myarray.includes($(this).text()) && $(this).parent().find('a').length < 2 }).each( function(index) {
  47. //console.log( $( this ).text() );
  48. newlinks.forEach(item => {
  49. if (item[0] == $(this).text())
  50. $( '<a href="' + item[1] + '" target="_blank"><img src="' + item[2] + '" width=30 height=20 style="padding:0 0 0 10px;">' ).insertAfter(this);
  51. });
  52. });
  53.  
  54. }
  55. }
  56. }
  57. }
  58. };
  59.  
  60. // Create an observer instance linked to the callback function
  61. const observer = new MutationObserver(callback);
  62.  
  63. // Start observing the target node for configured mutations
  64. observer.observe(document.body, config);
  65.  
  66. // Later, you can stop observing
  67. //observer.disconnect();
  68.  
  69. })();