Sonarr Link Adder

Adds links to specified series on the table view

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

(function() {
    'use strict';

    // define what links to add to the page
    // [Series Title, URL, icon]
    let newlinks = [
        ['Attack on Titan', 'https://animekaizoku.com/attack-on-titan-the-final-season-40028/', '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'],
        ['Fire Force', 'https://animekaizoku.com/fire-force-season-2-40956/', 'https://animekaizoku.com/favicon.ico']
    ];

    var myarray = [];
    newlinks.forEach(item => {myarray.push(item[0])});

    // Select the node that will be observed for mutations
    const targetNode = $('div[class^="PageContent"]')[0];

    // Options for the observer (which mutations to observe)
    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.target)
                //console.log(mutation.target.classList)
                if (mutation.target.classList.length > 0) {
                    if (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 myarray.includes($(this).text()) && $(this).parent().find('a').length < 2 }).each( function(index) {
                            //console.log( $( this ).text() );
                            newlinks.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);
                            });
                        });

                    }
                }
            }
        }
    };

    // 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();

})();