Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Открывает ссылки на удалённые комментарии
// ==UserScript==
// @name lor-deleted-comments-reveal
// @author bodqhrohro (original)
// @author Nebula-Mechanica (slight adaptation)
// @namespace lor
// @description Shows and opens deleted comments' links.
// @include *.linux.org.ru/*
// @version 1.1
// @grant none
// ==/UserScript==
window.addEventListener('load', function() {
// hook into evil-penguin pages
var threadLink = document.querySelector('#warning-text p a');
if (threadLink) {
var parser = new DOMParser();
fetch(threadLink.href).then(function(result) {
if (result.ok) {
return result.text();
}
}).then(function(text) {
var dom = parser.parseFromString(text,'text/html');
var forms = dom.querySelectorAll('form');
var deletedForm = null;
for (var form of forms) {
if (form.querySelector('input[name="deleted"]')) {
deletedForm = form;
break;
}
}
if (deletedForm) {
if(document.getElementById("LIDShowIgnored") == null) {
var showIgnoredInput = document.createElement("input")
showIgnoredInput.type = "hidden"
showIgnoredInput.name = "filter"
showIgnoredInput.value = "show"
var marker = document.createElement("div")
marker.style.display = "none"
marker.id = "LIDShowIgnored"
deletedForm.appendChild(marker)
deletedForm.appendChild(showIgnoredInput)
}
document.body.appendChild(deletedForm);
setTimeout(function() {
deletedForm.querySelector('input[type="submit"]').click();
}, 0);
localStorage.setItem('deleted-comments-reveal-cid', window.location.href.match(/.*cid=(\d+)/)[1]);
return;
}
});
}
// restore links on thread pages
var comments = document.querySelectorAll('#comments article.msg');
if (comments) {
for (var comment of comments) {
if (comment.id) {
var id = comment.id.match(/comment-(\d+)/)[1];
var replyLinks = comment.querySelectorAll('.reply a');
if (!(replyLinks && replyLinks.length)) {
replyBlock = document.createElement('div');
replyBlock.className = 'reply';
var link_li = document.createElement('li');
var link = document.createElement('a');
link.innerHTML = 'Ссылка';
link.href = location.href + '?cid=' + id;
replyBlock.appendChild(link_li);
link_li.appendChild(link);
comment.querySelector('.msg_body').appendChild(replyBlock);
}
}
}
}
// jump to the deleted comment
// pop once so the re-anchoring never repeats
var cid = localStorage.getItem('deleted-comments-reveal-cid');
localStorage.removeItem('deleted-comments-reveal-cid');
if (cid) {
location.href += '#comment-' + cid;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment