#MastodonTools #JavaScript #userscript #Firefox #TamperMonkey #NeuralNetwork #ChatGPT
Вот, предварительная версия скрипта, пытающегося удержать на месте последний загруженный пост при обновлении ленты.
Собно, не зная ни причины такого поведения, ни жабоскрипта в принципе (среда, мои чюваки! 🐸 ), получилось пока то, что получилось. Если у кого-то есть мюсли, как более изящно подхватить окончание загрузки ленты — делитесь.
В принципе, пробовал на глобалке с 900 новых постов, и оно работает.
//// ==UserScript==
// @name Restore scroll position
// @namespace http://tampermonkey.net/
// @version 0.9a
// @description I won't get lost again!
// @author ChatGPT
// @match https://Your.Instance/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Функция для получения первого видимого элемента <article>
function getFirstVisibleArticle() {
const articles = document.querySelectorAll('article');
for (let article of articles) {
const rect = article.getBoundingClientRect();
if (rect.top >= 0 && rect.top <= window.innerHeight) {
return article;
}
}
return null;
}
// Функция для плавного прокручивания к первому видимому <article>
function scrollToArticle() {
const article = getFirstVisibleArticle();
if (article) {
// console.log(article.getAttribute('aria-posinset')+ ' / '+article.getAttribute('data-id'));
// Прокручиваем к элементу трижды с интервалом в 1 секунду
setTimeout(() => {
article.scrollIntoView({ behavior: "smooth", block: 'start' });
// console.log(article.getAttribute('aria-posinset')+ ' / '+article.getAttribute('data-id'));
}, 1000);
setTimeout(() => {
article.scrollIntoView({ behavior: "smooth", block: 'start' });
// console.log(article.getAttribute('aria-posinset')+ ' / '+article.getAttribute('data-id'));
}, 2000);
setTimeout(() => {
article.scrollIntoView({ behavior: "smooth", block: 'start' });
// console.log(article.getAttribute('aria-posinset')+ ' / '+article.getAttribute('data-id'));
}, 3000);
}
}
// Отслеживание нажатия левой кнопки мыши по кнопке загрузки
document.addEventListener('mousedown', function(event) {
if (event.button === 0 && event.target.closest('.load-more.load-gap')) {
scrollToArticle();
}
});
})();