Stack Overflow: oznacz stare odpowiedzi
Dodaje ostrzeżenie nad odpowiedziami starszymi niż ustawiony rok, by przypominać o możliwej nieaktualności rozwiązania.
Kod do skopiowania
/* Flag answers older than a chosen year as possibly outdated */
(function () {
var CUTOFF = 2018;
function mark() {
document.querySelectorAll('#answers .answer').forEach(function (a) {
if (a.dataset.sofAge) return;
var t = a.querySelector('.user-action-time time, .relativetime');
var iso = t && (t.getAttribute('datetime') || t.getAttribute('title'));
if (!iso) return;
var year = new Date(iso).getFullYear();
if (!isNaN(year) && year < CUTOFF) {
a.dataset.sofAge = '1';
var tag = document.createElement('div');
tag.textContent = '⚠ Possibly outdated (' + year + ')';
tag.style.cssText = 'background:#fff4d6;color:#7a5b00;padding:4px 8px;border-radius:4px;margin:6px 0;font-size:12px;font-weight:600;';
var cell = a.querySelector('.answercell') || a;
cell.insertBefore(tag, cell.firstChild);
}
});
}
mark();
new MutationObserver(mark).observe(document.body, { childList: true, subtree: true });
})();
Jak użyć tego przykładu
- Skopiuj kod przyciskiem powyżej.
- Zainstaluj JustZix (2 minuty) i otwórz wtyczkę na docelowej stronie.
- Dodaj nową regułę dopasowaną do tej strony.
- Wklej kod w panelu JavaScript reguły i zapisz — uruchomi się przy każdym wejściu na stronę.
Oceń ten przykład
Brak ocen — oceń jako pierwszy.