From 2135a580e74b9777a632ac3930f9950e90757214 Mon Sep 17 00:00:00 2001 From: lzrdblzzrd Date: Fri, 7 Oct 2022 16:14:54 +0300 Subject: [PATCH] Update 'yohoho-watch.user.js' --- yohoho-watch.user.js | 223 +++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 113 deletions(-) diff --git a/yohoho-watch.user.js b/yohoho-watch.user.js index bdb8b99..eac3c26 100644 --- a/yohoho-watch.user.js +++ b/yohoho-watch.user.js @@ -1,113 +1,110 @@ -// ==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(); +// ==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; + } + +} + +function init() { + const observer = new MutationObserver(() => updateBanner()); + observer.observe(document, { subtree: true, childList: true }); + + updateBanner(); + console.log('Yohoho Watch started! 🎥'); +} + +init();