Last active
January 18, 2023 06:43
-
-
Save dubsnipe/baac9c040531c626d346eae2eeba5db0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wikimedia Commons Attribution | |
// @namespace http://emiliovelis.com | |
// @version 0.1 | |
// @description This script forms the markup code to use Wikimedia Commons images including attribution information. | |
// @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js | |
// @match https://*.wikimedia.org/* | |
// ==/UserScript== | |
window.addEventListener('load', function() { | |
var name = document.getElementById("firstHeading").textContent; | |
var author = document.getElementById("fileinfotpl_aut").nextElementSibling.innerText; | |
var licenseFirst = document.getElementsByClassName("licensetpl_short")[0].innerHTML.trim(); | |
if (license != "undefined"){ | |
var license = "(" + licenseFirst + ")"; | |
} | |
if (document.querySelectorAll('.description .mw-content-ltr .en').length = 0){ | |
var description = document.querySelectorAll('.description .mw-content-ltr .en')[0].nextSibling.data.trim(); | |
}else{ | |
var description = ""; | |
}; | |
if (description.length>0){description =""}; | |
//if (description.charAt(description.length - 1) != "."){ | |
//description += "."; | |
//}; | |
var url = decodeURIComponent(window.location).toString(); | |
var inner = name + " by " + author + license + ". " + description + " Available at " + url; | |
var image = decodeURIComponent(document.getElementsByClassName("fullImageLink")[0].getElementsByTagName("img")[0].src); | |
var final = '<br><div>' + inner + '</div><br><textarea id=\"myCode\" rows=\"6\" >.large-image[![' + name + '](' + image.replace(/\(/g, '%28').replace(/\)/g, '%29') + ')]\n.footnote[' + inner + ']</textarea>'; | |
document.getElementById("siteSub").insertAdjacentHTML('afterend', final); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment