Reddit User Blocker

Blocks Reddit users without reporting them

Click here to install Browse More Scripts
// ==UserScript==
// @name         Reddit User Blocker
// @namespace    66d7e0a67864c7b9795d7c40ba3754eb9ad3f8f9
// @version      0.4
// @description  Blocks Reddit users without reporting them
// @author       /u/AyrA_ch
// @match        https://www.reddit.com/*
// @grant        none
// ==/UserScript==

// Changelog
// 0.4 - Prevent links from being added to wrong elements
// 0.3 - Design adjustments
// 0.2 - Properly configure MutationObserver
// 0.1 - Initial Version

(function () {
	'use strict';
	//Creates an element with content and attributes
	var ce = function (type, props, content) {
		var e = document.createElement(type);
		var keys = Object.keys(props || {});
		for (var i = 0; i < keys.length; i++) {
			e.setAttribute(keys[i], props[keys[i]]);
		}
		if (content) {
			e.innerHTML = content;
		}
		return e;
	};
	//Content of the form
	var formContent = '<input type="hidden" name="executed" value="blocke' +
		'd"><span class="option main active"><a href="#" class="togglebut' +
		'ton " onclick="return toggle(this)" data-event-action="block_use' +
		'r">block user</a></span><span class="option error">are you sure?' +
		'  <a href="javascript:void(0)" class="yes" onclick="change_state' +
		'(this, &quot;block&quot;, hide_thing,undefined, null)">yes</a> /' +
		' <a href="javascript:void(0)" class="no" onclick="return toggle(' +
		'this)">no</a></span>';
	//Inserts a form into the given Element
	var insertForm = function (ele) {
		var form = ce("form", {
				"class": "toggle block-button",
				action: "#",
				method: "get"
			}, formContent);
		var li=document.createElement("li");
		li.appendChild(form);
		ele.appendChild(li);
		return li;
	};
	//Checks for elements that should have the block form but have not yet
	var checkAndAddForms = function () {
		//Containers that are supposed to hold the form
		var ele = document.querySelectorAll(".entry > ul.flat-list.buttons");
		for (var i = 0; i < ele.length; i++) {
			var e = ele[i];
			//Only insert form if it is not there already but other stuff is.
			if (e.childNodes.length > 0 && !e.querySelector(".block-button")) {
				insertForm(e);
			}
		}
	};
	//Initially process all nodes
	checkAndAddForms();
	//Listen to document changes to dynamically add the block option
	var observer = new MutationObserver(checkAndAddForms);
	var config = {
		attributes: false,
		childList: true,
		characterData: false,
		subtree: true
	};
	observer.observe(document.body, config);
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 3.135.209.107