whatimg - add [img] tags

you need to set 'upload layout' to boxed in whatimg settings

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        whatimg - add [img] tags
// @namespace   diff
// @description you need to set 'upload layout' to boxed in whatimg settings
// @include     https://whatimg.com/
// @include     https://whatimg.com/upload.php
// @require     https://greasyfork.org/scripts/1003-wait-for-key-elements/code/Wait%20for%20key%20elements.js?version=2765
// @version     0.2
// @grant       none
// ==/UserScript==

// using waitForKeyElements.js so this works with the drag'n'drop upload script: http://userscripts.org/scripts/show/105520

function doit() {
	var a = document.querySelector('textarea.input_field');
	var output = "";
	
	if (a) {
		var list = a.value.match(/(https?:\S*?\S\.(png|jpg|jpeg|gif))$/gim);
		for (i=0; i<list.length; i++) {
			output += "[img]" + list[i] + "[/img]\n";
		}
		
		a.value = a.value.replace(/^\s+(?=http)/gim, ""); // remove leading space from original links
		
		a.value += "\n[img] tags only:\n" + output;
	}
}

waitForKeyElements ("textarea.input_field", doit);