diff --git a/yohoho-watch.png b/yohoho-watch.png new file mode 100644 index 0000000..43169c6 Binary files /dev/null and b/yohoho-watch.png differ diff --git a/yohoho-watch.user.js b/yohoho-watch.user.js new file mode 100644 index 0000000..bdb8b99 --- /dev/null +++ b/yohoho-watch.user.js @@ -0,0 +1,113 @@ +// ==UserScript== +// @name Yohoho Watch +// @namespace yohoho-watch +// @author lzrdblzzrd +// @description Watch films from Kinopoisk.ru on Yohoho for free! +// @downloadURL https://gitea.lzrdblzzrd.xyz/lzrdblzzrd/Yohoho-Watch/raw/branch/master/yohoho-watch.user.js +// @updateURL https://gitea.lzrdblzzrd.xyz/lzrdblzzrd/Yohoho-Watch/raw/branch/master/yohoho-watch.user.js +// @icon https://gitea.lzrdblzzrd.xyz/lzrdblzzrd/Yohoho-Watch/raw/branch/master/yohoho-watch.png +// @version 1.0 +// @match *://www.kinopoisk.ru/* +// @grant none +// @run-at document-end +// ==/UserScript== + +const BANNER_IMAGE = ` + + + + + + + +`; + +const BANNER_ID = 'yohoho-watch'; +const MOVIE_TYPES = ['film', 'series']; + +let currentMovieId = null; +let lastUrl = '/'; + +function openPlayer() { + if (!currentMovieId) return; + const link = new URL('https://4h0y.gitlab.io/'); + link.hash = currentMovieId; + window.open(link.toString(), '_blank').focus(); +} + +function mountBanner() { + const banner = document.createElement('div'); + banner.id = BANNER_ID; + banner.innerHTML = BANNER_IMAGE; + banner.style.width = '32px'; + banner.style.height = '128px'; + banner.style.top = '-128px'; + banner.style.left = '8px'; + banner.style.outline = 'none'; + banner.style.cursor = 'pointer'; + banner.style.position = 'fixed'; + banner.style.zIndex = '9000'; + banner.style.transition = 'top 0.2s ease'; + + banner.addEventListener('click', () => openPlayer()); + banner.addEventListener('mouseover', () => { banner.style.top = '-24px' }); + banner.addEventListener('mouseout', () => { banner.style.top = '-32px' }); + + setTimeout(() => { banner.style.top = '-32px' }, 1000); + + document.body.appendChild(banner); +} + +function unmountBanner() { + const banner = document.getElementById(BANNER_ID); + if (banner) banner.remove(); +} + +function updateBanner() { + const url = location.href; + + if (url === lastUrl) return; + lastUrl = url; + + const banner = document.getElementById(BANNER_ID); + const urlData = url.split('/'); + const movieId = urlData[4]; + const movieType = urlData[3]; + + if (!movieId || !movieType || !MOVIE_TYPES.includes(movieType)) { + if (banner) unmountBanner(); + currentMovieId = null; + } else { + if (!banner) mountBanner(); + currentMovieId = movieId; + } + +} + +/** + * Script initialization + */ +function init() { + const observer = new MutationObserver(() => updateBanner()); + observer.observe(document, { subtree: true, childList: true }); + + updateBanner(); + console.log('Yohoho Watch started! 🎥'); +} + +init();