MyShowsExternalPlayer

Allows to open the episode's playback in a new window mainly via ororo.tv.

Ekde 2022/05/16. Vidu La ĝisdata versio.

// ==UserScript==
// @name        MyShowsExternalPlayer
// @author      o4zloiroman
// @license     MIT
// @version     0.17
// @match       https://old.myshows.me/*/
// @description Allows to open the episode's playback in a new window mainly via ororo.tv.
// @namespace https://greasyfork.dpdns.org/users/722089
// ==/UserScript==

const ORORO_TEMPLATE = 'https://ororo.tv/shows/{0}#{1}-{2}'
const FMOVIES_TEMPLATE = 'https://fmovies.wtf/series/{0}-{1}/{2}-{3}'

const FMOVIES_POSTFIXES = {
    'the-practice': '4qj37'
};

function populateProfile() {
    const seasons = document.getElementsByClassName('seasonBlockBody');

    seasons.forEach(season => {
        const dataShowId = season.parentElement.getAttribute('data-show-id');
        const subHeaderSpan = document.querySelector(`#s${dataShowId}.showHeader .subHeader`);
        const showName = sanitizeShowName(subHeaderSpan.textContent);

        const episodes = season.querySelector('table tBody').children;
        episodes.forEach(episode => {                      
            const seNum = episode.children[0].textContent.split('x');
            const sNum = seNum[0];
            const eNum = seNum[1];

            const url = makeExternalUrl(showName, sNum, eNum);
            
            let element = makePlayElement(url, 'td');
            episode.replaceChild(element, episode.children[5]);
        });
    });
}

function populateShow() {
    let showName = sanitizeShowName(document.querySelector('.subHeader').innerText);

    let seasons = document.querySelectorAll('[itemprop="season"]');
    seasons.forEach(season => {
        let sNum = season.querySelector('a').innerText.slice(0, -6);

        const episodes = season.querySelectorAll('[itemprop="episode"]');
        episodes.forEach(episode => {
            let eNum = Number(episode.querySelector('._numb').innerText);

            let url = makeExternalUrl(showName, sNum, eNum);
            
            let button = makePlayElement(url, 'label');            

            episode.insertBefore(button, episode.firstChild);         
        });
    });
}

// Элемент кнопки перехода на внещний ресурс
function makePlayElement(episodeUrl, parentTag) {
    const button = document.createElement('a');                    
    button.setAttribute('style', 'float: right;margin-top: -0.4rem;padding-left: 1.2rem;');
    button.innerHTML = '<button class="_play"/></button>';       

    // Используем для подсказки
    button.setAttribute('href', episodeUrl);                        

    // Что-то перехватывает клик на странице с шоу, приходится писать в обход
    button.onclick = (e) => {
        e.preventDefault()
        window.open(episodeUrl);
    };

    const parentElement = document.createElement(parentTag);
    parentElement.appendChild(button);   

    return parentElement;
}

// Ссылка на Ороро
function makeOroroUrl(showName, sNum, eNum) {
    // Edge Case  
    if (showName === 'american-dad') {
        sNum = Number(sNum) + 1;        
    }
    else if (showName === 'suits') {
        showName = 'suit'
    }

    return String.format(ORORO_TEMPLATE, showName, sNum, eNum);
}

function makeFmoviesUrl(showName, sNum, eNum) {
    let postfix = FMOVIES_POSTFIXES[showName];

    return String.format(FMOVIES_TEMPLATE, showName, postfix, sNum, eNum);
}

function makeExternalUrl(showName, sNum, eNum) {
    if(showName === 'the-practice') {
        return makeFmoviesUrl(showName, sNum, eNum);
    }

    return makeOroroUrl(showName, sNum, eNum);
}

function sanitizeShowName(showName) {
    return showName
            .replace(/[^a-zA-Z ']/g, "")
            .replaceAll(' ', '-')
            .replaceAll('\'', '-')
            .toLowerCase();
}

// Extensions
String.format = function(format) {
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/{(\d+)}/g, function(match, number) {
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
      ;
    });
  };

// Entrance
(function() {
    window.onload = () => {
        const documentUrl = document.URL.split('/').filter(x => x !== '');

        const isProfilePage = documentUrl.pop() === 'profile';
        const isShowPage = documentUrl.pop() === 'view';

        if (isProfilePage) {
            populateProfile();
        } else if(isShowPage) {
            populateShow();
        }
    };
}
)();
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元