commit 5b186d3179997eb11d66a586c12c6e55e5a83426 Author: f.strw Date: Sun Jul 28 13:32:24 2024 +0300 Initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..4685acc --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +
+

NameMC Random skins infinite scroll

+
+ +Maximum convenience for those who are addicted to Minecraft skins. + +A userscript for Tampermonkey or any other userscript extension. + +### [Install](https://fem.mint.lgbt/f.strw/namemc-infinitescroll/raw/branch/master/script.user.js) \ No newline at end of file diff --git a/script.user.js b/script.user.js new file mode 100644 index 0000000..07427b1 --- /dev/null +++ b/script.user.js @@ -0,0 +1,53 @@ +// ==UserScript== +// @name NameMC random skins infinite scroll +// @namespace https://fem.mint.lgbt/f.strw +// @version v1 +// @description To those who are addicted to Minecraft skins (totally not me btw) +// @author f.strw +// @match https://namemc.com/minecraft-skins/random +// @icon https://www.google.com/s2/favicons?sz=64&domain=namemc.com +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + function appendNewElements() { + fetch('https://namemc.com/minecraft-skins/random') + .then(response => response.text()) + .then(data => { + const tempContainer = document.createElement('div'); + tempContainer.innerHTML = data; + + const newElements = tempContainer.querySelector('.mb-2'); + + const images = newElements.querySelectorAll('img'); + images.forEach(img => { + const dataSrc = img.getAttribute('data-src'); + if (dataSrc) { + img.setAttribute('src', dataSrc); + } + }); + + const existingContainer = document.querySelector('.mb-2'); + existingContainer.insertAdjacentHTML('beforeend', newElements.innerHTML); + }) + .catch(error => { + console.error('Error fetching new skins:', error); + }); + } + + function isBottomReached() { + const scrollPosition = window.innerHeight + window.scrollY; + const pageHeight = document.documentElement.offsetHeight; + return scrollPosition >= pageHeight; + } + + function handleScroll() { + if (isBottomReached()) { + appendNewElements(); + } + } + + window.addEventListener('scroll', handleScroll); +})(); \ No newline at end of file