Hide discussion

try to take over the world!

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Hide discussion
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://mangalib.me/*
// @grant        none
// ==/UserScript==

(function() {
    setTimeout(SetEve, 500);
    setTimeout(Go, 1000);

    function SetEve() {
      if (document.querySelector('.f-categories')) {
        document.querySelector('.f-categories').addEventListener("click",function(e) {
	      setTimeout(Go, 500);
        });
      }
    }

    function Go() {
      if (document.querySelector('.f-pagination')) {
        document.querySelector('.f-pagination').addEventListener("click",function(e) {
	      setTimeout(Go, 500);
        });
      }
      hideItems();
      addButtons();
    }

    function hideItems() {
      var discusArr = document.getElementsByClassName('discussion-item');
      for (var i = 0; i < discusArr.length; i++) {
        var disscusId = discusArr[i].querySelector('.link-default').href.match(/\/forum\/discussion\/(.*)/)[1];
        if (localStorage.getItem("hide" + disscusId)) {
          discusArr[i].style.display = 'none';
          console.log("Hide: " + disscusId);
        }
      }
    }

    function addButtons() {
      var discusArr = document.getElementsByClassName('discussion-item');
      for (var i = 0; i < discusArr.length; i++) {
        var button = document.createElement("button");
        button.setAttribute("style", "float: right");
        button.innerHTML = 'X';
        button.onclick = function(e) {
          var id = e.target.parentNode.firstChild.href.match(/\/forum\/discussion\/(.*)/)[1];
          localStorage.setItem("hide" + id, 1);
          console.log("hide" + id);
          e.target.closest('.discussion-item').style.display = 'none';
        };
        discusArr[i].querySelector('h2').setAttribute("style", "margin-right: 0px");
        discusArr[i].querySelector('h2').appendChild(button);
      }
    }

})();