HN Blocker

Block users on the orange website

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

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

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

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

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         HN Blocker
// @namespace    http://news.ycombinator.com/
// @version      0.1
// @description  Block users on the orange website
// @author       A. Person
// @match        https://news.ycombinator.com/item*
// @icon         https://www.google.com/s2/favicons?domain=ycombinator.com
// @grant        GM.setValue
// @grant        GM.getValue
// @grant        GM.addStyle
// @license      MIT
// ==/UserScript==

GM.addStyle(`
.default .comment.blocked span.commtext, .reply {
    display:none !important;
}

.default .comment.blocked:not(:hover)::after {
    content: "[blocked]";
}

.default .comment.blocked:hover span.commtext {
    display:block !important;
}
`);

var users = [];
async function getBlockedUsers() {
  users = await GM.getValue("hn_banned", []);
  console.log(`[HN] Loaded ${users.length} users`);
}

let banUser = function (name) {
  users.push(name);
  GM.setValue("hn_banned", users);
};

let unbanUser = function (name) {
  var i = users.indexOf(name);
  if (i !== -1) users.splice(i, 1);
  GM.setValue("hn_banned", users);
};

function handleItem(item) {
  var username = item.querySelector("a").text;
  let commentEl = item.querySelector(".comment");

  var seperator = item.querySelector(".hn_bl_seperator");

  if (seperator !== null) {
    seperator.remove();
    seperator = null;
  }

  seperator = document.createElement("span");
  seperator.innerHTML = " | ";
  seperator.className = "hn_bl_seperator";

  var actor = document.createElement("a");
  actor.href = "#";

  item.querySelector(".comhead").appendChild(seperator);
  seperator.appendChild(actor);

  var blockedMessage = item.querySelector(".blocked");

  if (blockedMessage !== null) {
    blockedMessage.remove();
  }

  if (users.includes(username)) {
    commentEl.classList.add("blocked");

    actor.innerHTML = "unblock";
    actor.onclick = function () {
      unbanUser(username);
      commentEl.classList.remove("blocked");
      return false;
    };
  } else {
    commentEl.classList.remove("blocked");

    actor.innerHTML = "block";
    actor.onclick = function () {
      banUser(username);
      commentEl.classList.add("blocked");
      return false;
    };
  }
}

(async function () {
  "use strict";

  await getBlockedUsers();

  var comments = document.querySelectorAll(".default");
  console.log("got comments", comments.length);

  comments.forEach((comment) => {
    handleItem(comment);
  });
})();