Word and Image Blocker - Settings - UI

This is the UI script. It's seperate so you can toggle the UI on and off. Use this script to add and delete words and phrases. Toggle off and on in the violentmonkey extension. Blocking works without this toggled on.

2023-12-09 기준 버전입니다. 최신 버전을 확인하세요.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Word and Image Blocker - Settings - UI
// @namespace    https://github.com/def-initive/
// @version      1.0
// @description  This is the UI script. It's seperate so you can toggle the UI on and off. Use this script to add and delete words and phrases. Toggle off and on in the violentmonkey extension. Blocking works without this toggled on.
// @author       def-initive
// @match        *://*/*
// @exclude      *://github.com/*
// @exclude      *://greasyfork.org/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to create the UI element
    function createUI() {
        // Get the blocked phrases from local storage
        var storedPhrases = localStorage.getItem('blockedPhrases');
        var blockedPhrases = storedPhrases ? JSON.parse(storedPhrases) : [];

        // Create a container element for the UI
        var container = document.createElement('div');
        container.className = 'blocked-phrases-settings-container'; // Add a class for identification
        container.style.position = 'fixed';
        container.style.top = '10px';
        container.style.right = '10px';
        container.style.padding = '10px';
        container.style.background = 'white';
        container.style.border = '1px solid #ccc';
        container.style.zIndex = '9999';

        // Create a heading for the UI
        var heading = document.createElement('h2');
        heading.textContent = 'Blocked Phrases Settings';
        container.appendChild(heading);

        // Create an unordered list to display the phrases
        var list = document.createElement('ul');

        // Function to remove a phrase from the list and update the UI
        function removePhrase(index) {
            blockedPhrases.splice(index, 1);
            updateUI();
            saveToLocalStorage();
        }

        // Add each blocked phrase to the list
        blockedPhrases.forEach(function (phrase, index) {
            var listItem = document.createElement('li');
            listItem.textContent = phrase;

            // Create a "Remove" button for each phrase
            var removeButton = document.createElement('button');
            removeButton.textContent = '-';
            removeButton.style.marginLeft = '5px';
            removeButton.addEventListener('click', function () {
                removePhrase(index);
            });

            listItem.appendChild(removeButton);
            list.appendChild(listItem);
        });

        container.appendChild(list);

        // Create an "Add Words" button
        var addButton = document.createElement('button');
        addButton.textContent = 'Add Words';
        addButton.addEventListener('click', function () {
            // Prompt the user to enter new words
            var newWords = prompt('Enter new words or phrases (comma-separated):');
            if (newWords) {
                // Split the entered words and add them to the blocked phrases list
                var newWordsArray = newWords.split(',').map(function (word) {
                    return word.trim();
                });
                blockedPhrases = blockedPhrases.concat(newWordsArray);

                // Update the UI with the new list of blocked phrases
                updateUI();
                saveToLocalStorage();
            }
        });

        container.appendChild(addButton);

        // Append the container to the document body
        document.body.appendChild(container);

        // Function to update the UI with the latest list of blocked phrases
        function updateUI() {
            list.innerHTML = ''; // Clear the existing list

            // Add each blocked phrase to the list
            blockedPhrases.forEach(function (phrase, index) {
                var listItem = document.createElement('li');
                listItem.textContent = phrase;

                // Create a "Remove" button for each phrase
                var removeButton = document.createElement('button');
                removeButton.textContent = '-';
                removeButton.style.marginLeft = '5px';
                removeButton.addEventListener('click', function () {
                    removePhrase(index);
                });

                listItem.appendChild(removeButton);
                list.appendChild(listItem);
            });
        }

        // Function to save the updated list to local storage
        function saveToLocalStorage() {
            localStorage.setItem('blockedPhrases', JSON.stringify(blockedPhrases));
        }
    }

    // Create the UI when the script is executed
    createUI();
})();