User:Najzere/adduploadurl.js

// Author: User:Najzere // License: CC-BY-SA 3.0 - http://creativecommons.org/licenses/by-sa/3.0/ // Description: Adds image source to upload summary when uploading from URL

if (wgPageName == 'Special:Upload') { addOnloadHook(get_URL); };

function get_URL { var URL_form=document.getElementById('wpUploadFileURL'); addHandler(URL_form, 'change', insert_URL); };

function insert_URL(event) { var URL = document.getElementById('wpUploadFileURL').value; var summary = document.getElementById('wpUploadDescription'); if(document.getElementById('wpDestFile').getAttribute('readonly') != null) { var re = /Source URL: .+$/; var replacement = 'Source URL: ' + URL } else { var re = /\[http.*? Source URL\]/; var replacement = '[' + URL + ' Source URL]'; }; if(summary.value.match(re)) { summary.value = summary.value.replace(re, replacement); } else { summary.value = summary.value + '\n\n' + replacement; }; };