Greasy Fork

MyDramaList to Avistaz Search

Add a button to search dramas and movies on Avistaz from MyDramaList.

目前为 2024-12-13 提交的版本。查看 最新版本

// ==UserScript==
// @name         MyDramaList to Avistaz Search
// @namespace    https://mydramalist.com/
// @version      1.1
// @description  Add a button to search dramas and movies on Avistaz from MyDramaList.
// @author       ChatGPT
// @match        https://mydramalist.com/shows/*
// @match        https://mydramalist.com/movies/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Helper function to create the search button
    function createSearchButton(name, year, type) {
        const button = document.createElement('button');
        button.textContent = 'Search on Avistaz';
        button.style.marginLeft = '10px';
        button.style.padding = '5px 10px';
        button.style.backgroundColor = '#1E90FF';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';

        const query = encodeURIComponent(name);
        const url = `https://avistaz.to/${type}?search=${query}&year_start=${year}&year_end=${year}`;

        button.addEventListener('click', () => {
            window.open(url, '_blank');
        });

        return button;
    }

    function addSearchButtons(type) {
        const items = document.querySelectorAll('.box .box-body .content');
        items.forEach(item => {
            const titleElement = item.querySelector('.title a');
            const metadataElement = item.querySelector('.text-muted');

            if (titleElement && metadataElement) {
                const name = titleElement.textContent.trim();
                const yearMatch = metadataElement.textContent.match(/-\s(\d{4})/);

                if (yearMatch) {
                    const year = yearMatch[1];
                    const searchButton = createSearchButton(name, year, type);
                    titleElement.parentElement.appendChild(searchButton);
                }
            }
        });
    }

    // Add buttons for dramas and movies
    if (window.location.pathname.includes('/shows/')) {
        addSearchButtons('tv-shows');
    } else if (window.location.pathname.includes('/movies/')) {
        addSearchButtons('movies');
    }
})();