Raw Source
bbaronSVK / SCintegracia

// ==UserScript==
// @name SCintegracia
// @license MIT
// @namespace https://stream-cinema.online/
// @downloadURL https://stream-cinema.online/widget/csfd.js
// @updateURL https://openuserjs.org/meta/bbaronSVK/SCintegracia.meta.js
// @version 1.2
// @description Integracia SC do csfd, imdb a trakt
// @author Me
// @match https://www.csfd.cz/film/*
// @match https://www.csfd.cz/zebricky/*
// @match https://www.csfd.cz/podrobne-vyhledavani/*
// @match https://www.csfd.sk/film/*
// @match https://www.csfd.sk/zebricky/*
// @match https://www.csfd.sk/podrobne-vyhladavanie/*
// @match https://www.imdb.com/title/*
// @match https://trakt.tv/*
// @esversion: 6
// @grant none
// ==/UserScript==
/* jshint esversion: 6 */
/* globals $, jQuery */

'use strict';

var vurl = null;
var pushState = history.pushState;
var timeout = null;
var level = 0;
history.pushState = function () {
    pushState.apply(history, arguments);
    console.log('zmena URL');
    level = 0;
    scIntegrate();
};
function cmajzniZoznam(zlodej) {
    let zoznam = [];
    $(zlodej + ' a').each((e, a) => {
        let match = $(a).attr('href').match(/film\/([0-9]+)\-/);
        if (match[1] > 0) {
            $(zlodej, $(a).closest('tr')).attr('data-sc', match[1]);
            zoznam.push(match[1]);
        }
    });
    return zoznam;
}
function scIntegrate() {
    const href = window.location.href;
    console.log('[SC] integracia %o', href);
    if (href.indexOf('trakt.tv') > 0) {
        if (href.indexOf('movie') || href.indexOf('shows')) {
            var data = $('.summary-user-rating').data();
            console.log('data: %o', data);
            if (data && (data.type == 'show' || data.type == 'episode')) {
                vurl = 'https://stream-cinema.online/widget/csfd?t=3;g=' + encodeURIComponent(data.showId);
            }
            else if (data) {
                vurl = 'https://stream-cinema.online/widget/csfd?t=1;g=' + encodeURIComponent(data.movieId);
            }
            else {
                console.log('[SC] nemam data');
                if (timeout) {
                    clearTimeout(timeout);
                }
                if (level < 10) {
                    timeout = setTimeout(scIntegrate, 250);
                    level++;
                }
                return;
            }
            console.log(vurl);
        }
    } else if (href.match(/csfd.(cz|sk)/) != -1 && (href.match(/[zr]ebricky|\/podrobne\-vyhl[ea]davanie?/) !== null)) {
        let zoznam = [];
        zoznam = cmajzniZoznam('td.title');
        if (zoznam.length == 0) {
            zoznam = cmajzniZoznam('td.name');
        }
        console.log('[SC] zoznam: %o', zoznam);
        $.ajax('//stream-cinema.online/widget/ajax?g=list', {
            data: {list: zoznam},
            type: 'POST',
            success: (r) => {
                r.forEach(e => {
                    $('td[data-sc="' + e + '"] h3').prepend('<a href="https://stream-cinema.online/film/csfd/'+e+'"><img src="https://stream-cinema.online/Nof7AYf1.png" width="15px" style="margin-right: 5px;"></a>');
                })
            }
        });
        return;
    } else {
        vurl = 'https://stream-cinema.online/widget/csfd?g=' + encodeURIComponent(window.location);
    }
    var bbga = document.createElement('script');
    bbga.type = 'text/javascript';
    bbga.async = true;
    bbga.src = vurl;
    var bbs = document.getElementsByTagName('script')[0];
    bbs.parentNode.insertBefore(bbga, bbs);
}

scIntegrate();