Skip to content

Instantly share code, notes, and snippets.

@Nebula-Mechanica
Last active December 4, 2022 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nebula-Mechanica/613bf3a91fd806d22cb218f2d80db40b to your computer and use it in GitHub Desktop.
Save Nebula-Mechanica/613bf3a91fd806d22cb218f2d80db40b to your computer and use it in GitHub Desktop.
Открывает ссылки на удалённые комментарии
// ==UserScript==
// @name lor-deleted-comments-reveal
// @author bodqhrohro (original)
// @author Nebula-Mechanica (slight adaptation)
// @namespace lor
// @description Shows and opens deleted comments' links.
// @include http://www.linux.org.ru/*
// @include https://www.linux.org.ru/*
// @version 1.1
// @grant none
// ==/UserScript==
// 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