// ==UserScript== // @name ReYohoho // @namespace https://github.com/olegsvs/reyohoho-chrome-ff-ext/ // @homepage https://github.com/olegsvs/reyohoho-chrome-ff-ext/ // @version 0.4 // @description Open ReYohoho directly from kinopoisk.ru // @author olegsvs // @match *://*.kinopoisk.ru/* // @icon https://github.com/olegsvs/reyohoho-chrome-ff-ext/raw/master/images/icon128.png // @grant none // @connect kinopoisk.ru // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant GM_info // @resource IMPORTED_CSS https://raw.githubusercontent.com/olegsvs/reyohoho-chrome-ff-ext/master/player.css // @run-at document-end // @downloadURL none // ==/UserScript== let lastUrl = location.href; const playerTailId = 'watch-kinopoisk-player-tail'; const movieTypes = ['film', 'series']; const tailImage = ``; function mountPlayer(movieId) { window.open("https://olegsvs.github.io/yohoho/#" + movieId, '_blank'); } function mountPlayerTail(movieId) { const playerTile = document.createElement('div'); playerTile.id = playerTailId; playerTile.innerHTML = tailImage; playerTile.addEventListener('click', () => mountPlayer(movieId)); playerTile.addEventListener('mouseover', () => { playerTile.style.top = '0px' }); playerTile.addEventListener('mouseout', () => { playerTile.style.top = '-32px' }); setTimeout(() => { playerTile.style.top = '-32px'; }, 100); document.body.appendChild(playerTile); } function removeElement(elementId) { if (document.contains(document.getElementById(elementId))) { document.getElementById(elementId).remove(); } } function kinopoiskPageHandler() { const pathname = window.location.pathname.substr(1).split('/'); const movieId = pathname[1]; const movieType = pathname[0]; const isMovieIdNum = /^\d+$/.test(movieId); if (typeof movieId === 'undefined' || typeof movieType === 'undefined' || !isMovieIdNum ) { console.error('Watch kinopoisk wrong movie data'); removeElement(playerTailId); return; } console.log('Watch kinopoisk movie id: ' + movieId); if (movieTypes.includes(movieType)) { mountPlayerTail(movieId); } else { removeElement(playerTailId); } } new MutationObserver(() => { const url = location.href; if (url !== lastUrl) { lastUrl = url; kinopoiskPageHandler(); } }).observe(document, { subtree: true, childList: true }); window.addEventListener('load', kinopoiskPageHandler) if (typeof GM_addStyle === 'undefined') { GM_addStyle = (aCss) => { 'use strict'; let head = document.getElementsByTagName('head')[0]; if (head) { let style = document.createElement('style'); style.setAttribute('type', 'text/css'); style.textContent = aCss; head.appendChild(style); return style; } return null; }; }; if (typeof GM_getResourceText === 'undefined') { var my_css = `#watch-kinopoisk-player-tail { width: 32px; height: 128px; top: -128px; left: 8px; outline: none; cursor: pointer; position: fixed; z-index: 8888; transition: top 0.2s ease }` GM_addStyle(my_css) } else { const styles = GM_getResourceText("IMPORTED_CSS"); GM_addStyle(styles); }