Stack Overflow: contrassegna le risposte vecchie
Aggiunge un avviso sopra le risposte più vecchie di un anno impostato per ricordare la possibile obsolescenza.
Codice da copiare
/* 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 });
})();
Come usare questo esempio
- Copia il codice con il pulsante qui sopra.
- Installa JustZix (2 minuti) e apri l'estensione sulla pagina di destinazione.
- Aggiungi una nuova regola corrispondente a quella pagina.
- Incolla il codice nel pannello JavaScript della regola e salva — viene eseguito a ogni visita della pagina.
Valuta questo esempio
Nessuna valutazione — sii il primo.