lor-deleted-comments-reveal

Shows links on the deleted comments. Board-style.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        lor-deleted-comments-reveal
// @namespace   lor
// @description Shows links on the deleted comments. Board-style.
// @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) {
        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) {
          for (var link of replyLinks) {
            if (link.innerHTML.trim() === 'Ссылка') {
              link.innerHTML = '#' + id;
              break;
            }
          }
        } else {
          replyBlock = document.createElement('div');
          replyBlock.className = 'reply';
          var link = document.createElement('a');
          link.innerHTML = '#' + id;
          link.href = location.href + '#' + id;
          replyBlock.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;
  }
});