Jump to content

User:Phette23/Scripts/FindDPLA.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
!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('<script src="'+l(t)+'"></script>')},f=function(t){s=t;var e=s.docs.length;e>0?d(g):o<n.otherTitles.length?(c(n.otherTitles[o]),o++):r<n.categories.length&&(c(n.categories[r]),r++)},h=function(t,e){var i=parseInt(e,10)||60,n=t.replace(/(\s\/)$/,"");return n.length>i?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='<style>.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;} }</style><div id="wikipedpla" class="dablink" style="display:none;"><a href="http://dp.la">DPLA</a> ',e=!1,i=a,n=i.length;1===n?(t+="item of possible interest:",t+=' <a href="'+p(i[0].uri)+'"',i[0].isImage&&(t+=' class="dp-img"'),t+=">"+p(i[0].title)+"</a>."):(t+="items of possible interest:",$.each(i,function(i,r){i+1==n&&(e=!0),e&&(t+=" & "),t+=' <a href="'+p(r.uri)+'"',r.isImage&&(t+=' class="dp-img"'),t+=">"+p(r.title),t+=e?"</a>.":"</a>,"})),t+="</div>",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.top<a,h=c.bottom>0&&c.bottom<=a,d=c.left>=0&&c.left<s,p=c.right>0&&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);