User:Phette23/Scripts/FindDPLA.js

!function(t,e,i){var n={title:$("#firstHeading").text,categories:[],otherTitles:[],redirects:[],getCategories:function{$("#mw-normal-catlinks li").each(function(t,e){n.categories.push($(e).text)})},getOtherTitles:function{$(".dablink").each(function(t,e){test=$(e).text.match('"(.*)" redirects here.'),test&&n.otherTitles.push(test[1])})}},r=0,o=0,s={},a=[],l=function(t){var e="e4c036f3302aad8d8c188683967b9619",i="http://api.dp.la/v2/items";return i+"?api_key="+e+"&q="+encodeURIComponent(t)+"&callback=_handleResponse"},c=function(t){$("body").append(' ')},f=function(t){s=t;var e=s.docs.length;e>0?d(g):oi?n.substr(0,i).replace(/\s$/,"")+"&hellip;":n},d=function(t){var e=s.docs,i={};$.each(e,function(t,e){var n=e.sourceResource;i.title=$.isArray(n.title)?n.title[0]:n.title,i.title=h(i.title),i.uri=e.isShownAt,i.isImage=v(n),a.push(i),i={}}),"function"==typeof t&&t},p=function(t){return t.replace("<","&lt;").replace(">","&gt;")},u=function(e){var i=$("#firstHeading").add(".dablink"),n=function(e){i.visible(!0)&&($("#wikipedpla").show("slow"),$(t).off("scroll",n))};$("#mw-content-text").prepend(e),$("#wikipedpla").css("display","hidden"),i.visible(!0)?$("#wikipedpla").show("slow"):$(t).on("scroll",n)},g=function{var t=' .dp-img:after { content: " "; background: url(https://upload.wikimedia.org/wikipedia/commons/a/a3/VisualEditor_-_Icon_-_Picture.svg); width: 12px; height: 12px; display: inline-block; background-size: 12px 12px;} } DPLA ',e=!1,i=a,n=i.length;1===n?(t+="item of possible interest:",t+=' "+p(i[0].title)+"."):(t+="items of possible interest:",$.each(i,function(i,r){i+1==n&&(e=!0),e&&(t+=" & "),t+=' "+p(r.title),t+=e?".":","})),t+=" ",u(t)},v=function(t){var e=t.type;if($.isArray(e)){for(var i in e)if(e.hasOwnProperty(i)&&"image"==i.toLowerCase)return!0;return!1}return e&&"image"===e.toLowerCase?!0:!1},m=function{var e=$('li[id^="ca-nstab-"]'),i=e.attr("id"),r="Main Page"===e.text;t._handleResponse||(t._handleResponse=f),"undefined"!=typeof unsafeWindow&&(unsafeWindow._handleResponse=f),"main"!==i.substr(-4)||r||(n.getCategories,n.getOtherTitles,c(n.title))};!function(e){var i=e(t);e.fn.visible=function(t,e,n){if(!(this.length<1)){var r=this.length>1?this.eq(0):this,o=r.get(0),s=i.width,a=i.height,n=n?n:"both",l=e===!0?o.offsetWidth*o.offsetHeight:!0;if("function"==typeof o.getBoundingClientRect){var c=o.getBoundingClientRect,f=c.top>=0&&c.top0&&c.bottom<=a,d=c.left>=0&&c.left0&&c.right<=s,u=t?f||h:f&&h,g=t?d||d:d&&p;if("both"===n)return l&&u&&g;if("vertical"===n)return l&&u;if("horizontal"===n)return l&&g}else{var v=i.scrollTop,m=v+a,w=i.scrollLeft,b=w+s,$=r.offset,y=$.top,k=y+r.height,x=$.left,_=x+r.width,R=t===!0?k:y,C=t===!0?y:k,T=t===!0?_:x,I=t===!0?x:_;if("both"===n)return!!l&&m>=C&&R>=v&&b>=I&&T>=w;if("vertical"===n)return!!l&&m>=C&&R>=v;if("horizontal"===n)return!!l&&b>=I&&T>=w}}}}(jQuery),m}(window,document);