Wiki File Helper

Find file history on en.wp and commons

by Meep

HTML

<div>
    <fieldset>
        <legend>Wikipedia: File lookup (commons and en.)</legend>
        <input id="filename" type="text" value="" style="width:90%" /> <a id="butGO" href="#">GO</a>

        <div id="outONE"></div>
        <div id="outTWO"></div>
    </fieldset>
</div>

JavaScript

$(document).ready(function () {
       $("#butGO").on("click", doit);
       $('#filename').keyup(function (e) {
           if (e.keyCode === 13) {
               doit();
           }
       });
   });

   function doit() {
       if ($("#filename").val() === '') {
           $("#outONE").html("Enter a filename first muppet!");
       } else {
           $("#outONE").html("<iframe style='width:100%; height: 50%; min-height:400px;' src='" + "https://commons.wikimedia.org/wiki/File:" + fixedEncodeURIComponent($("#filename").val()) + "'></iframe>");
           $("#outTWO").html("<iframe style='width:100%; height: 50%; min-height:400px;' src='" + "https://en.wikipedia.org/wiki/File:" + fixedEncodeURIComponent($("#filename").val()) + "'></iframe>");
       }
   }

   function fixedEncodeURIComponent(str) {
       return encodeURIComponent(str).replace(/[!'()*]/g, escape);
   }