Jandan user blocker

block Jandan users

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

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 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         Jandan user blocker
// @namespace    jandan.net
// @name:zh-CN   煎蛋屏蔽用户
// @version      0.1
// @description  block Jandan users
// @description:zh-cn  屏蔽特定用户
// @author       Suzuhana
// @match        http://jandan.net/pic
// @match        http://jandan.net/pic/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const localStorage = window.localStorage;
  let blockList = localStorage.getItem('blockList')
    ? JSON.parse(localStorage.getItem('blockList'))
    : [];
  const commentList = document.querySelector('ol.commentlist');
  const posts = document.querySelectorAll("ol.commentlist li[id^='comment']");
  const postsArr = Array.from(posts);
  const filteredPosts = postsArr.filter((ele) => {
    let shouldBeFiltered = false;

    blockList
      .map((ele) => ele.userId)
      .forEach((blockedId) => {
        if (
          ele
            .querySelector('div.author > strong')
            .getAttribute('title')
            .includes(blockedId)
        ) {
          shouldBeFiltered = true;
        }
      });

    return !shouldBeFiltered;
  });

  //empty nodeList and repopulate with filtered comments
  commentList.innerHTML = '';

  filteredPosts.forEach((ele) => {
    //Grab user name and user id;
    const userNode = ele.querySelector('div.author > strong');

    const userName = userNode.innerText;
    const userId = userNode.getAttribute('title').split(':')[1];

    //Create a Button for blocking user
    const blockButton = document.createElement('BUTTON');
    blockButton.innerHTML = 'Block this User';
    blockButton.addEventListener('click', () => {
      blockList.push({
        userId,
        userName,
      });
      localStorage.setItem('blockList', JSON.stringify(blockList));
      //TODO: could be replaced with better option
      location.reload();
    });

    ele.querySelector('div.author').appendChild(blockButton);
    commentList.appendChild(ele);
  });

  //reset blocklist
  const resetButton = document.createElement('BUTTON');
  resetButton.innerHTML = 'Release the trolls';
  resetButton.addEventListener('click', () => {
    blockList = [];
    localStorage.removeItem('blockList');
    //TODO: could be replaced with better option
    location.reload();
  });
  resetButton.style = 'float: right';

  document.querySelector('div.cp-pagenavi').appendChild(resetButton);
})();