Black List

скрывает комментарии юзера

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Black List
// @namespace    http://shikimori.io
// @description  скрывает комментарии юзера
// @version      1.2
// @author       pirate-
// @match        *://shikimori.io/*
// @match        *://shikimori.rip/*
// @match        *://shiki.one/*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	let hiddenUserIds = [];

	if (localStorage.getItem('hiddenUserIds')) {
		hiddenUserIds = JSON.parse(localStorage.getItem('hiddenUserIds'));
	}

	function updateBlacklistStyle(userIds) {
		let styleElement = document.getElementById('blacklist');

		if (!styleElement) {
			styleElement = document.createElement('style');
			styleElement.id = 'blacklist';
			document.head.appendChild(styleElement);
		}

		const newRule = userIds.map(id => `.b-comment[data-user_id="${id}"]`).join(', ') + ' { display: none; }';
		styleElement.innerHTML = newRule;

		updateBlockedUsersList(userIds);
	}

	function updateBlockedUsersList(userIds) {
		blockedUsersList.innerHTML = '';

		userIds.forEach(userId => {
			const commentElement = document.querySelector(`.b-comment[data-user_id="${userId}"]`);
			if (commentElement) {
				const nickname = commentElement.getAttribute('data-user_nickname');

				const userBlock = document.createElement('div');
				const nicknameLink = document.createElement('a');
				nicknameLink.href = `https://shikimori.one/${nickname}`;
				nicknameLink.textContent = nickname;

				const unblockButton = document.createElement('span');
				unblockButton.textContent = '×';
				unblockButton.style.color = 'red';
				unblockButton.style.cursor = 'pointer';

				unblockButton.addEventListener('click', () => {
					const index = hiddenUserIds.indexOf(userId);
					if (index > -1) {
						hiddenUserIds.splice(index, 1);
						localStorage.setItem('hiddenUserIds', JSON.stringify(hiddenUserIds));
						updateBlacklistStyle(hiddenUserIds);
						updateBlockedUsersList(hiddenUserIds);
					}
				});

				userBlock.appendChild(nicknameLink);
				userBlock.appendChild(unblockButton);
				blockedUsersList.appendChild(userBlock);
			}
		});
	}

	function addBlockText(mainControls) {
		const commentElement = mainControls.closest('.b-comment');
		const userId = commentElement.getAttribute('data-user_id');

		if (!hiddenUserIds.includes(userId) && !mainControls.querySelector('.block-text')) {
			const blockText = document.createElement('span');
			blockText.classList.add('block-text');
			blockText.style.cursor = 'pointer';
			blockText.style.color = 'red';
			blockText.addEventListener('click', function() {
				if (!hiddenUserIds.includes(userId)) {
					hiddenUserIds.push(userId);
					localStorage.setItem('hiddenUserIds', JSON.stringify(hiddenUserIds));
					updateBlacklistStyle(hiddenUserIds);
				}
			});

			mainControls.appendChild(blockText);
		}
	}

	function updateComments() {
		const mainControlsList = document.querySelectorAll('.b-comment .inner .buttons .main-controls');
		mainControlsList.forEach(addBlockText);
	}

	const blockedUsersList = document.createElement('div');
	blockedUsersList.className = 'blist-users';
	blockedUsersList.style.display = 'none';

	function createShowBlockedButton() {
		const showBlockedButton = document.createElement('span');
		showBlockedButton.classList.add('show-blist', 'b-button');
		showBlockedButton.textContent = 'список';
		showBlockedButton.style.cursor = 'pointer';

		showBlockedButton.addEventListener('click', () => {
			showBlockedButton.classList.toggle('active');
			blockedUsersList.style.display = blockedUsersList.style.display === 'none' ? 'flex' : 'none';
			updateBlockedUsersList(hiddenUserIds);
		});

		return showBlockedButton;
	}

	function initInterface() {
		document.body.appendChild(createShowBlockedButton());
		document.body.appendChild(blockedUsersList);
	}

	const styles = document.createElement('style');
	styles.innerHTML = `
    .blist-users {
        gap: 5px;
        flex-direction: column;
        max-height: 100px;
        overflow-y: auto;
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        z-index: 99;
        background: white;
        width: 300px;
        border-radius: 3px;
        box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .16);
        padding: 10px;
    }

    .blist-users > div {
        display: flex;
        justify-content: space-between;
    }

    .show-blist {
        position: fixed;
        right: 5px;
        top: 70px;
    }

   .block-text {
   opacity:.7;
   margin-left: 15px;
}

   .block-text:hover {
    opacity:1;
}

    .block-text:before {
    font-family: shikimori;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    text-transform: none;
    letter-spacing: normal;
    content: "";
    }

    `;
	document.head.appendChild(styles);

	function checkElementsPeriodically() {
		updateComments();
		if (!document.querySelector('.show-blist')) {
			initInterface();
		}
	}

	setInterval(checkElementsPeriodically, 1000);
	updateBlacklistStyle(hiddenUserIds);
})();