Reddit Content Deleter

Adds "Delete" button to messages if none is provided

Click here to install Browse More Scripts
// ==UserScript==
// @name         Reddit Content Deleter
// @namespace    cff03ab1cf21b97243e0505155254ac916d803b3
// @version      0.1
// @description  Adds "Delete" button to messages if none is provided
// @author       /u/AyrA_ch
// @match        https://www.reddit.com/*
// @grant        none
// ==/UserScript==

// Changelog
// 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="delete' +
		'd"><span class="option main active"><a href="#" class="togglebut' +
		'ton " onclick="return toggle(this)" data-event-action="delete' +
		'">delete</a></span><span class="option error">are you sure?' +
		'  <a href="javascript:void(0)" class="yes" onclick="change_state' +
		'(this, &quot;del&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 del-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 del 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(".del-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 98.80.143.34