Greasy Fork

Greasy Fork is available in English.

Кнопка перехода на Flicksbar из Kinorium (без использования API Кинопоиска)

Ищет фильм в Google и автоматически переходит на Flicksbar без использования API Кинопоиска

当前为 2025-04-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Кнопка перехода на Flicksbar из Kinorium (без использования API Кинопоиска)
// @namespace    http://tampermonkey.net/
// @version      0.9.8
// @description  Ищет фильм в Google и автоматически переходит на Flicksbar без использования API Кинопоиска
// @author       CgPT & Vladimir_0202
// @icon         https://ru.kinorium.com/favicon.ico
// @match        *://*.kinorium.com/*
// @match        *://www.google.com/search*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const url = window.location.href;

    // === 1. KINORIUM: Добавляем кнопку на страницу фильма ===
    if (/kinorium\.com\/\d+\/?$/.test(url)) {
        function getFilmDetails() {
            const titleElement = document.querySelector('.film-page__title-text.film-page__itemprop');
            const originalTitleElement = document.querySelector('.film-page__orig_with_comment');
            const typeLink = document.querySelector('.b-post__info a[href*="/series/"]');
            const yearElement = document.querySelector('.film-page__date a[href*="years_min="]');
            const title = titleElement ? titleElement.textContent.trim() : '';
            const originalTitle = originalTitleElement ? originalTitleElement.textContent.trim() : '';
            const year = yearElement ? yearElement.textContent.trim() : '';
            const isSeries = typeLink !== null;
            return { title, originalTitle, year, isSeries };
        }

        function createButton() {
            const button = document.createElement('button');
            button.innerHTML = '<span style="display:inline-flex; align-items:center; justify-content:center; width:20px; height:22px; margin-right:8px; border:2px solid white; border-radius:50%; font-size:12px; padding-left:2px;">▶</span>Смотреть на Flicksbar';
            button.style.cssText = `
                padding: 9px;
                margin-top: -5px;
                margin-bottom: 2px;
                background-color: #007bff;
                color: white;
                border: none;
                border-radius: 3px;
                width: 100%;
                cursor: pointer;
                transition: background-color 0.3s ease;
            `;

            button.addEventListener('mouseenter', () => button.style.backgroundColor = '#0056b3');
            button.addEventListener('mouseleave', () => button.style.backgroundColor = '#007bff');

            const { title, originalTitle, year } = getFilmDetails();
            button.title = `Смотреть "${title} ${originalTitle} ${year}" бесплатно онлайн на Flicksbar`;

            button.onclick = () => {
                const { title, originalTitle, year, isSeries } = getFilmDetails();
                if (!title) return alert('Не удалось извлечь информацию о фильме.');
                const searchQuery = encodeURIComponent(`${title} ${originalTitle} ${year} кинопоиск`);
                const flicksbarType = isSeries ? 'series' : 'film';
                const googleUrl = `https://www.google.com/search?q=${searchQuery}&btnK&flcks_type=${flicksbarType}`;
                window.open(googleUrl, '_blank');
            };

            const sideCover = document.querySelector('.collectionWidget.collectionWidgetData.withFavourites');
            if (sideCover) sideCover.appendChild(button);
            else console.warn('Элемент для вставки кнопки не найден.');
        }

        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', createButton);
        } else {
            createButton();
        }
    }

    // === 2. GOOGLE: Автопереход на Flicksbar по найденному ID Кинопоиска ===
    if (/google\.com\/search/.test(url)) {
        function showConfirmWithTimeout(flicksbarUrl, timeout = 5000) {
            return new Promise((resolve) => {
                const modal = document.createElement('div');
                Object.assign(modal.style, {
                    position: 'fixed',
                    top: '50%',
                    left: '50%',
                    transform: 'translate(-50%, -50%)',
                    padding: '20px',
                    backgroundColor: '#EEE8AA',
                    border: '1px solid #ccc',
                    zIndex: '9999',
                    boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
                    borderRadius: '8px',
                });

                const message = document.createElement('p');
                message.style.color = 'black';
                message.innerHTML = `<b>Переход на Flicksbar</b> <br><br>Перейти по ссылке: <b>${flicksbarUrl}</b> ?`;
                modal.appendChild(message);

                const okButton = document.createElement('button');
                okButton.textContent = 'Да';
                Object.assign(okButton.style, {
                    marginRight: '10px',
                    padding: '5px 10px',
                    backgroundColor: '#28a745',
                    color: 'white',
                    border: 'none',
                    cursor: 'pointer',
                    borderRadius: '5px',
                });
                okButton.onclick = () => {
                    resolve(true);
                    modal.remove();
                };
                modal.appendChild(okButton);

                const cancelButton = document.createElement('button');
                cancelButton.textContent = 'Нет';
                Object.assign(cancelButton.style, {
                    padding: '5px 10px',
                    backgroundColor: '#dc3545',
                    color: 'white',
                    border: 'none',
                    cursor: 'pointer',
                    borderRadius: '5px',
                });
                cancelButton.onclick = () => {
                    resolve(false);
                    modal.remove();
                };
                modal.appendChild(cancelButton);

                document.body.appendChild(modal);

                setTimeout(() => {
                    resolve(false);
                    modal.remove();
                }, timeout);
            });
        }

        async function tryRedirect() {
            const kpLink = document.querySelector('a[href*="kinopoisk.ru/film/"]');
            if (!kpLink) return;
            const match = kpLink.href.match(/kinopoisk\.ru\/film\/(\d+)/);
            if (!match) return;

            const kpId = match[1];
            const urlParams = new URLSearchParams(window.location.search);
            const type = urlParams.get('flcks_type') || 'film';
            const flicksbarUrl = `https://flicksbar.mom/${type}/${kpId}/`;

            const answer = await showConfirmWithTimeout(flicksbarUrl, 5000); //чтобы производился Автопереход без окно запроса, то закоментирвать это!
            if (answer) window.location.href = flicksbarUrl; //и это закоментирвать
            else console.log('Переход отменен пользователем или истек таймаут.'); //и вот это закоментирвать
            //window.location.href = flicksbarUrl; // А это раскомментировать!
        }

        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', tryRedirect);
        } else {
            tryRedirect();
        }
    }
})();