Sonarr Link Adder

Adds links to specified series on the table view

目前為 2021-02-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Sonarr Link Adder
// @namespace    https://greasyfork.org/en/users/814-bunta
// @version      1.0
// @description  Adds links to specified series on the table view
// @author       Bunta
// @match        http://billy:8989/*
// @match        http://localhost:8989/*
// @license      http://creativecommons.org/licenses/by-nc-sa/3.0/us/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // define what links to add to series on the table list
    // these links will appear as icons to the right of the specified series' names
    // syntax: [Series Title, URL, icon]
    let tableLinks = [
        ['Attack on Titan', 'https://animekaizoku.com/attack-on-titan-the-final-season-40028/', 'https://animekaizoku.com/favicon.ico'],
        ['Black Clover', 'https://animekaizoku.com/black-clover-34572/', 'https://animekaizoku.com/favicon.ico'],
        ['Dr. Stone', 'https://animekaizoku.com/dr-stone-stone-wars-40852/', 'https://animekaizoku.com/favicon.ico'],
        ['Fire Force', 'https://animekaizoku.com/fire-force-season-2-40956/', 'https://animekaizoku.com/favicon.ico'],
        ['Jujutsu Kaisen', 'https://animekaizoku.com/jujutsu-kaisen-40748/', 'https://animekaizoku.com/favicon.ico'],
        ['One Piece', 'https://animekaizoku.com/one-piece-21/', 'https://animekaizoku.com/favicon.ico'],
        ['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'],
        ['The Promised Neverland', 'https://animekaizoku.com/the-promised-neverland-season-2-39617/', 'https://animekaizoku.com/favicon.ico']
    ];

    // define what links to add to the "Links" menu for all series
    // syntax: [Link Title, URL]
    // URL can use following substitutions:
    //    {title} - Series Title
    let seriesLinks = [
        ['Kaizoku', 'https://animekaizoku.com/?s={title}'],
        ['Bluray', 'https://www.blu-ray.com/movies/search.php?keyword={title}&action=search']
    ];

    var tableArray = [];
    tableLinks.forEach(item => {tableArray.push(item[0])});

    var seriesArray = [];
    seriesLinks.forEach(item => {seriesArray.push(item[0])});

    // Options for the observer (which mutations to observe: attributes, childList, subtree, characterData)
    const config = { attributes: true, childList: true, subtree: true };

    // Callback function to execute when mutations are observed
    const callback = function(mutationsList, observer) {

        // Use traditional 'for loops' for IE 11
        for(const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                //console.log('A child node has been added or removed.');
                //console.log(mutation)
                //console.log(mutation.target.classList)
                if (mutation.target.classList.length > 0) {
                    // Adding links to titles on series table view
                    if (tableLinks.length > 0 && (mutation.target.classList[0].startsWith('SeriesIndex/contentBodyContainer') || mutation.target.classList[0].startsWith('VirtualTableRow/row') || mutation.target.classList[0].startsWith('ReactVirtualized__Grid__innerScrollContainer')) ) {
                        $(mutation.target).find('a').filter(function() { return tableArray.includes($(this).text()) && $(this).parent().find('a').length < 2 }).each( function(index) {
                            //console.log( $( this ).text() );
                            tableLinks.forEach(item => {
                                if (item[0] == $(this).text())
                                    $( '<a href="' + item[1] + '" target="_blank"><img src="' + item[2] + '" width=30 height=20 style="padding:0 0 0 10px;">' ).insertAfter(this);
                            });
                        });

                    }

                    // Adding links to "Links" shortcuts on series view
                    if (seriesLinks.length > 0 && mutation.target.classList[0].contains('Tooltip/tooltipContainer/2693s')) {
                        var links = $(mutation.target).find('div.SeriesDetailsLinks\\/links\\/qbTXN');
                        if (links.length === 0) continue;
                        if (links.find('a').filter(function() { return seriesLinks.includes($(this).text()) }).length > 0) continue;
                        var seriesTitle = $('div.SeriesDetails\\/title\\/1yGfe').text();
                        seriesLinks.forEach(item => {
                            links.append( '<a target="_blank" href="'+item[1].replace('{title}', seriesTitle)+'" class="SeriesDetailsLinks/link/me2eE Link/link/1rgM9 Link/to/6fmSq"><span class="SeriesDetailsLinks/linkLabel/2GpRK Label/label/30Bqv Label/info/3YD3Y Label/large/1wO3D">'+item[0]+'</span></a>');
                        });
                    }
                }
            }
        }
    };

    // Create an observer instance linked to the callback function
    const observer = new MutationObserver(callback);

    // Start observing the target node for configured mutations
    observer.observe(document.body, config);

    // Later, you can stop observing
    //observer.disconnect();

})();