KG - upload: add [img] tags

adds link to auto tag image URLs

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        KG - upload: add [img] tags
// @description adds link to auto tag image URLs
// @namespace   KG
// @include     http*://*karagarga.in/upload.php*
// @grant	none
// @version     0.4
// ==/UserScript==

var d = document.getElementsByName("descr")[0];

if (d && d.type != 'hidden') {  // only run on second step of upload.php

	 var code = 'javascript: '
		 + 'var d = document.getElementsByName("descr")[0];'
		 + 'd.value = d.value.replace(/^\\s+(?=http)/gim, "");'		 
		 + 'd.value = d.value.replace(/(https?:\\S*?\\S\\.(png|jpg|jpeg|gif))/gi, "[img]$1[/img]\\n");'
		 + 'return false;'
		 ;
	 
	 var tagImg = document.createElement("a");
	 tagImg.setAttribute("onclick", code);
	 tagImg.textContent = "Add [IMG][/IMG] tags";
	 tagImg.href = "#";
	 
	 d.parentNode.insertBefore(tagImg, d.nextSibling);
}