User:Lwt/global.js

var wpTb1 var btnArt var btnAlb var request = false; var _timer; var btnBusyImage var btnArtImage var btnAlbImage var wpSumm function init{ if (_timer) clearInterval(_timer); var tlbr=window.document.getElementById("toolbar"); btnBusyImage = "http://images3.wikia.nocookie.net/__cb20100126184912/lyricwiki/images/7/76/LW_btn_busy.gif" btnArtImage = "http://images1.wikia.nocookie.net/__cb20101206073518/lyricwiki/images/d/d8/Lw_btn_user.png"; btnAlbImage ="http://images3.wikia.nocookie.net/__cb20101206073617/lyricwiki/images/d/d1/Lw_btn_disc.png" btnAlb=window.document.getElementById("mw-editbutton-headline"); var objImage = new Image; objImage.src=btnBusyImage; btnAlb.src = btnAlbImage; btnAlb.title = "Set AlbumCover"; btnAlb.onclick=CheckAlbum1; btnArt=window.document.getElementById("mw-editbutton-image"); btnArt.src = btnArtImage; btnArt.title = "Set ArtistPhoto"; btnArt.style.opacity=0.8; btnArt.style.filter = "alpha(opacity=80)" btnArt.onclick=CheckArtist; request = new XMLHttpRequest; }

function CheckAlbum1 { if (btnAlb.src == btnAlbImage) { btnAlb.src=btnBusyImage; GetAlbum; } } function CheckArtist { if (btnArt.src == btnArtImage) { btnArt.src=btnBusyImage; GetArtist; } } function GetAlbum { var urlstr = "/api.php?action=query&generator=imageusage&prop=categories&clcategories=Category:Album&format=xml&giutitle=" + encodeURIComponent(wgPageName).replace('.','%2E'); request.open("GET", urlstr, true); request.onreadystatechange = parseAlbum; request.send(null); return false; } function parseAlbum { if (request.readyState == 4) { if (request.status == 200) { var oreg =/:]+?):([^>]+?) \((\d+)\))"><categories/; var m= oreg.exec(request.responseText); if (m) { wpTb1.value="{" + "{AlbumCover\n|artist = " + unescape(m[2]) + "\n|album = " + unescape(m[3]) + "\n|year   = " + m[4] + "\n|source = \n|info   = \n}}"; wpSumm.value="AlbumCover"; } else wpTb1.value="{" + "{AlbumCover\n|artist = \n|album = \n|year   = \n|source = \n|info   = \n}}"; btnAlb.src = btnAlbImage; } } } function GetArtist { var urlstr = "http://lyrics.wikia.com/api.php?action=query&generator=imageusage&prop=categories&clcategories=Category:Artist&format=xml&giutitle=" + encodeURIComponent(wgPageName).replace('.','%2E'); request.open("GET", urlstr, true); request.onreadystatechange = parseArtist; request.send(null); return false; } function parseArtist { if (request.readyState == 4) { if (request.status == 200) { var oreg =/]+?)"><categories/; var m =oreg.exec(request.responseText); var art=(m) ? m[1] : ''; wpTb1.value="{" + "{ArtistPhoto\n|artist = " + art+ "\n|site  = \n|url    = \n|dirurl = \n|info   = \n}}"; btnArt.src = btnArtImage; } } }

function CheckPage { if ((wgAction=="edit") && (wgNamespaceNumber==6)){ wpTb1 = window.document.getElementById("wpTextbox1"); wpSumm=document.getElementById("wpSummary"); if (isIE) _timer = setInterval(init, 300); else init; } } var isIE = /*@cc_on!@*/false; //alert(isIE); if (isIE) window.attachEvent('onload', CheckPage); else window.addEventListener('load', CheckPage, false);