Достало меня, что при переходе к сообщениям, реакциям скролл смещался в конец страницы и наклепал я вот такой вот скриптик:
// ==UserScript==
// @name LOR FIX
// @namespace lorf
// @match *://www.linux.org.ru/*
// @grant none
// @inject-into content
// @run-at document-start
// ==/UserScript==
(function() {
const origScrollTo = window.scrollTo.bind(window);
const origScrollIntoView = Element.prototype.scrollIntoView;
let blocked = false;
let targetId = null;
const initialCid = new URL(location.href).searchParams.get('cid');
if (initialCid) {
targetId = 'comment-' + initialCid;
blocked = true;
}
window.scrollTo = function(...args) {
if (blocked) return;
origScrollTo(...args);
};
Element.prototype.scrollIntoView = function(...args) {
if (blocked) return;
origScrollIntoView.apply(this, args);
};
if (!targetId) {
let attempts = 0;
const cidInterval = setInterval(function() {
attempts++;
const c = new URL(location.href).searchParams.get('cid');
if (c) {
clearInterval(cidInterval);
targetId = 'comment-' + c;
blocked = true;
setTimeout(function() {
blocked = false;
const el = document.getElementById(targetId);
if (el) {
el.style.outline = '3px solid #4a90d9';
origScrollIntoView.call(el, { behavior: 'smooth', block: 'start' });
setTimeout(function() { el.style.outline = ''; }, 3000);
}
}, 2000);
} else if (attempts >= 10) {
clearInterval(cidInterval);
}
}, 500);
} else {
window.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
blocked = false;
const el = document.getElementById(targetId);
if (el) {
el.style.outline = '3px solid #4a90d9';
origScrollIntoView.call(el, { behavior: 'smooth', block: 'start' });
setTimeout(function() { el.style.outline = ''; }, 3000);
}
}, 2000);
});
}
})();
Оно конечно работает, но может есть тут специалисты, где я дурак? Может можно сделать как то правильнее? Может как то проще можно перехватить этот скролл и без таймеров? Или понять что мне этот скролл изначально ломает?

