// ==UserScript== // @name ReYohoho // @namespace https://github.com/reyohoho/reyohoho-chrome-ff-ext/ // @homepage https://github.com/reyohoho/reyohoho-chrome-ff-ext/ // @version 0.6 // @description Open ReYohoho directly from kinopoisk.ru // @author reyohoho // @match *://*.kinopoisk.ru/* // @icon https://github.com/reyohoho/reyohoho-chrome-ff-ext/raw/master/images/icon128.png // @grant GM_getResourceText // @grant GM_addStyle // @grant GM.xmlHttpRequest // @grant GM_info // @resource IMPORTED_CSS https://raw.githubusercontent.com/reyohoho/reyohoho-chrome-ff-ext/master/player.css // @run-at document-end // @connect reyohoho.space // @downloadURL https://update.greasyfork.icu/scripts/479031/ReYohoho.user.js // @updateURL https://update.greasyfork.icu/scripts/479031/ReYohoho.meta.js // ==/UserScript== let lastUrl = location.href; const playerTailId = 'watch-kinopoisk-player-tail'; const movieTypes = ['film', 'series']; const tailImage = ``; function mountPlayer(siteUrl) { window.open(siteUrl, '_blank'); } function mountPlayerTail(movieId) { const playerTile = document.createElement('div'); playerTile.id = playerTailId; playerTile.innerHTML = tailImage; try { GM.xmlHttpRequest({ url: 'https://reyohoho.space:4437/reyohoho_link', synchronous: true, method: 'GET', onload: function(r) { if (r.status == 200) { playerTile.addEventListener('click', () => mountPlayer(r.responseText + "#" + 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); } else { playerTile.addEventListener('click', () => mountPlayer("https://reyohoho.github.io/reyohoho/#" + 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); } } }); } catch (e) { playerTile.addEventListener('click', () => mountPlayer("https://reyohoho.github.io/reyohoho/#" + 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); }