Pastebin file upload for free users

Provides Pastebin file upload without the need for a pro subscription.

This script is marked as "external"
This script was commisioned by someone else, and I will not check if it works. If it breaks, contact me
Click here to install Browse More Scripts
// ==UserScript==
// @name         Pastebin file upload for free users
// @namespace    d7f1c70d1db009ead3af20ee8e9260c0310e2094
// @version      0.2
// @description  Provides Pastebin file upload without the need for a pro subscription.
// @author       /u/AyrA_ch
// @match        http://pastebin.com/*
// @match        https://pastebin.com/*
// @grant        none
// @external     true
// ==/UserScript==

(function()
{
	//only add upload control if we are a free user or not logged in
	var status=document.getElementById("header_user_status");
	if(status && status.textContent.toUpperCase()!=="PRO")
	{
		//Note: Do not just append the input by changing the "innerHTML" of the parent element.
		//Otherwise it will get rid of the event the textbox has attached.
		
		//find the element that holds the text box
		var paste=document.getElementById("paste_code");
		var e=paste.parentElement;
		
		//append a text and a file upload control
		var text=document.createTextNode("Select a file instead: ");
		var input=document.createElement("input");
		input.setAttribute("type","file");
		e.appendChild(text);
		e.appendChild(input);
		
		//add event to the file upload control so it calls our function when the user selects a file
		input.addEventListener("change",function(e)
		{
			var f=e.target.files;
			//make sure a file has been selected
			if(f && f.length>0)
			{
				//Pastebin has a 500kb size limitation for free users.
				if(f[0].size<500*1000)
				{
					//read the file as text
					var fr=new FileReader();
					fr.onloadend=function()
					{
						//set the textbox content to the file content
						paste.value=fr.result;
					};
					fr.readAsText(f[0]);
				}
				else
				{
					alert("Maximum size is 500 kb. Your file is "+Math.floor(f.size/1000)+" kb");
				}
			}
		});
	}
})();

/*
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 18.218.234.83