diff --git a/.travis.yml b/.travis.yml index d923d0e..5c7a886 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "14" + - "node" dist: trusty cache: npm: true diff --git a/package-lock.json b/package-lock.json index ce2cb23..d63b08e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8113,9 +8113,9 @@ "dev": true }, "nanoid": { - "version": "3.1.16", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.16.tgz", - "integrity": "sha512-+AK8MN0WHji40lj8AEuwLOvLSbWYApQpre/aFJZD71r43wVRLrOYS4FmJOPQYon1TqB462RzrrxlfA74XRES8w==", + "version": "3.1.15", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.15.tgz", + "integrity": "sha512-n8rXUZ8UU3lV6+43atPrSizqzh25n1/f00Wx1sCiE7R1sSHytZLTTiQl8DjC4IDLOnEZDlgJhy0yO4VsIpMxow==", "dev": true }, "nanomatch": { @@ -8933,9 +8933,9 @@ "dev": true }, "postcss": { - "version": "8.1.4", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.1.4.tgz", - "integrity": "sha512-LfqcwgMq9LOd8pX7K2+r2HPitlIGC5p6PoZhVELlqhh2YGDVcXKpkCseqan73Hrdik6nBd2OvoDPUaP/oMj9hQ==", + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.1.3.tgz", + "integrity": "sha512-AKsHGqd7HmXmL/EgyAjI4Gx719A5yQdt9HzyXrI8M/hzxfumecYS95kfvIt40UZqPVNoEt0Va1M3PG54XtNPbg==", "dev": true, "requires": { "colorette": "^1.2.1", diff --git a/package.json b/package.json index 5347f59..bcbe472 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "gulp-terser": "^1.4.0", "gulp-zip": "^5.0.2", "merge-stream": "^2.0.0", - "postcss": "^8.1.4", + "postcss": "^8.1.3", "sass": "^1.27.0", "terser": "^5.3.8", "vinyl-buffer": "^1.0.1", diff --git a/src/javascript/enhancements/anilyr.js b/src/javascript/enhancements/anilyr.js new file mode 100644 index 0000000..f80ebd8 --- /dev/null +++ b/src/javascript/enhancements/anilyr.js @@ -0,0 +1,48 @@ +import * as core from '../utils/aniwatchCore'; +import * as helper from '../utils/helpers'; + +const SCREENSHOT_TOOLTIP_ID = 'anilyr-screenshots-tooltip'; +const PLAYER_ID = 'player'; + +export function init() { + core.registerScript(node => { + if (helper.isHtmlElement(node) && node.id === SCREENSHOT_TOOLTIP_ID) { + observeScreenshotTooltip(node); + } + }, "^/anime/[0-9]*/[0-9]*$"); +} + +function observeScreenshotTooltip(tooltip) { + let observer = new MutationObserver(mutations => { + mutations.forEach(mutation => { + // Switched to invisible + if (!mutation.oldValue.includes('display: none') && mutation.target.style.display == 'none') { + let player = findPlayer(); + if(typeof player !== 'undefined'){ + resumePlayer(player); + } + } + }); + }); + + observer.observe(tooltip, { + attributes: true, + attributeOldValue: true, + attributeFilter: ['style'], + }); +} + +function findPlayer() { + const PLAYER_TAG_NAME = 'VIDEO'; // tagName gives UpperCase + + let playerCandidate = document.getElementById(PLAYER_ID); + if (playerCandidate.tagName === PLAYER_TAG_NAME) { + return playerCandidate; + } + + return undefined; +} + +function resumePlayer(player) { + player.play(); +} \ No newline at end of file diff --git a/src/javascript/enhancements/notifications.js b/src/javascript/enhancements/notifications.js deleted file mode 100644 index e97e530..0000000 --- a/src/javascript/enhancements/notifications.js +++ /dev/null @@ -1,33 +0,0 @@ -import * as core from '../utils/aniwatchCore'; -import * as helper from '../utils/helpers'; - -export function init() { - core.runAfterLoad(() => { - updateNotificationsInTitle(); - }, ".*"); - - core.runAfterLocationChange(() => { - updateNotificationsInTitle(); - }, ".*"); -} - -function getNotificationCount() { - if (core.isLoggedIn()) { - let menuUserText = document.getElementById('materialize-menu-dropdown').innerText.split('\n')[4]; - let notificationCount = menuUserText.match(/\d+/)?.[0] ?? 0; - return notificationCount; - } else { - return 0; - } -} - -function updateNotificationsInTitle() { - let count = getNotificationCount(); - - if (helper.assigned(count) && count > 0) { - // document.title is updated after the event is triggered, so we delay our title update by a reasonable time - setTimeout(() => { - document.title = `(${count}) ${document.title}`; - }, 100); - } -} \ No newline at end of file diff --git a/src/javascript/index.js b/src/javascript/index.js index 408eba4..b58cb94 100644 --- a/src/javascript/index.js +++ b/src/javascript/index.js @@ -3,9 +3,9 @@ import { initCore } from './utils/aniwatchCore'; // helper import { initHelpers } from './utils/helpers'; // enhancements +import { init as anilyr } from './enhancements/anilyr'; import { init as animeRequests } from './enhancements/animeRequests'; import { init as languageDisplay } from './enhancements/languageDisplay'; -import { init as notifications } from './enhancements/notifications'; import { init as quickSearch } from './enhancements/quickSearch'; // core @@ -15,7 +15,7 @@ initCore(); initHelpers(); // enhancements +anilyr(); animeRequests(); languageDisplay(); -notifications(); quickSearch(); \ No newline at end of file diff --git a/src/javascript/utils/aniwatchCore.js b/src/javascript/utils/aniwatchCore.js index db6c599..abe5afa 100644 --- a/src/javascript/utils/aniwatchCore.js +++ b/src/javascript/utils/aniwatchCore.js @@ -1,9 +1,7 @@ import * as helper from './helpers'; -/* SCRIPT LOGICS */ let __scripts = []; let __afterLoadScripts = []; -let __afterLocationChangeScripts = []; export function initCore() { let observer = new MutationObserver(mutations => { @@ -20,29 +18,6 @@ export function initCore() { attributes: true }); - runAfterLoad(() => { - let loadingBar = document.getElementById('enable-ani-cm'); - let loadingBarObserver = new MutationObserver(mutations => { - mutations.forEach(mutation => { - // enable-ani-cm node changes from display:none to display:block after loading - if (mutation.oldValue.includes('display: none')) { - __afterLocationChangeScripts.forEach(script => { - if (window.location.pathname.match(script.pattern)) { - script.function(); - } - }); - } - }) - }); - - loadingBarObserver.observe(loadingBar, { - attributes: true, - attributeOldValue: true, - attributeFilter: ['style'], - }); - - }, '.*') - helper.onReady(() => awaitPageLoaded()); } @@ -88,30 +63,10 @@ function awaitPageLoaded() { } let loop = setInterval(() => { - if (preLoader.style.display === "none" && document.readyState === 'complete') { + if (preLoader.style.display === "none") { clearInterval(loop); runScripts(); } }, 100); -} - -/* PATHNAME LOGIC */ -export function runAfterLocationChange(func, pattern = '.*') { - __afterLocationChangeScripts.push({ "function": func, "pattern": pattern }); -} - -/* LOGIN LOGIC */ -export function isLoggedIn() { - let menu = document.getElementById('materialize-menu-dropdown'); - let result = true; - - menu.innerText.split('\n').forEach(item => { - if (item === 'Login') { - result = false; - return; - } - }); - - return result; } \ No newline at end of file diff --git a/src/javascript/utils/helpers.js b/src/javascript/utils/helpers.js index 053aa18..a52968e 100644 --- a/src/javascript/utils/helpers.js +++ b/src/javascript/utils/helpers.js @@ -18,10 +18,6 @@ export function onReady(fn) { } } -export function assigned(obj) { - return !(typeof obj === 'undefined' || obj === null); -} - function handleKeyDown(event) { handleKeyToggle(event, true); } diff --git a/src/stylesheets/aniwatchplus.scss b/src/stylesheets/aniwatchplus.scss index b7f44a8..cdcb559 100644 --- a/src/stylesheets/aniwatchplus.scss +++ b/src/stylesheets/aniwatchplus.scss @@ -2,5 +2,4 @@ @import './vars/colors'; // enhancements -@import './enhancements/lists'; -@import './enhancements/watch2gether'; \ No newline at end of file +@import './enhancements/lists.scss'; \ No newline at end of file diff --git a/src/stylesheets/enhancements/_watch2gether.scss b/src/stylesheets/enhancements/_watch2gether.scss deleted file mode 100644 index a260283..0000000 --- a/src/stylesheets/enhancements/_watch2gether.scss +++ /dev/null @@ -1,6 +0,0 @@ -.material-icons { - // Fix icon position for room creator - &[aria-label="Room creator"] { - vertical-align: text-top; - } -}