the source is over 100KB, syntax highlighting in the browser is too slow
// ==UserScript==
// @name Geordie - Beta 9
// @author BrianFreud
// @namespace MBVA
// @include http://musicbrainz.org/release/*
// @description beta 9: Feb 27: Discogs code entirely rewritten to be much more flexible. Added release comparison popup. Turns off the empty track times filed now that that code is actually being used - Discogs now auto-populates when it has a matching release. I/O request status meter is a little screwy at the moment, it's off a bit with the new Discogs code. A lot more 'under the hood' improvements. Next up: adding Discogs ARs... Don't forget - install the script, but copy/paste over it the code from http://userscripts.org/scripts/review/22970?format=txt , where UserScripts doesn't randomly insert characters. For those playing with this, please let me know what you think! Some comments would be great!
// @Version beta 8: VA track titles are also now inlined. Distortion line causes by iframe ought to now be gone. Added basic button controls. Added the first bits of edit controls, plus edit 'popup' window - please let me know if it's rendering incorrectly for you. And, with many thanks to dmppanda for his js tips, rewrote the annotation parsers - they now handle lists, etc, correctly too. Also some code cleanup and optimization, it ought to be a bit faster to react now.
// Credits: getElementsByClass and $ by Dustin Diaz
// addGlobalStyle() by Mark Pilgrim
// ==/UserScript==
var currentVerified = "";
var storedRelease = [];
var preStatusOCount = 0;
var preStatusICount = 0;
var currentlyViewing = "";
var popupActive = false;
var vArtistDatesB = [];
var vArtistDatesD = [];
var vfbURLAD = [];
var vfbURLAU = [];
var checkBork = [];
var rReleaseTrackCount = 0;
checkBork[0] = '%28legal%29';
checkBork[1] = '%28medical%29';
checkBork[2] = '%28medicine%29';
checkBork[3] = '%28country%29';
checkBork[4] = '%28state%29';
checkBork[5] = 'fuseaction';
checkBork[6] = 'VideoID';
checkBork[7] = '/search';
checkBork[8] = '/Search';
checkBork[9] = '%28planet%29';
checkBork[10] = '%28astronomy%29';
checkBork[11] = 'soundlike';
checkBork[12] = 'video_result';
checkBork[13] = '/listeners/';
checkBork[14] = '/Wikipedia:Deletion_review/';
checkBork[15] = '/Log/';
checkBork[16] = '/User_talk:';
checkBork[17] = 'wiki/Template:';
var counter2 = 0;
var counter3 = 0;
var debug = GM_getValue('debug', false);
var timeDelay = 1000;
var DiscogsKey = "5738d50d3c";
var fbArtistType = [];
var firsttime = GM_getValue('firsttime', true);
var seenURLs = [];
var siteCDBaby = "cdbaby.com";
var siteDiscogs = "discogs.com";
var siteDiscogsArtist = siteDiscogs + "%2Fartist";
var siteDiscogsLabel = siteDiscogs + "%2Flabel";
var tracktitlelengthlimit = 255;
var siteDiscogsRelease = siteDiscogs + "%2Frelease";
var siteIMDb = "imdb.com";
var annotation = "view";
var siteJamendo = "jamendo.com/en/artist";
var siteMusicmoz = "musicmoz.org";
var siteMusicmozArtist = siteMusicmoz + "%2FBands_and_Artists";
var siteMusicmozRelease = "Discography";
var siteMySpace = "www.myspace.com";
var siteOzon = "www.ozon.ru/multimedia -site:www.ozon.ru/multimedia/books";
var sitePureVolume = "purevolume.com -site:www.purevolume.com/forums";
var siteWikipedia = "wikipedia.org -site:wikipedia.org/wiki/User";
var rMBID = location.href.replace("http://musicbrainz.org/release/", "").split(".")[0];
var VACounter2 = 0;
var peachDiv = getElementsByClass('edit')[0];
var annotationString = "";
var startLink = document.createElement("a");
var fbDateB = [];
var fbDateD = [];
var fbATags = [];
startLink.style.cursor = 'pointer';
startLink.id = "startLink";
startLink.addEventListener("click", startScript, true);
startLink.innerHTML = "BETA";
peachDiv.appendChild(document.createTextNode(" [ "));
peachDiv.appendChild(startLink);
peachDiv.appendChild(document.createTextNode(" ]"));
var VACounter = 0;
if (GM_getValue('debug', false) === true) GM_registerMenuCommand('Debug Mode off', debugSwitch);
else GM_registerMenuCommand('Debug Mode on', debugSwitch);
var URLARs = ['artist','release','label'];
URLARs['artist'] = [[2,"has an official homepage at","Indicates the official home page for an artist.",""],
[3,"has a fan page at","Indicates a homepage by a fan for an artist.",""],
[4,"has a biography page at","Indicates a webpage with a biography of an artist.",""],
[5,"has a discography page at","Indicates a webpage with a discography of an artist. ",""],
[7,"music can be purchased for download at","Indicates a webpage where you can purchase an artist's work for download.",""],
[8,"music can be downloaded for free at","Indicates a webpage where you can download an artist's work for free.",""],
[10,"has a Wikipedia page at","Points to the Wikipedia page for this artist.","Wikipedia"],
[11,"has a Discogs page at","Points to the Discogs page for this artist.","Discogs"],
[12,"has a MusicMoz page at","Points to the MusicMoz page for this artist.","MusicMoz"],
[14,"has a picture at","Indicates a pictorial image (JPEG, GIF, PNG) of an artist.",""],
[15,"music can be purchased for mail-order at","Indicates a webpage where you can purchase an artist's work for mail-order.",""],
[17,"has an IMDb page at","Points to the Internet Movie Database page for this artist.","IMDb"],
[19,"has a MySpace page at","This relationship type can be used to link a MusicBrainz artist to the equivalent entry in MySpace.","MySpace"],
[21,"has an online community page at","This relationship type can be used to link a MusicBrainz artist to their online community pages.",""],
[21,"has a PureVolume page at","This relationship type can be used to link a MusicBrainz artist to the equivalent entry in PureVolume.","PureVolume"],
[24,"has a blog at","This relationship type can be used to link a MusicBrainz artist to their weblogs.",""]];
URLARs['release'] = [[17,"has a review page at","Indicates a webpage that reviews the work of an artist.",""],
[19,"can be purchased for mail-order at","Indicates a webpage where you can purchase an album for mail-order.",""],
[20,"can be purchased for download at","Indicates a webpage where you can purchase an album for download.",""],
[21,"can be downloaded for free at","Indicates a webpage where you can download an album for free.",""],
[23,"has a Wikipedia page at","Points to the Wikipedia page for this album.","Wikipedia"],
[24,"has a Discogs page at","Points to the Discogs page for this album.","Discogs"],
[25,"has a MusicMoz page at","Points to the MusicMoz page for this album.","MusicMoz"],
[27,"is a soundtrack for the movie with an IMDb page at","Relates a soundtrack album to the Internet Movie Database page for the movie of which it is a soundtrack.","IMDb"],
[30,"has Amazon ASIN","This link type is used for Amazon ASINs.","Amazon"],
[34,"has cover art at","This link is used to deep-link to cover art on other retailers sites.","CDBaby_Jamendo_Ozon"]];
URLARs['label'] = [[3,"has an official homepage at","This link points to (one of) the official website(s) of the label",""],
[4,"has its history presented at","This link points to a site describing relevant facts about the label history.",""],
[5,"has a catalog of records at","This link points to a site that contains a catalog (eg: list) of records published by the label.",""],
[6,"has a logo at","This is used to provide a logo for the label.",""],
[7,"has a fan page at","This link is used to relate to a label's fans site",""],
[10,"has a MySpace page at","This relationship type can be used to link a MusicBrainz label to the equivalent entry in MySpace.","MySpace"],
[8,"has a Wikipedia page at","This is used to link a label to its corresponding Wikipedia page.","Wikipedia"],
[9,"has a Discogs page at","This is used to link a Label to the equivalent entry in Discogs.","Discogs"]];
var objectTypes = ['artist','release','label'];
objectTypes['artist'] = ['Person','Group','Unknown'];
objectTypes['release'] = ['unknown','album','single','EP','compilation','soundtrack','spokenword','interview','audiobook','live','remix','other'];
objectTypes['label'] = [];
function getElementsByClass(searchClass, node, tag) {
var classElements = [];
if (node == null) {
node = document;
}
if (tag == null) {
tag = '*';
}
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\\\s)" + searchClass + "(\\\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if (pattern.test(els[i].className)) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
function insertChar(string, chr, nth) {
var output = '';
for (var i = 0; i < string.length; i++) {
if (i > 0 && i % nth === 0) output = output + chr;
output += string.charAt(i);
}
return output;
}
function debugMessage(message, i) {
var iTime = fullTime();
debugCell.appendChild(document.createTextNode(message));
if (i) debugCell.appendChild(document.createTextNode(" " + iTime));
debugCell.appendChild(document.createTextNode("."));
debugCell.appendChild(document.createElement('br'));
}
function popupPrompt(text, EditType, objectType) {
if(popupActive === false) {
popupActive = true;
var v = makeElement('div', '25%', '25%', '40%', '40%', '1%', '1px', '1px outset', 'grey', 'fixed', false);
var u = makeElement('span', 0, 0, '1em', text.length + 'em', 0, '0 none', '', 'relative', true);
var x = makeElement('div', '-8px', '-6px', '96%', '97%', '2%', '5px', '1px outset', '#E3E3E3', 'relative', true);
popupText = makeElement('div', '2%', 0, '36%', '80%', '4%', '1em 1em 2em', '1px solid #000', '#fcfcfc', 'relative', false);
popupText.style.textAlign = "left";
u.appendChild(document.createTextNode(text));
var EditForm = document.createElement("form");
switch (EditType) {
case "addURL":
var URLDropDown = document.createElement("select");
URLDropDown.name = "URLDropDown";
for(var i=0;i<URLARs[objectType].length;i++) {
var selectOption = document.createElement("option");
selectOption.value = objectType+"_"+i;
selectOption.innerHTML = URLARs[objectType][i][1];
URLDropDown.appendChild(selectOption);
}
URLDropDown.addEventListener("change",function() {
currentURLARType = this.value.split('_')[0];
currentURLARValue = this.value.split('_')[1];
popupText.innerHTML = "";
var j = URLARs[currentURLARType][currentURLARValue][3];
if(j.length > 0) {
j = j.split("_");
var popupTextDiv = document.createElement('div');
popupTextDiv.align = 'center';
for(var k=0;k<j.length;k++) {
var siteImg = updateUser('',j[k],'','other','','','','','','',1);
siteImg.style.width = "";
popupTextDiv.appendChild(siteImg);
}
popupText.appendChild(popupTextDiv);
}
descriptionText = URLARs[currentURLARType][currentURLARValue][2];
popupText.appendChild(document.createElement('br'));
popupText.appendChild(document.createTextNode(descriptionText));
}, false);
EditForm.appendChild(URLDropDown);
case "editType":
var URLDropDown = document.createElement("select");
URLDropDown.name = "URLDropDown";
for(var i=0;i<URLARs[objectType].length;i++) {
var selectOption = document.createElement("option");
selectOption.value = objectType+"_"+i;
selectOption.innerHTML = objectTypes[objectType][i];
URLDropDown.appendChild(selectOption);
}
default:
}
u.style.fontWeight = "700";
u.style.fontSize = "1.1em";
v.style.zIndex = '100';
v.appendChild(x);
x.appendChild(u);
x.appendChild(document.createElement('br'));
x.appendChild(document.createElement('br'));
x.appendChild(EditForm);
x.appendChild(popupText);
var za = makeButton('Okay', 'large');
za.addEventListener('click', function() { alert("Not implemented yet"); }, false);
var zb = makeButton('Cancel', 'large');
zb.addEventListener('click', popupAway, false);
x.appendChild(za);
x.appendChild(zb);
targetPoint.appendChild(v);
}
}
function popupAway() {
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
popupActive = false;
}
function makeButton(text, size) {
var x = makeElement('span', '', '5px', '', '', '4px', '5px', '1px outset', "#D3D3D3", 'relative', true);
x.appendChild(document.createTextNode(' ' + text + ' '));
x.style.cursor = 'pointer';
x.style.fontWeight = "700";
switch (size) {
case "xsmall":
x.style.fontSize = ".6em";
break;
case "small":
x.style.fontSize = ".8em";
break;
case "medium":
x.style.fontSize = "1em";
break;
case "large":
x.style.fontSize = "1.2em";
break;
case "xlarge":
x.style.fontSize = "1.5em";
break;
}
x.addEventListener('mousedown', pushedButton, false);
x.addEventListener('mouseup', releasedButton, false);
return x;
}
function pushedButton() {
this.style.border = '1px inset';
}
function releasedButton() {
this.style.border = '1px outset';
}
function makeElement(type, top, left, height, width, padding, margin, border, backgroundColor, position, center) {
var a = document.createElement(type);
a.style.top = top;
a.style.left = left;
a.style.height = height;
a.style.width = width;
a.style.margin = margin;
a.style.padding = padding;
a.style.border = border;
a.style.backgroundColor = backgroundColor;
a.style.position = position;
if (center) a.align = 'center';
return a;
}
function isIn(theValue, typeSearch) {
if (theValue === undefined) return true;
if (theValue === "") return true;
for (var checkValue = 0; checkValue < seenURLs.length; checkValue++) {
if ((seenURLs[checkValue] == theValue)) return true;
}
var bogusity = new RegExp();
var x = false;
switch (typeSearch) {
case "artist":
bogusity.compile("album%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
bogusity.compile("label%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
break;
case "release":
bogusity.compile("band%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
bogusity.compile("label%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
break;
case "label":
bogusity.compile("band%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
bogusity.compile("album%29");
if (bogusity.test(theValue)) {
x = true;
break;
}
break;
default:
}
seenURLs.push(theValue);
for (checkValue = 0; checkValue < checkBork.length; checkValue++) {
bogusity.compile(checkBork[checkValue]);
if (bogusity.test(theValue)) x = true;
}
return x;
}
function StatusOUp() {
$('statusOut').innerHTML = String(Number($('statusOut').innerHTML) + 1);
}
function StatusODown() {
$('statusOut').innerHTML = String(Number($('statusOut').innerHTML) + 1);
}
function StatusIUp() {
$('statusIn').innerHTML = String(Number($('statusIn').innerHTML) + 1);
}
function StatusIDown() {
$('statusIn').innerHTML = String(Number($('statusIn').innerHTML) + 1);
}
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string') element = document.getElementById(element);
if (arguments.length == 1) return element;
elements.push(element);
}
return elements;
}
function stripSite() {
document.body.style.display = "none"; // Faster DOM modifications if they're not repainting as the DOM is changed
if (debug === true) debugMessage("Started tearing apart page at", true);
var r = getElementsByClass('partnerlinks');
var x = getElementsByClass('asin');
if (x[0]) {
var j = x[0].parentNode.parentNode;
document.body.appendChild(x[0]);
}
x = $('footerbar');
x.parentNode.removeChild(x);
if ($('RelatedModsBox')) {
x = $('RelatedModsBox');
x.parentNode.removeChild(x);
}
if ($('sidebar-td')) {
x = $('sidebar-td');
x.parentNode.removeChild(x);
}
x = $('creditsbar');
x.parentNode.removeChild(x);
x = $('sidebar-togglecell');
if (x) x.parentNode.removeChild(x);
x = $('submenu-table');
x.parentNode.removeChild(x);
x = getElementsByClass('toc');
for (var i = 0; i < x.length; i++) {
x[i].parentNode.parentNode.removeChild(x[i].parentNode);
}
x = getElementsByClass('annotation')[0];
if (x) x.parentNode.removeChild(x);
x = document.getElementsByTagName('a');
var toRemove = [];
var toRemove2 = [];
for (i = 0; i < x.length; i++) {
var y = x[i].parentNode;
if (x[i].innerHTML == "Edit") {
toRemove.push(x[i]);
}
if (x[i].innerHTML == "Edit release events") {
x[i].style.visibility = "hidden";
}
}
for (i = 0; i < toRemove.length; i++) {
if (i < (toRemove.length - 1)) toRemove[i].parentNode.parentNode.removeChild(toRemove[i].parentNode);
else {
var v = toRemove[i].parentNode.parentNode;
v.parentNode.removeChild(v);
}
}
x = document.getElementsByTagName('table');
targetPoint = x[6];
x[10].parentNode.removeChild(x[10]);
x[7].parentNode.removeChild(x[7]);
x = x[4].getElementsByTagName('tr');
x[3].parentNode.removeChild(x[3]);
x[2].style.visibility = "collapse";
x[1].parentNode.removeChild(x[1]);
x = getElementsByClass('RelationshipBox');
x[0].parentNode.removeChild(x[0]);
x = document.getElementsByTagName('img');
x[2].style.width = "27px";
x[2].style.height = "27px";
x = document.getElementsByTagName('a');
x[12].style.padding = "4px";
x[12].innerHTML = x[12].innerHTML;
x[12].parentNode.appendChild(document.createTextNode(" : " + rRelease));
x = getElementsByClass('relationships');
for (i = 0; i < x.length; i++) {
x[i].parentNode.removeChild(x[i]);
}
var toReplace = [];
var z = [];
x = getElementsByClass('title');
x = x[0].parentNode.parentNode.parentNode.parentNode.getElementsByTagName('a');
for (i = 3; i < x.length; i++) {
z[i] = document.createElement('span');
if (x[i].innerHTML != "Edit release events") z[i].innerHTML = x[i].innerHTML;
x[i].parentNode.replaceChild(z[i], x[i]);
x[i] = x[i--];
}
x = document.getElementsByTagName('img');
toRemove = [];
for (i = 0; i < x.length; i++) {
if (x[i].alt == "TRM" || x[i].alt == "PUID" || x[i].alt == "Toggle release") toRemove.push(x[i]);
}
for (i = 0; i < toRemove.length; i++) {
toRemove[i].parentNode.removeChild(toRemove[i]);
}
x = getElementsByClass('batchop');
x[0].parentNode.removeChild(x[0]);
x = document.getElementsByTagName('p');
if (x[1]) x[1].parentNode.removeChild(x[1]);
if (!r.parentNode) {} else r = r.parentNode.removeChild(r);
if (debug === true) debugMessage("Finished tearing apart page at", true);
}
function drawSite() {
if (debug === true) debugMessage("Starting redesign of page at", true);
var v = targetPoint.parentNode.parentNode.parentNode;
v.parentNode.style.backgroundColor = "white";
targetPoint.style.background = "white";
/* --------------------------------------------------------------
Cover Art and Dimensions
-------------------------------------------------------------- */
var x = getElementsByClass('asin');
if (x[0]) {
targetPoint.parentNode.appendChild(x[0]);
x[0].style.position = "absolute";
x[0].style.top = "158px";
x[0].style.right = "15px";
x[0].style.height = "225px";
x[0].style.width = "auto";
var imgDimsT = document.createElement('div');
imgDimsT.style.fontWeight = "bold";
imgDimsT.id = "imageInfo";
imgDimsT.innerHTML = "( " + x[0].width + " x " + x[0].height + " )";
targetPoint.appendChild(imgDimsT);
imgDimsT.style.position = "absolute";
imgDimsT.style.paddingLeft = (screen.width - x[0].width + 15) + "px";
imgDimsT.width = x[0].width + "px";
imgDimsT.style.margin = "0 auto";
imgDimsT.style.top = "386px";
}
/* --------------------------------------------------------------
Status window
-------------------------------------------------------------- */
statusLine = document.createElement('tr');
targetPoint.appendChild(statusLine);
statusCell.style.overflow = "scroll";
statusCell.style.overflowY = "scroll";
statusCell.style.padding = "4px";
statusLine.appendChild(statusContainer1);
statusContainer1.appendChild(statusContainer2);
statusContainer1.style.height = "275px";
statusContainer1.style.width = "100%";
statusContainer2.appendChild(statusCell);
statusContainer1.colSpan = "3";
statusLine.style.position = "relative";
statusContainer1.style.position = "relative";
statusContainer2.style.position = "absolute";
statusContainer2.style.top = "158px";
statusContainer2.style.left = "15px";
statusContainer2.style.height = "300px";
statusContainer2.style.width = "70%";
statusCell.style.position = "absolute";
statusCell.style.top = "52px";
statusCell.style.left = "0";
statusCell.style.overflowX = "auto";
statusCell.style.overflowY = "auto";
statusCell.style.height = "233px";
statusCell.style.width = "100%";
statusOut.id = "statusOut";
statusIn.id = "statusIn";
/* --------------------------------------------------------------
Debug window
-------------------------------------------------------------- */
if (debug === true) {
targetPoint.appendChild(document.createElement('br'));
var debugLine = document.createElement('tr');
targetPoint.appendChild(debugLine);
debugCell.style.backgroundColor = "#DDAABB";
debugCell.style.border = "solid thin";
debugCell.style.padding = "4px";
debugCell.colSpan = "3";
debugLine.appendChild(debugCell);
}
/* --------------------------------------------------------------
Three incoming data columns
-------------------------------------------------------------- */
targetPoint.appendChild(document.createElement('br'));
var dataLine = document.createElement('tr');
targetPoint.appendChild(dataLine);
dataCenter.style.backgroundColor = "#CDD6FF";
dataCenter.style.border = "solid thin";
dataCenter.style.padding = "4px";
dataCenter.style.verticalAlign = "top";
dataCenter.style.whiteSpace = "-moz-pre-wrap !important";
dataCenter.style.width = "33% !important";
dataLeft.style.backgroundColor = "#CDD6FF";
dataLeft.style.border = "solid thin";
dataLeft.style.padding = "4px";
dataLeft.style.verticalAlign = "top";
dataLeft.style.whiteSpace = "-moz-pre-wrap !important";
dataLeft.style.width = "33% !important";
dataRight.style.backgroundColor = "#CDD6FF";
dataRight.style.border = "solid thin";
dataRight.style.padding = "4px";
dataRight.style.verticalAlign = "top";
dataRight.style.whiteSpace = "-moz-pre-wrap !important";
dataRight.style.width = "33% !important";
dataCenter.style.overflowY = "scroll";
dataLeft.style.overflowY = "scroll";
dataRight.style.overflowY = "scroll";
dataCenter.style.height = "40%";
dataLeft.style.height = "40%";
dataRight.style.height = "40%";
dataLine.appendChild(dataLeft);
dataLine.appendChild(dataCenter);
dataLine.appendChild(dataRight);
/* --------------------------------------------------------------
Reset "button"
-------------------------------------------------------------- */
resetLink3 = document.createElement('div');
resetLink3.style.marginRight = "4px";
resetLink3.style.marginBottom = "4px";
resetLink3.style.color = "inherit";
resetLink3.style.backgroundColor = "#ccc";
resetLink2 = document.createElement('div');
resetLink2.style.marginRight = "2px";
resetLink2.style.marginBottom = "2px";
resetLink2.style.color = "inherit";
resetLink2.style.backgroundColor = "#666";
resetLink1 = document.createElement('div');
resetLink1.style.padding = ".5em 1ex";
resetLink1.style.border = "1px solid #000";
resetLink1.style.backgroundColor = "white";
resetLink0 = document.createElement('a');
resetLink0.innerHTML = "RESET";
resetLink0.style.fontSize = "18px";
resetLink0.style.textColor = "red";
resetLink0.href = location.href;
resetLink3.style.position = "absolute";
resetLink3.style.top = "100px";
resetLink3.style.right = "30px";
resetLink1.appendChild(resetLink0);
resetLink2.appendChild(resetLink1);
resetLink3.appendChild(resetLink2);
targetPoint.parentNode.appendChild(resetLink3);
/* --------------------------------------------------------------
IFrame and Close Button
-------------------------------------------------------------- */
hiddenWindow = makeElement('div', '5%', '10%', '90%', '80%', '', '', '', '', 'fixed', 'true');
openTarget = makeElement('iframe', '1%', '', '90%', '100%', '', '', '', 'white', 'relative', 'false');
closeTarget = makeButton('Hide Window', 'xlarge');
hiddenWindow.style.display = "none";
closeTarget.style.textAlign = "center";
closeTarget.style.width = "100%";
openTarget.scrolling = "vertical";
openTarget.style.zIndex = "100";
closeTarget.style.zIndex = "100";
openTarget.id = "openTarget";
closeTarget.id = "closeTarget";
closeTarget.addEventListener("click", hideIframe, true);
hiddenWindow.appendChild(closeTarget);
hiddenWindow.appendChild(openTarget);
targetPoint.appendChild(hiddenWindow);
/* --------------------------------------------------------------
New Version Notification
-------------------------------------------------------------- */
versionAlert = document.createElement('a');
versionAlert.style.top = "158px";
versionAlert.style.marginLeft = "30%";
versionAlert.style.marginRight = "30%";
versionAlert.style.fontWeight = "bold";
versionAlert.style.fontSize = "1.5em";
versionAlert.style.position = "absolute";
versionAlert.innerHTML = "New Version of Script Available!";
versionAlert.href = "http://userscripts.org/scripts/show/22970";
versionAlert.style.visibility = "hidden";
targetPoint.appendChild(versionAlert);
versionAlert.id = "versionAlert";
/* --------------------------------------------------------------
Annotations
-------------------------------------------------------------- */
targetPoint.appendChild(document.createElement('br'));
var annoTitle2 = document.createElement('tr');
var annoTitle = document.createElement('td');
annoTitle.colSpan = "3";
annoTitle.align = "center";
annoTitle.innerHTML = "Release Annotation";
annoTitle.style.fontWeight = "700";
annoTitle2.appendChild(annoTitle);
targetPoint.appendChild(annoTitle2);
var annoRow = document.createElement('tr');
targetPoint.appendChild(annoRow);
var annoCell2 = document.createElement('td');
annoRow.appendChild(annoCell2);
annoCell2.colSpan = "3";
annoCell = document.createElement('div');
annoCell2.appendChild(annoCell);
annotationEditCell = document.createElement('textarea');
annotationDisplayCell = document.createElement('div');
annotationDisplayCell.style.display = "inline";
annotationEditCell.style.display = "none";
annotationDisplayCell.style.padding = "4px";
annotationDisplayCell.style.overflow = "auto";
annotationDisplayCell.style.overflowY = "scroll";
annotationDisplayCell.style.overflowX = "hidden";
annotationEditCell.style.padding = "4px";
annotationEditCell.style.overflow = "auto";
annotationEditCell.style.overflowY = "scroll";
annotationEditCell.style.overflowX = "hidden";
annotationEditCell.style.wrap = "physical";
annoCell.style.position = "relative";
annoCell.style.height = "220px";
annoCell.style.width = "100%";
annoCell.appendChild(annotationEditCell);
annoCell.appendChild(annotationDisplayCell);
annotationEditCell.style.position = "absolute";
annotationDisplayCell.style.position = "absolute";
annotationEditCell.style.top = "0";
annotationEditCell.style.left = "1px";
annotationDisplayCell.style.top = "0";
annotationDisplayCell.style.height = "90%";
annotationEditCell.style.height = "90%";
annotationEditCell.style.width = "99%";
annotationDisplayCell.style.width = "99%";
annotationDisplayCell.style.backgroundColor = "white";
annotationEditCell.style.border = "thin solid black";
annotationDisplayCell.style.border = "thin solid black";
annotationEditCell.scrolling = "vertical";
annotationDisplayCell.scrolling = "auto";
annotationSpacer1 = document.createElement('div');
annotationSpacer2 = document.createElement('div');
annotationTabView = document.createElement('div');
annotationSpacer1.style.position = "absolute";
annotationSpacer2.style.position = "absolute";
annotationTabView.style.position = "absolute";
annotationSpacer1.style.bottom = "0";
annotationSpacer2.style.bottom = "0";
annotationTabView.style.bottom = "0";
annotationSpacer1.style.left = "0";
annotationSpacer2.style.right = "0";
annotationTabView.style.left = "35%";
annotationTabView.align = "center";
annotationSpacer1.style.border = "medium none white";
annotationSpacer2.style.border = "medium none white";
annotationTabView.style.backgroundColor = "#D3D3D3";
annotationTabView.style.padding = "2px";
annotationTabView.style.fontWeight = "700";
annotationTabView.style.fontSize = "1.1em";
annotationSpacer1.style.width = "30%";
annotationSpacer2.style.width = "30%";
annotationTabView.style.width = "8%";
annotationSpacer1.style.height = "10%";
annotationSpacer2.style.height = "10%";
annotationTabView.style.height = "9%";
annoCell.appendChild(annotationSpacer1);
annoCell.appendChild(annotationSpacer2);
annotationEditCell.value = annotationString;
annotationDisplayCell.innerHTML = annotationString;
annotationSpacer1.innerHTML = " ";
annotationSpacer2.innerHTML = " ";
annotationTabEdit = makeButton('Edit Annotation', 'medium');
annotationTabView = makeButton('View Annotation', 'medium');
annotationTabEdit.id = "annotationEdit";
annotationTabView.id = "annotationView";
annotationTabEdit.addEventListener("click", flipAnnotation, false);
annotationTabView.addEventListener("click", flipAnnotation, false);
annotationTabEdit.style.display = "inline";
annotationTabView.style.display = "none";
var annoBtnsTR = document.createElement('tr');
var annoBtnsTD = document.createElement('td');
var annoBtnsDiv = document.createElement('div');
annoBtnsTD.appendChild(annoBtnsDiv);
annoBtnsTD.colSpan = 3;
annoBtnsTR.appendChild(annoBtnsTD);
targetPoint.appendChild(annoBtnsTR);
annoBtnsDiv.appendChild(annotationTabEdit);
annoBtnsDiv.appendChild(annotationTabView);
annoBtnsDiv.align = "center";
/* --------------------------------------------------------------
GM icon
-------------------------------------------------------------- */
monkeyHead = document.createElement('img');
monkeyHead.src = "http://static.userscripts.org/images/gravatar_default.png";
monkeyHead.style.position = "absolute";
monkeyHead.style.top = "10px";
monkeyHead.style.right = "15px";
monkeyHead.style.height = "45px";
monkeyHead.style.width = "auto";
targetPoint.appendChild(monkeyHead);
/* ------------------------------------------------------------ */
var argh = getElementsByClass("cover");
if (argh.length > 0) argh[0].parentNode.removeChild(argh[0]);
if (debug === true) debugMessage("Finished redesign of page at", true);
document.body.style.display = "block"; // Turn the page back on
}
function flipAnnotation(which) {
if (this.id == "annotationView") {
annotationString = annotationEditCell.value;
if (debugAnnotationHTML !== true) convertToHTML();
annotationDisplayCell.innerHTML = annotationString;
annotationDisplayCell.style.display = "inline";
annotationEditCell.style.display = "none";
annotationTabView.style.display = "none";
annotationTabEdit.style.display = "inline";
} else if (this.id == "annotationEdit") {
if (debugAnnotationMarkup !== true) convertToMarkup();
annotationEditCell.value = annotationString;
annotationDisplayCell.style.display = "none";
annotationEditCell.style.display = "inline";
annotationTabView.style.display = "inline";
annotationTabEdit.style.display = "none";
} else {
//initialization routine
if (debugAnnotationMarkup !== true) convertToMarkup();
annotationEditCell.value = annotationString;
if (debugAnnotationHTML !== true) convertToHTML();
annotationDisplayCell.innerHTML = annotationString;
}
}
function openIframe() {
if(popupActive === false) {
popupActive = true;
if(currentlyViewing == "")
openTarget.src = this.name;
else openTarget.src = currentlyViewing;
hiddenWindow.style.display = "inline";
var x = getElementsByClass('asin');
if (x[0]) x[0].style.visibility = "collapse";
}
}
function hideIframe() {
popupActive = false;
document.getElementById("KeyFrame").style.display = "inline";
hiddenWindow.style.display = "none";
var x = getElementsByClass('asin');
if (x[0]) x[0].style.visibility = "visible";
}
function fullTime() {
var d = new Date();
var cTime = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds();
return cTime;
}
function convertToMarkup() {
var i = 0;
var x = '';
var listDepth = 0;
function convertToMarkupCallback(str) {
switch (str) {
case '<p>':
case '</p>':
case '\n</p>':
case '\n<p>':
return '\n';
case '<em>':
return "''";
case '\n<em>':
return "\n''";
case '\n</em>':
return "\n''";
case '</em>':
return "''";
case '<strong>':
return "'''";
case '\n<strong>':
return "\n'''";
case '\n</strong>':
return "\n'''";
case '</strong>':
return "'''";
case '\n<h1>':
return "\n= ";
case '</h1>':
return " =";
case '\n<h2>':
return "\n== ";
case '</h2>':
return " ==";
case '\n<h3>':
return "\n=== ";
case '</h3>':
return " ===";
case '\n<h4>':
return "\n==== ";
case '</h4>':
return " ====";
case '\n<h5>':
return "\n===== ";
case '</h5>':
return " =====";
case '\n<h6>':
return "\n====== ";
case '</h6>':
return " ======";
case '</a>':
case '\n</a>':
return "]";
case '\n<hr>':
return "\n----";
case '<hr>':
return "----\n";
case '\n<ol>':
case '\n<ul>':
case '<ol>':
case '<ul>':
listDepth++;
return "";
case '\n<br>':
return "\n";
case '\n</ol>':
case '</ol>':
case '\n</ul>':
case '</ul>':
listDepth--;
return '';
case '\n</li>':
case '</li>':
return "";
case '<br>':
case '<code>':
return "";
case '</pre>':
case '</code>':
case '\n</code>':
return "\n";
case '\n<li>':
case '<li>':
x = "";
for (var i = 0; i < listDepth; i++) {
x = x + " ";
}
return '\n' + x + "* ";
case '\n<pre>':
return "\n ";
default:
x = "";
if (str.slice(0, 4) == "\n<li" || str.slice(0, 4) == "<li ") {
for (i = 0; i < listDepth; i++) {
x = x + " ";
}
return '\n' + x + str.split('"')[1] + ". ";
} else return str;
}
}
function makeURL(str) {
x = str.slice(1, str.length);
return "\n[" + x + "|" + x + "]";
}
function clearRedundantLists(str) {
switch (str) {
case '</ol><ol>':
case '</ol>\n<ol>':
return '';
case '</ul><ul>':
case '</ul>\n<ul>':
return '';
case '</ul></li></ul>':
case '</ul></li></ol>':
return '</ul>';
case '</ol></li></ol>':
case '</ul></li></ol>':
return '</ol>';
default:
return str;
}
}
if (annotationString.length > 0) {
annotationString = annotationString.replace(/\[/g, "[");
annotationString = annotationString.replace(/\]/g, "]");
x = annotationString.split(/<a href=\"/);
// Detect which type of anchor we have
annotationString = x[0];
if (x.length > 1) {
for (i = 1; i < x.length; i++) {
x[i] = x[i].replace(/">/, "|");
annotationString = annotationString + "[" + x[i];
}
}
// Strip the first <p> without adding a newline
annotationString = annotationString.replace('<p>', "");
// Catch the 2 cases that can cause ''''''''
annotationString = annotationString.replace(/<\/strong><\/em><strong>/g, "''");
annotationString = annotationString.replace(/<\/em><\/strong><em>/g, "'''");
// Keep spaces before lists
annotationString = annotationString.replace(/<\/p><.?l>/g, "\n<ol>");
annotationString = annotationString.replace(/<\/p><ul>/g, "\n<ul>");
// Text::WikiFormat doesn't do block-level indents
annotationString = annotationString.replace(/\n */g, "\n");
// Convert everything else
annotationString = annotationString.replace(/\n?<.*?>/g, convertToMarkupCallback);
// Text::WikiFormat converts alt-255 into space
annotationString = annotationString.replace(/ /g, " ");
// Linkify those naked urls Text::WikiFormat currently misses
annotationString = annotationString.replace(/\n\b((ftp|https?):\/\/\S*)/g, makeURL);
annotationString = annotationString.replace(/\n\n\n/g, '\n\n');
// Strip whitespace off the end
while (annotationString.length > 0 && annotationString.charAt(annotationString.length - 1).match(/\s/)) {
annotationString = annotationString.slice(0, annotationString.length - 1);
}
}
}
function convertToHTML() {
var i = 0;
var lastDepth = 0;
var lasttype = "";
var listTypes = [];
var currentDepth = 0;
var inList = false;
function addPreAndLists(str, p1, p2) {
var d = 0;
// Fix where the user added an extra 1-3 spaces.
// ----------------------------------------------------------------------------------
// Normalizing levels here means the generated HTML will not
// be 100% 1:1 with Text::WikiFormat-generated HTML. However,
// Text::WikiFormat adds meaningless </ul><ul> and </ol><ol> tags where
// they have no semantic markup or HTML meaning; doing it this way
// is ultimately less confusing for the user, by making depth errors in
// nested lists much easier to spot - the depth difference between '3
// spaces vs 4 spaces' is much more obvious when rerendered in
// markup as '0 spaces vs 4 spaces'.
// ----------------------------------------------------------------------------------
while ((str.length - 4) % 4 > 0) {
str = str.slice(1, str.length);
}
// ----------------------------------------------------------------------------------
// Pre + Code, can only happen at 8 spaces in
if (str.match(/ {8}[^ ..|\* ..|\d\d?\. ?.]/) != null) {
str = '<pre><code>' + str.slice(str.length - 4, str.length);
return str;
}
// ----------------------------------------------------------------------------------
// Now it can only be *, #., or ##. where # can be a number or letter
// If it's *, it's an UL. Otherwise it's an OL.
currentDepth = str.split(' ').length - 1;
var y = "";
switch (str.split(' ')[currentDepth].slice(0, 1)) {
case '*':
if (currentDepth == lastDepth) {
if (lasttype == 'ol') y = '</ol><ul>';
else if (lasttype == '') y = '<ul>';
} else if (currentDepth > lastDepth) {
y = '<ul>';
listTypes[listTypes.length] = 'ul>';
lastDepth = currentDepth;
} else if (currentDepth < lastDepth) {
for (d = lastDepth; d > currentDepth; d--) {
y = y + '</' + listTypes.pop();
}
}
y = y + '<li>' + str.slice(str.length - 2);
lasttype = 'ul';
break;
default:
if (currentDepth == lastDepth) {
if (lasttype == 'ul') y = '</ul><ol>';
else if (lasttype == '') y = '<ol>';
} else if (currentDepth > lastDepth) {
listTypes[listTypes.length] = 'ol>';
y = '<ol>';
lastDepth = currentDepth;
} else if (currentDepth < lastDepth) {
for (d = lastDepth; d > currentDepth; d--) {
y = y + '</' + listTypes.pop();
}
}
var z = str.slice(str.length - 3).split(' ')[1];
if (z == undefined) z = "";
y = y + '<li value="' + str.split('.')[0].replace(/\s/g, '') + '">' + z;
lasttype = 'ol';
break;
}
return y;
}
function convertToHTMLHeadersCallback(str) {
function selector(inputStr) {
switch (inputStr) {
case '\n=':
case '<p>=':
case '=</p>':
case '=':
return 'h1>';
case '\n==':
case '<p>==':
case '==</p>':
case '==':
return 'h2>';
case '\n===':
case '<p>===':
case '===</p>':
case '===':
return 'h3>';
case '\n====':
case '<p>====':
case '====</p>':
case '====':
return 'h4>';
case '\n=====':
case '<p>=====':
case '=====</p>':
case '=====':
return 'h5>';
case '\n======':
case '<p>======':
case '======</p>':
case '======':
return 'h6>';
}
}
var x = str.split(' ');
x[0] = '<' + selector(x[0]);
x[(x.length - 1)] = '</' + selector(x[(x.length - 1)]);
str = x.join("");
return str;
}
function fixLists(str) {
var x = str.slice(0, 7);
var y = str.slice(7, str.length - 4);
y = y.replace(/></g, '>\n<');
switch (x) {
case '<p><ul>':
x = '<ul>\n';
break;
case '<p><ol>':
x = '<ol>\n';
break;
case '</ol><p>':
x = '</ol>';
break;
case '</ul><p>':
x = '</ul>';
break;
}
x = x + y;
return x;
}
function fixHeaders(str) {
return str + '\n';
}
function fixEndOfLists(str) {
var v = str.slice(0, 5);
v = v + '\n<p>';
var w = str.slice(5, str.length - 6);
var y = str.slice(str.length - 1);
if (y == '\n') {
// Only happens if we have a list, then a single text block, then a new list
str = v + w + '</p>' + y;
} else {
str = v + w + '<br>' + y;
}
return str;
}
function fixBreakType(str) {
return '\n<p>' + str.slice(5, str.length);
}
function fixBr(str) {
return str.slice(0, 1) + '<br>\n';
}
function fixPostHrBreak(str) {
return '<hr>\n<p>' + str.slice(9, str.length - 4) + '</p>';
}
function lastFix(str) {
return '</p>' + str.slice(8, str.length);
}
function ILied(str) {
switch (str) {
case '<li>\n':
return '<li>';
case '<p>\n':
return '<p>';
}
}
function preCorrectLists(str) {
return str.slice(0, 1) + '\n<li';
}
if (annotationString.length > 0) {
annotationString = annotationString.replace(/.<li/g, preCorrectLists);
var zzz = annotationString.split('\n');
annotationString = "";
for (i = 0; i < zzz.length; i++) {
if (zzz[i].split(/\s{4}\s*..../).length == 1) {
// close lists
if (inList === true) {
for (d = listTypes.length; d > 0; d--) {
if (d == 1) zzz[i] = '</' + listTypes.shift() + '\n\n' + zzz[i];
else zzz[i] = '</' + listTypes.shift() + zzz[i];
}
lastDepth = 0;
}
} else {
zzz[i] = zzz[i].replace(/\s{4}\s*..../g, addPreAndLists);
inList = true;
}
switch (zzz[i].slice(0, 4)) {
case '<pre':
zzz[i] = '\n' + zzz[i] + '</code></pre>';
break;
case '<li>':
case '<ol>':
case '<ul>':
// Including the next two adds an incorrect </li>, but it blocks paragraphizing of the
// last <li> and the line following the closing tag of a list.
case '</ol':
case '</ul':
case '<li ':
zzz[i] = zzz[i] + '</li>';
break;
default:
}
// Take care of non-<p> line breaks
if (i < zzz.length - 1 && zzz[i].match(/^[\w|"|']/) != null && zzz[i].match(/^[\w|"|']/) != null && zzz[i].length > 0 && zzz[i + 1].length > 0) annotationString = annotationString
+ zzz[i] + '<br>';
else if (i < zzz.length - 1 && zzz[i].match(/>$/) != null && zzz[i].match(/^</) != null) annotationString = annotationString + zzz[i];
else if (zzz[i].match(/-{4}/) != null) annotationString = annotationString + '<hr>';
else annotationString = annotationString + zzz[i] + '\n';
}
annotationString = annotationString.replace(/\n\n/g, "</p>\n<p>");
annotationString = annotationString.replace(/\n/g, "<br>");
// Add the surrounding <p>
annotationString = '<p>' + annotationString + '</p>';
// Link both types of anchors
var x = annotationString.split(/\[/);
if (x.length > 1) {
annotationString = x[0];
for (i = 1; i < x.length; i++) {
if (x[i].indexOf('|') > -1) {
var y = x[i].split(/\|/);
x[i] = '<a href="' + y[0] + '">' + y[1].replace(/\]/, '</a>');
} else {
x[i] = '<a href="' + x[i] + '">' + x[i] + '</a>';
}
annotationString = annotationString + x[i];
}
}
// Distinguish and convert '' and '''
var bold = false;
var italics = false;
// Using the <X> later to clear unwanted linebreaks
for (i = 0; i < annotationString.length; i++) {
if (annotationString.charAt(i) == "'") {
if (annotationString.charAt(i + 1) == "'") {
if (annotationString.charAt(i + 2) == "'") {
if (bold == false) {
annotationString = annotationString.slice(0, i) + '<strong><X>' + annotationString.slice((i + 3));
i += 3;
bold = true;
} else {
annotationString = annotationString.slice(0, i) + '</strong><X>' + annotationString.slice((i + 3));
i += 3;
bold = false;
}
} else {
if (italics == false) {
annotationString = annotationString.slice(0, i) + '<em><X>' + annotationString.slice((i + 2));
i += 2;
italics = true;
} else {
annotationString = annotationString.slice(0, i) + '</em><X>' + annotationString.slice((i + 2));
i += 2;
italics = false;
}
}
}
}
}
// Strip whitespace off the end of the string
while (annotationString.length > 0 && annotationString.charAt(annotationString.length - 1).match(/\s/)) {
annotationString = annotationString.slice(0, annotationString.length - 1);
}
// Scrub the results so they match the HTML shortcuts and line-breaks Text::WikiFormat uses
// ----------------------------------------------------------------------------------------------------------------
annotationString = annotationString.replace(/<p><\/p>\n<p>/g, '<p>');
annotationString = annotationString.replace(/<\/h\d>/g, fixHeaders);
annotationString = annotationString.replace(/.<br>/g, fixBr);
// Cheaper to use <X> here than loop on <strong> and <em>
annotationString = annotationString.replace(/\n?<X>\n?/g, '');
annotationString = annotationString.replace(/\n<ol>/g, '<ol>');
annotationString = annotationString.replace(/\n<ul>/g, '<ul>');
annotationString = annotationString.replace(/<\/p>\n?<br>/g, '</p>');
annotationString = annotationString.replace(/<p>\n<hr>/g, '<hr>');
annotationString = annotationString.replace(/\n<br>.*<\/p>/g, fixBreakType);
annotationString = annotationString.replace(/\n<br>/g, '<br>\n');
annotationString = annotationString.replace(/<hr><br>\n.*<br>/g, fixPostHrBreak);
annotationString = annotationString.replace(/<br>\n\n/g, '<br>\n');
annotationString = annotationString.replace(/<\/p>\n<p><(o|u)l>\n<li>/g, lastFix);
annotationString = annotationString.replace(/<(li|p)>\n/g, ILied);
annotationString = annotationString.replace(/<\/p>\n\n/g, '</p>\n');
annotationString = annotationString.slice(0, annotationString.length - 5);
// code blocks tend to grow tags
annotationString = annotationString.replace(/\n?<p>\n?<br>\n?<pre>\n?/g, '\n<pre>');
annotationString = annotationString.replace(/\n?<\/pre>\n?<br>\n?<\/ol>\n?(<\/li>)?\n?/g, '</pre>\n');
annotationString = annotationString.replace(/<\/pre>\n<br>/g, '</pre>');
annotationString = annotationString.replace(/=<br>/g, '=\n');
annotationString = annotationString.replace(/<p>=/g, '=');
annotationString = annotationString.replace(/=<\/p>/g, '=');
annotationString = annotationString.replace(/(<p>={1,6}\s.+=\s{1,6}<\/p>)|(^={1,6}\s.+\s={1,6}$)/gm, convertToHTMLHeadersCallback);
// Next two lines prevent lists from collapsing over multiple conversions
annotationString = annotationString.replace(/<\/p><ul>/g, '<\/p>\n<ul>');
annotationString = annotationString.replace(/<\/p><ol>/g, '<\/p>\n<ol>');
}
}
function getFreebase(cb) {
var i = 0;
var t = 0;
// VACounter2 does the exact same thing as the original for loop in StartSearching()
VACounter2 = 0;
// VACounter3 is our artist array counter
VACounter3 = 0;
StatusODown();
for (t = 0; t < vArtist.length; t++) {
if (debug === true) debugMessage('Queing FreeBase query for ' + vArtist[t]);
window.setTimeout(getFreebase2, (delayTime * VACounter2));
VACounter2++;
}
}
var getFreebase2 = function() {
// We've waited our turn, not setting the current artist from the array and passing the request
rArtist = vArtist[VACounter3];
rArtistType = vArtistType[VACounter3];
VACounter3++;
if (debug === true) debugMessage('Passing FreeBase query for ' + vArtist[(VACounter3 - 1)]);
fbArtistType[(VACounter3 - 1)] = "";
getFreebase3(doneScrapingFreeBase, (VACounter3 - 1));
};
function getFreebase3(cb, vanum) {
var i = 0;
// Making the request for the artist specified in getFreebase2
var fbURLAD = [];
vfbURLAD[vanum] = fbURLAD;
var fbURLAU = [];
vfbURLAU[vanum] = fbURLAU;
if (rArtistType == "Group" || fbArtistType[vanum] == "whoknows") {
if (debug === true) debugMessage('Querying FreeBase for group (or unknown type)');
if (debug === true) debugMessage('http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/music/artist","active_end":[],"active_start":[],"genre":[],"home_page":[{"description":null,"name":null,"uri":null}],"name":' + '"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"' + '}}}', 1);
if (debug === true) debugMessage('Making FreeBase query for ' + rArtist);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/music/artist","active_end":[],"active_start":[],"genre":[],"home_page":[{"description":null,"name":null,"uri":null}],"name":' + '"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"' + '}}}',
onload: function(responseDetails) {
StatusIUp();
if (responseDetails.responseText.length == 123) {
if (debug === true) debugMessage('Artist not found at FreeBase');
fbArtistType[vanum] = "notfound";
cb(vanum);
} else {
var obj = eval('(' + responseDetails.responseText + ')');
if (!obj.albums) {} else {
if (!obj.albums.result) {} else {
if (!obj.albums.result.home_page[0]) {} else {
for (i = 0; i < obj.albums.result.home_page.length; i++) {
if (obj.albums.result.home_page[i].description !== null) fbURLAD[i] = "<B>" + obj.albums.result.home_page[i].description + "</B>";
if (obj.albums.result.home_page[i].name !== null) fbURLAD[i] = fbURLAD[i] + ": " + obj.albums.result.home_page[i].name;
fbURLAD[i] = fbURLAD[i].replace("undefined: ", "");
fbURLAU[i] = obj.albums.result.home_page[i].uri;
}
}
if (!obj.albums.result.active_start[0]) {} else {
fbDateB[vanum] = obj.albums.result.active_start[0];
}
if (!obj.albums.result.active_end[0]) {} else {
fbDateD[vanum] = obj.albums.result.active_end[0];
}
fbATags[vanum] = [];
if (!obj.albums.result.genre[0]) {} else {
for (i = 0; i < obj.albums.result.genre.length; i++) {
fbATags[vanum][i] = obj.albums.result.genre[i];
}
}
}
}
if (fbDateB[vanum] === undefined) fbDateB[vanum] = "";
if (fbDateD[vanum] === undefined) fbDateD[vanum] = "";
cb(vanum);
}
}
});
} else if (rArtistType == "Person") {
if (debug === true) debugMessage('Querying FreeBase for person');
if (debug === true) debugMessage('http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"genre" : [],"home_page" : [{"description":null,"name":null,"uri":null}],"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '","type":"/music/artist"}}}', 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"genre" : [],"home_page" : [{"description":null,"name":null,"uri":null}],"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '","type":"/music/artist"}}}',
onload: function(responseDetails) {
StatusIUp();
if (responseDetails.responseText.length == 123) {
if (debug === true) debugMessage('Artist not found at FreeBase');
fbArtistType[vanum] = "notfound";
cb(vanum);
} else {
var obj = eval('(' + responseDetails.responseText + ')');
fbATags[vanum] = [];
if (!obj.albums) {} else {
if (!obj.albums.result) {} else {
if (!obj.albums.result.genre[0]) {} else {
for (i = 0; i < obj.albums.result.genre.length; i++) {
fbATags[vanum][i] = obj.albums.result.genre[i];
}
}
if (!obj.albums.result.home_page[0]) {} else {
for (i = 0; i < obj.albums.result.home_page.length; i++) {
if (obj.albums.result.home_page[i].description !== null) fbURLAD[i] = "<B>" + obj.albums.result.home_page[i].description + "</B>";
if (obj.albums.result.home_page[i].name !== null) fbURLAD[i] = fbURLAD[i] + ": " + obj.albums.result.home_page[i].name;
fbURLAD[i] = fbURLAD[i].replace("undefined: ", "");
fbURLAU[i] = obj.albums.result.home_page[i].uri;
}
}
}
}
if (debug === true) debugMessage('Querying FreeBase for birthdate');
if (debug === true) debugMessage('http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/person","date_of_birth":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}', 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/person","date_of_birth":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}',
onload: function(responseDetails) {
StatusIUp();
var obj = eval('(' + responseDetails.responseText + ')');
if (!obj.albums) {} else {
if (!obj.albums.result) {} else {
if (!obj.albums.result.date_of_birth) {} else {
fbDateB[vanum] = obj.albums.result.date_of_birth;
}
}
}
if (debug === true) debugMessage('Querying FreeBase for deathdate');
if (debug === true) debugMessage('http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/deceased_person","date_of_death":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}', 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/deceased_person","date_of_death":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}',
onload: function(responseDetails) {
StatusIUp();
var obj = eval('(' + responseDetails.responseText + ')');
if (!obj.albums) {} else {
if (obj.albums.hasOwnProperty('date_of_death')) {
fbDateB[vanum] = obj.albums.result.date_of_death;
} else fbDateD[vanum] = "";
}
if (fbDateB[vanum] === undefined) fbDateB[vanum] = "";
if (fbDateD[vanum] === undefined) fbDateD[vanum] = "";
cb(vanum);
}
});
}
});
}
}
});
} else {
if (debug === true) debugMessage('Querying FreeBase to try and ID the artist type');
if (debug === true) debugMessage('http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/person","date_of_birth":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}', 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.freebase.com/api/service/mqlread?queries={"albums":{"query":{"type":"/people/person","date_of_birth":null,"name":"' + rArtist.replace(/ /g, "+").replace(/\&/g, "and") + '"}}}',
onload: function(responseDetails) {
StatusIUp();
if (responseDetails.responseText.length == 123) {
if (debug === true) debugMessage('Artist not found at FreeBase');
fbArtistType[vanum] = "notfound";
cb(vanum);
} else {
var obj = eval('(' + responseDetails.responseText + ')');
if (!obj.albums) {} else {
if (obj.albums.hasOwnProperty('date_of_birth')) {
fbArtistType[vanum] = 'Person';
if (debug === true) debugMessage('FreeBase has a matching person entry');
getFreebase3(doneScrapingFreeBase, vanum);
} else {
fbArtistType[vanum] = 'whoknows';
if (debug === true) debugMessage('FreeBase does not have a matching person entry, trying artist as group');
getFreebase3(doneScrapingFreeBase, vanum);
}
}
}
}
});
}
}
function doneScrapingFreeBase(artistNumber) {
var i = 0;
// artistNumber stores which artist in the array we just got info about
if (fbArtistType[artistNumber] != "notfound") {
updateUser('artist','Freebase', 'has returned information for ' + vArtist[artistNumber] + ', likely sourced from Wikipedia.', 'status');
if (vfbURLAU[artistNumber] !== undefined) for (i = 0; i < vfbURLAU[artistNumber].length; i++) {
if (!isIn(vfbURLAU[artistNumber][i], 'artist')) {
if (!vfbURLAD[artistNumber][i]) {
updateUser('artist','Freebase', 'found a possible AR URL for ' + vArtist[artistNumber] + ":", 'left', vfbURLAU[artistNumber][i], 1);
} else {
updateUser('artist','Freebase', 'found a possible AR URL for ' + vArtist[artistNumber] + ":", 'left', vfbURLAU[artistNumber][i], vfbURLAD[artistNumber][i], 1);
}
}
}
}
if (fbATags[artistNumber] !== undefined) {
var fooString = "";
for (i = 0; i < fbATags[artistNumber].length; i++) {
if (i == (fbATags[artistNumber].length - 1)) fooString = fooString + fbATags[artistNumber][i];
else fooString = fooString + fbATags[artistNumber][i] + ", ";
}
if (fbATags[artistNumber].length == 1) updateUser('artist','Freebase', 'tag for ' + vArtist[artistNumber] + ": " + fooString, 'left', 1);
else if (fbATags[artistNumber].length > 0) {
updateUser('artist','Freebase', 'tags for ' + vArtist[artistNumber] + ": " + fooString, 'left', 1);
}
}
if (fbDateB[artistNumber] !== undefined) {
if (fbDateB[artistNumber].length > 0) {
if (rArtistType == "Person" || fbArtistType[artistNumber] == "Person") updateUser('artist','Freebase', "thinks the birth date for " + vArtist[artistNumber] + " is possibly " + fbDateB[artistNumber], 'left', 1);
else if (rArtistType == "Group" || fbArtistType[artistNumber] == "Group") updateUser('artist','Freebase', "thinks the start date for " + vArtist[artistNumber] + " is possibly " + fbDateB[artistNumber], 'left', 1);
else updateUser('artist','Freebase', "thinks the birth / start date for " + vArtist[artistNumber] + " is possibly " + fbDateB[artistNumber], 'left', 1);
}
}
if (fbDateD[artistNumber] !== undefined) {
if (fbDateD[artistNumber].length > 0) {
if (rArtistType == "Person" || fbArtistType[artistNumber] == "Person") updateUser('artist','Freebase', "thinks the death date for " + vArtist[artistNumber] + " is possibly " + fbDateD[artistNumber], 'left', 1);
else if (rArtistType == "Group" || fbArtistType[artistNumber] == "Group") updateUser('artist','Freebase', "thinks the end date for " + vArtist[artistNumber] + " is possibly " + fbDateD[artistNumber], 'left', 1);
else updateUser('artist','Freebase', "thinks the birth / end date for " + vArtist[artistNumber] + " is possibly " + fbDateD[artistNumber], 'left', 1);
}
}
if (fbArtistType[artistNumber] !== undefined) {
if (fbArtistType[artistNumber].length > 0) {
if (fbArtistType[artistNumber] != "notfound") {
if (rArtistType != "Person" && rArtistType != "Group" && fbArtistType[artistNumber] != "whoknows") updateUser('artist','Freebase', "thinks " + vArtist[artistNumber] + " is possibly a " + fbArtistType[artistNumber], 'left', 1);
}
}
}
}
function debugSwitch() {
if (GM_getValue('debug') === true) GM_setValue('debug', false);
else GM_setValue('debug', true);
location.href = location.href;
}
function updateUser(objectType, site, message, panel, urldest, premessage, addButton, imageURL, dimX, dimY, suppressLine, dataArrayLoc) {
switch (site) {
case 'Google':
case 'DiscogsFound':
var iconT = "http://www.google.com/favicon.ico";
break;
case 'MusicBrainz':
var iconT = 'http://musicbrainz.org/favicon.ico';
break;
case 'PureVolume':
var iconT = "http://www.purevolume.com/favicon.ico";
break;
case 'MySpace':
var iconT = "http://www.myspace.com/favicon.ico";
break;
case 'Wikipedia':
var iconT = "http://en.wikipedia.org/favicon.ico";
break;
case 'IMDb':
var iconT = "http://imdb.com/favicon.ico";
break;
case 'Jamendo':
var iconT = "http://www.jamendo.com/favicon.ico";
break;
case 'Ozon':
var iconT = "http://www.ozon.ru/favicon.ico";
site = "Ozon.ru";
break;
case 'Freebase':
var iconT = "http://freebase.com/favicon.ico";
break;
case 'BNN':
var iconT = "http://www.secretcoupons.com/images/v-3-logo.gif";
site = "Barnes & Noble";
break;
case 'Discogs':
var iconT = "http://www.discogs.com/images/favicon.ico";
break;
case 'Amazon':
var iconT = "http://amazon.co.uk/favicon.ico";
break;
case 'CDBaby':
var iconT = "http://cdbaby.com/favicon.ico";
site = "CD Baby";
break;
case 'MusicMoz':
default:
iconT = "";
}
if(panel =='other')
var fullM = document.createElement('span');
else
var fullM = document.createElement('div');
fullM.style.padding = "3px";
fullM.style.width = "90%";
if (iconT.length > 0) {
var imgM = document.createElement('img');
imgM.src = iconT;
fullM.appendChild(imgM);
fullM.appendChild(document.createTextNode(" "));
}
if (site) {
var textmessageM = document.createElement('text');
if (site == "DiscogsFound")
textmessageM.innerHTML = "Google ";
else
textmessageM.innerHTML = site + " ";
textmessageM.style.fontWeight = "bold";
fullM.appendChild(textmessageM);
}
if (message) {
var textmessageM = document.createElement('text');
textmessageM.innerHTML = message + " ";
textmessageM.style.fontWeight = "bold";
fullM.appendChild(textmessageM);
if (site == "IMDb") {
var imdbM = document.createElement('text');
imdbM.style.fontWeight = "bold";
fullM.appendChild(imdbM);
imdbName(urldest, imdbM);
}
}
if (urldest) {
fullM.appendChild(document.createElement('br'));
var urlM = document.createElement('a');
urlM.name = urldest;
urlM.style.fontSize = ".8em";
urlM.innerHTML = insertChar(urldest, '<br>', 52);
fullM.appendChild(urlM);
urlM.style.cursor = 'pointer';
urlM.addEventListener("click", openIframe, true);
}
if (premessage) {
if (premessage.length > 0) {
fullM.appendChild(document.createElement('br'));
var fieldM = document.createElement('blockquote');
fieldM.style.width = "94%";
fieldM.style.marginLeft = "2em";
fieldM.style.padding = "3px";
fieldM.style.paddingBottom = "0";
fieldM.style.backgroundColor = "#FFF0F5";
fieldM.style.border = "solid thin";
fieldM.style.whiteSpace = "-moz-pre-wrap !important";
fieldM.innerHTML = '“… ' + premessage + ' …”';
fullM.appendChild(fieldM);
}
}
if (imageURL) {
var coverM = new Image();
coverM.src = imageURL;
coverM.style.padding = "3px";
coverM.style.border = "medium none";
coverM.style.display = "block";
coverM.style.margin = "0 auto";
var imagemessageM = document.createElement('p');
imagemessageM.innerHTML = "( " + dimX + " x " + dimY + " )";
imagemessageM.style.display = "block";
imagemessageM.align = "center";
imagemessageM.style.fontSize = ".9em";
imagemessageM.style.margin = "0 auto";
fullM.appendChild(document.createElement('br'));
fullM.appendChild(document.createElement('br'));
coverM.style.width = "60%";
fullM.appendChild(coverM);
fullM.appendChild(imagemessageM);
fullM.appendChild(document.createElement('br'));
}
if (addButton == 1) {
var w = document.createElement("div");
w.align = "center";
w.style.paddingBottom = ".1em";
var x = makeButton("Correct", "small");
var y = makeButton("Not correct", "small");
if (site == "Freebase" || site == "DiscogsFound") var z = makeButton("?", "small");
else var z = makeButton(site, "small");
w.appendChild(x);
w.appendChild(y);
w.appendChild(z);
fullM.appendChild(w);
x.addEventListener('click', function() { alert("Not implemented yet"); }, false);
y.addEventListener("click", goAway, false);
z.addEventListener("click", function() {
if(popupActive === false)
popupPrompt('Add URL Relationship for '+objectType,'addURL',objectType);
}, true);
}
if(dataArrayLoc != null) {
fullM.appendChild(document.createElement('br'));
var zw = document.createElement("div");
zw.align = "center";
zw.style.paddingBottom = ".1em";
var x = makeButton("Inspect", "small");
zw.appendChild(x);
fullM.appendChild(zw);
x.addEventListener('click', function() {
popupActive = true;
setInfo(dataArrayLoc);
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
}, false);
}
if (!suppressLine) {
var lineM = document.createElement('hr');
lineM.style.width = "50%";
lineM.style.backgroundColor = "slategrey";
lineM.style.height = "1px";
lineM.align = "center";
fullM.appendChild(lineM);
}
switch (panel) {
case 'left':
$("dataLeft").appendChild(fullM);
break;
case 'center':
$("dataCenter").appendChild(fullM);
break;
case 'right':
$("dataRight").appendChild(fullM);
break;
case 'other':
return fullM;
case 'status':
default:
lineM.style.width = "95%";
lineM.align = "left";
lineM.style.marginTop = ".3em";
lineM.style.paddingTop = "0";
fullM.style.fontSize = ".8em";
$("dataStatus").appendChild(fullM);
}
dataRight.style.width = "33% !important";
dataCenter.style.width = "33% !important";
dataLeft.style.width = "33% !important";
targetPoint.parentNode.style.width = "100% !important";
}
function goAway() {
if(popupActive === false)
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
}
function getMBRelease() {
startLink.style.visibility = "hidden";
if (debug === true) debugMessage('http://musicbrainz.org/ws/1/release/' + rMBID + '=?type=xml&inc=url-rels+counts+tracks+release-events+labels+release-rels+artist');
GM_xmlhttpRequest({
method: 'GET',
url: 'http://musicbrainz.org/ws/1/release/' + rMBID + '=?type=xml&inc=url-rels+counts+tracks+release-events+labels+release-rels+artist',
onload: function(responseDetails) {
var parserA = new DOMParser();
var maDiv = parserA.parseFromString(responseDetails.responseText, "application/xml");
zz = maDiv.getElementsByTagName('release');
if (!zz[0]) {} else {
if (!zz[0].getAttribute('type')) {} else MBrType = zz[0].getAttribute('type').split(' ');
}
zz = maDiv.getElementsByTagName('text-representation');
if (!zz[0]) {} else {
MBrLanguage = zz[0].getAttribute('language');
MBrScript = zz[0].getAttribute('script');
}
if (maDiv.getElementsByTagName('asin')) MBrASIN = maDiv.getElementsByTagName('asin').textContent;
// Add event info above labels here
zz = maDiv.getElementsByTagName('label');
MBrLabel = [];
mlMBID = [];
if (!zz[0]) {} else {
for (xx = 0; xx < zz.length; xx++) {
MBrLabel[xx] = zz[xx].getElementsByTagName('name')[0].textContent;
mlMBID[xx] = zz[xx].getAttribute('id');
}
rLabel = MBrLabel[0];
}
zz = maDiv.getElementsByTagName("artist");
vArtist = [];
vMBID = [];
vArtistType = [];
if (maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("name").length == 0) {
if (debug === true) debugMessage(maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("name").length + " Release type is SA");
rArtist = zz[0].getElementsByTagName("name")[0].textContent;
vMBID[0] = zz[0].getAttribute('id');
vArtistType[0] = zz[0].getAttribute('type');
VARelease = false;
vArtist[0] = rArtist;
} else {
if (debug === true) debugMessage(maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("name").length + " Release type is VA");
for (s = 0; s < maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("name").length; s++) {
vArtist[s] = maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("name")[s].textContent;
vMBID[s] = maDiv.getElementsByTagName("track-list")[0].getElementsByTagName("artist")[s].getAttribute('id');
}
rArtist = vArtist[0];
VARelease = true;
}
zz = maDiv.getElementsByTagName("title");
rRelease = zz[0].textContent;
if (rRelease.match(/The.*?/)) if (rRelease != "The The" && rRelease.length > 8) rRelease = rRelease.split(/The.*?/)[1];
zz = maDiv.getElementsByTagName("relation");
MBURLs = [];
for (vvv = 0, www = 0; vvv < zz.length; vvv++) {
if (zz[vvv].getAttribute('target').slice(0, 7) == "http://") {
MBURLs[www] = zz[vvv].getAttribute('target');
www++;
if(zz[vvv].getAttribute('target').match("discogs") != null) formDiscogs(zz[vvv].getAttribute('target'), 0, true);
}
}
StartSearching();
}
});
}
function googleIt(cb, gDomain, gQuery, gHighlight, vaNumber) {
if(!vaNumber) vaNumber = 0;
gURL = "";
gDescription = "";
if (debug === true) debugMessage('http://www.google.com/search?q=site%3A' + gDomain + '+' + gQuery, 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.google.com/search?q=site%3A' + gDomain + '+' + gQuery,
onload: function(responseDetails) {
StatusIUp();
var oDiv = document.createElement('div');
oDiv.innerHTML = responseDetails.responseText;
a = oDiv.getElementsByTagName("div")[6];
if (!a) {} else {
if (!a.getElementsByTagName("a")[0]) {
if (debug === true) debugMessage("No results found for " + gQuery);
else {}
} else {
a.innerHTML = a.innerHTML.replace(/<table cellspacing=\"0\" cellpadding=\"1\".*?table>/, "").replace(/<table style=\"margin-top: 1em;\" border=\"0\".*?table>/, "").replace(/<nobr.*?nobr>/, "");
// First replace strips the alternate word forms
// Second replace strips "in English only"
// Third replace strips "Translate this page"
gURL = a.getElementsByTagName("a")[0].getAttribute("href");
gDescription = a.getElementsByTagName("font")[0].innerHTML.split("<span")[0].replace(/<\/?br?>/g, "").replace(" ...", "").replace(gHighlight, "<b>" + gHighlight + "</b>");
}
oDiv = null;
cb(gURL, gDescription, vaNumber);
}
}
});
}
function getWikipediaA(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on Wikipedia.', 'status');
updateUser('artist','Wikipedia', 'possible URL:', 'left', gU, gD, 1);
}
}
function getWikipediaR(gU, gD, vaNumber) {
if (!isIn(gU, 'release')) {
updateUser('release','Google', 'has returned information on Wikipedia.', 'status');
updateUser('release','Wikipedia', 'possible URL:', 'center', gU, gD, 1);
}
}
function getWikipediaL(gU, gD, vaNumber) {
if (!isIn(gU, 'label')) {
updateUser('label','Google', 'has returned information on Wikipedia.', 'status');
updateUser('label','Wikipedia', 'possible URL:', 'right', gU, gD, 1);
}
}
function getJamendoArtist(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on Jamendo.', 'status');
updateUser('artist','Jamendo', 'possible URL:', 'left', gU, gD, 1);
}
}
function getPureVolume(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on PureVolume.', 'status');
updateUser('artist','PureVolume', 'possible URL:', 'left', gU, gD, 1);
}
}
function getMySpaceArtist(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on MySpace.', 'status');
updateUser('artist','MySpace', 'possible URL:', 'left', gU, gD, 1);
}
}
function getMySpaceLabel(gU, gD, vaNumber) {
if (!isIn(gU, 'label')) {
updateUser('label','Google', 'has returned information on MySpace.', 'status');
updateUser('label','MySpace', 'possible URL:', 'right', gU, gD, 1);
}
}
function getCDBaby(gU, gD, vaNumber) {
if (!isIn(gU, 'release')) {
updateUser('release','Google', 'has returned information on CD Baby.', 'status');
updateUser('release','CDBaby', 'possible URL:', 'center', gU, gD, 1);
}
}
function getIMDbRelease(gU, gD, vaNumber) {
if (!isIn(gU, 'release')) {
updateUser('release','Google', 'has returned information on IMDb.', 'status');
updateUser('release','IMDb', 'possible URL', 'center', gU, gD, 1);
}
}
function getIMDbArtist(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on IMDb.', 'status');
updateUser('artist','IMDb', 'possible URL', 'left', gU, gD, 1);
}
}
function getOzonImage(gU, dimX, dimY) {
if (!isIn(gU, 'release')) {
updateUser('release','Google', 'has returned information on Ozon.ru.', 'status');
updateUser('release','Ozon', 'possible coverart:', 'center', gU, "", 1, gU, dimX, dimY);
}
}
function startScript() {
document.cursor = "wait";
if (debug === true) var iTime = fullTime();
statusCell = document.createElement('td');
statusContainer1 = document.createElement('td');
statusContainer2 = document.createElement('div');
statusContainer2.innerHTML = '<b><u>Status</u></b><br>';
statusCell.id = "dataStatus";
statusOut = document.createElement('span');
statusIn = document.createElement('span');
statusContainer2.appendChild(document.createTextNode("Outgoing requests sent: "));
statusContainer2.appendChild(statusOut);
statusContainer2.appendChild(document.createElement('br'));
statusContainer2.appendChild(document.createTextNode("Requests received: "));
statusContainer2.appendChild(statusIn);
statusContainer2.appendChild(document.createElement('br'));
if (debug === true) {
debugCell = document.createElement('td');
debugCell.innerHTML = '<b><u>DEBUG</u></b><br>';
debugCell.id = "dataDebug";
debugCell.appendChild(document.createTextNode("Started at " + iTime));
debugCell.appendChild(document.createElement('br'));
}
dataLeft = document.createElement('td');
dataCenter = document.createElement('td');
dataRight = document.createElement('td');
dataLeft.innerHTML = '<b><u>Artist</u></b><br>';
dataCenter.innerHTML = '<b><u>Release</u></b><br>';
dataRight.innerHTML = '<b><u>Labels</u></b><br>';
dataLeft.id = "dataLeft";
dataCenter.id = "dataCenter";
dataRight.id = "dataRight";
getMBRelease();
}
function googleImage(cb, gDomain, gQuery, gSize, vaNumber) {
// Google sizes: small, medium, large, xlarge, xxlarge, huge
if (debug === true) debugMessage('http://images.google.com/images?gbv=2&hl=en&imgsz=' + gSize + '&q=site:%3A' + gDomain + '+' + gQuery);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://images.google.com/images?gbv=2&hl=en&imgsz=' + gSize + '&q=site:%3A' + gDomain + '+' + gQuery,
onload: function(responseDetails) {
StatusIUp();
var oDiv = document.createElement('div');
oDiv.innerHTML = responseDetails.responseText;
if (oDiv.innerHTML.match(/dyn.Img/)) {
var tmpA = oDiv.innerHTML.split('dyn.Img')[1].split(':","')[1].split('","');
oDiv = null;
// Need to change the following to cb(tmpA[0], tmpA[1], tmpA[2], vaNumber); to track who we just got info on
cb(tmpA[0], tmpA[1], tmpA[2])
} else cb("");
}
});
}
function imdbName(iURL, imdbM) {
if (debug === true) debugMessage(iURL);
GM_xmlhttpRequest({
method: 'GET',
url: iURL,
onload: function(responseDetails) {
imdbM.innerHTML = "for " + responseDetails.responseText.split('<meta name="title" content="')[1].split('">')[0] + ":";
}
});
}
function checkUpdate() {
if (debug === true) debugMessage("Checking for updated version");
GM_xmlhttpRequest({
method: 'GET',
url: 'http://userscripts.org/scripts/show/22970',
onload: function(responseDetails) {
if (responseDetails.responseText.split('<title>')[1].split('</title>')[0] != version) versionAlert.style.visibility = "visible";
}
});
}
function addTrackTitlesRow() {
allTracks = getElementsByClass("track");
var newTrackTitleRow = document.createElement('tr');
newTrackTitleRow.border = "1px solid #000000";
allTracks[0].parentNode.insertBefore(newTrackTitleRow, allTracks[0]);
if (!allTracks[0].getElementsByTagName("td")[3]) {} else {
var unusedTD0 = document.createElement('td');
unusedTD0.class = "no";
unusedTD0.innerHTML = " ";
newTrackTitleRow.appendChild(unusedTD0);
}
var unusedTD1 = document.createElement('td');
unusedTD1.class = "no";
unusedTD1.innerHTML = " ";
var unusedTD2 = document.createElement('td');
unusedTD2.class = "title";
unusedTD2.innerHTML = " ";
originalTimesTitle = document.createElement('td');
originalTimesTitle.class = "length";
originalTimesTitle.border = "1px solid #000000";
originalTimesTitle.id = "originalTimesTitle";
originalTimesTitle.innerHTML = " Original ";
newTrackTitleRow.appendChild(unusedTD1);
newTrackTitleRow.appendChild(unusedTD2);
newTrackTitleRow.appendChild(originalTimesTitle);
}
function addTrackHighlights() {
trackList = getElementsByClass("track");
for (i = 0; i < trackList.length; i++) {
trackList[i].addEventListener('mouseover',
function(event) {
this.style.backgroundColor = '#CDD6FF';
},
false);
trackList[i].addEventListener('mouseout',
function(event) {
this.style.backgroundColor = '#FFFFFF';
},
false);
}
}
function addTrackTimeEditCells() {
trackTable = getElementsByClass('releasetracks');
trackTitles = getElementsByClass("length", trackTable[0]);
for (i = 0; i < trackTitles.length; i++) {
newTrackEditor = makeEditor();
newTrackEditor.value = trackTitles[i].innerHTML.replace(/\ \;/g, '');
newTrackEditor.id = 'Time_Edit_' + i;
newTrackView = makeViewer();
newTrackView.innerHTML = trackTitles[i].innerHTML.replace(/\ \;/g, '');
newTrackView.id = 'Time_View_' + i;
trackTitles[i].innerHTML = "";
trackTitles[i].appendChild(newTrackEditor);
trackTitles[i].appendChild(newTrackView);
newTrackEditor.addEventListener("dblclick", switchTrackMode, true);
newTrackView.addEventListener("dblclick", switchTrackMode, true);
}
}
function addTrackTitleEditCells() {
trackTable = getElementsByClass('releasetracks');
trackTitles = getElementsByClass("title", trackTable[0]);
trackTitles = trackTitles.concat(getElementsByClass("title va", trackTable[0]));
for (i = 0; i < trackTitles.length; i++) {
newTrackEditor = makeEditor();
newTrackEditor.value = trackTitles[i].getElementsByTagName("span")[0].innerHTML;
newTrackEditor.id = 'Track_Edit_' + i;
newTrackView = makeViewer();
newTrackView.innerHTML = trackTitles[i].getElementsByTagName("span")[0].innerHTML;
newTrackView.id = 'Track_View_' + i;
trackTitles[i].innerHTML = "";
trackTitles[i].appendChild(newTrackEditor);
trackTitles[i].appendChild(newTrackView);
newTrackEditor.addEventListener("dblclick", switchTrackMode, true);
newTrackView.addEventListener("dblclick", switchTrackMode, true);
}
}
function addReleaseTitleEditCell() {
trackTable = getElementsByClass('releasebegin');
trackTable = trackTable[0].getElementsByTagName('tr');
trackTable[0].removeChild(trackTable[0].getElementsByTagName("td")[0]);
newTrackEditor = makeEditor();
newTrackEditor.id = 'Title_Edit_ReleaseTitle';
newTrackEditor.style.fontWeight = "700";
newTrackEditor.style.border = '1px thin black';
newTrackEditor.addEventListener("dblclick", switchTrackMode, true);
newTrackEditor.style.width = "95%";
newTrackEditor.value = rRelease;
newReleaseTitle = makeViewer();
newReleaseTitle.style.fontWeight = "700";
// Never ever uncomment the next line!
// newReleaseTitle.style.border = '1px thin black';
newReleaseTitle.id = 'Title_View_ReleaseTitle';
newReleaseTitle.addEventListener("dblclick", switchTrackMode, true);
newReleaseTitle.innerHTML = rRelease;
newReleaseTitle.style.padding = "1px";
newReleaseTitle.style.margin = "1px 1px 1px 1em";
newReleaseTitle.style.fontWeight = "700";
newReleaseTitle.style.fontSize = "1.1em";
newReleaseTitle.style.height = "1.15em";
trackTable[0].style.backgroundColor = "#CDD6FF";
trackTable[0].removeChild(trackTable[0].getElementsByTagName("td")[0]);
newReleaseTitleCell = document.createElement('td');
newReleaseTitleCell.appendChild(newTrackEditor);
newReleaseTitleCell.appendChild(newReleaseTitle);
trackTable[0].appendChild(newReleaseTitleCell);
}
function makeEditor() {
var newTrackEditor = document.createElement('textarea');
newTrackEditor.style.border = "1px none '#FFDCAD";
newTrackEditor.style.padding = "0";
newTrackEditor.style.backgroundColor = "#ECECEC";
newTrackEditor.style.height = "100%";
newTrackEditor.style.width = "100%";
newTrackEditor.style.margin = "1px";
newTrackEditor.style.overflow = 'none';
newTrackEditor.style.overflowY = 'none';
newTrackEditor.style.overflowX = 'none';
newTrackEditor.style.display = "none";
return newTrackEditor;
}
function makeViewer() {
var newTrackView = document.createElement('div');
newTrackView.style.border = "0 none white";
newTrackView.style.padding = "0";
newTrackView.style.margin = "1px";
newTrackView.style.overflow = 'none';
newTrackView.style.height = "100%";
newTrackView.style.width = "100%";
newTrackView.style.display = "inline";
return newTrackView;
}
function stripChangeLinkText() {
var d = document.getElementsByTagName("span");
for (i = 0; i < d.length; i++) {
if (d[i].innerHTML == "Change") {
var dd = d[i].parentNode;
dd.removeChild(d[i]);
dd.innerHTML = dd.innerHTML.split(0, (dd.innerHTML.length - 2))[0].replace(" ()", "");
}
}
}
function switchTrackMode() {
var xType = this.id.split('_')[1];
var editTrack = $(this.id.split('_')[0] + "_Edit_" + this.id.split('_')[2]);
var viewTrack = $(this.id.split('_')[0] + "_View_" + this.id.split('_')[2]);
if (xType == 'View') {
if (debug === true) debugMessage("Switching to edit mode for: " + this.id);
editTrack.style.display = "block";
viewTrack.style.display = "none";
editTrack.parentNode.style.backgroundColor = "#ECECEC";
} else if (xType == 'Edit') {
if (debug === true) debugMessage("Switching to view mode for: " + this.id);
if (editTrack.value != viewTrack.innerHTML) {
if (debug === true) debugMessage("Checking length.... Length is " + checkLength(editTrack.value) + " bytes. Current limit is " + tracktitlelengthlimit + " bytes");
if (checkLength(editTrack.value) > tracktitlelengthlimit) {
alert("New track title is too long: " + checkLength(editTrack.value) + " bytes, server byte-length limit is: " + tracktitlelengthlimit);
} else {
viewTrack.class = "";
viewTrack.parentNode.style.backgroundColor = '#FFDCAD';
viewTrack.style.backgroundColor = '#FFDCAD';
viewTrack.innerHTML = editTrack.value;
viewTrack.style.display = "inline";
editTrack.style.display = "none";
}
} else {
if (viewTrack.style.backgroundColor != '#FFDCAD') {
if (this.id.split('_')[2] != "ReleaseTitle") {
editTrack.parentNode.style.backgroundColor = "#FFFFFF";
} else {
editTrack.parentNode.style.backgroundColor = "#CDD6FF";
}
}
editTrack.style.display = "none";
viewTrack.style.display = "inline";
}
}
}
function makeTracklistMaster() {
// This copy will be used as the model for comparative views
TrackListCopyFrame = makeElement('div', '0','0', '95%', '95%', '', '', '', '', 'fixed', true);
TrackListCopyFrame.id = "NewReleaseWindow";
TrackListCopyFrame.style.display = "none";
var KeyFrame = makeElement('div', '2%','32%', '11%', '40%', '', '', '1px double', 'white', 'fixed', true);
KeyFrame.id = "KeyFrame";
var KeyFrameA = makeElement('span', '4%','45%', '2%', '3%', '', '', '1px solid', 'white', 'fixed', true);
var KeyFrameB = makeElement('span', '8%','45%', '2%', '3%', '', '', '1px solid', '#A3AA8C', 'fixed', true);
var KeyFrameC = makeElement('span', '4%','49%', '4%', '10%', '', '', 'none', 'white', 'fixed', false);
var KeyFrameD = makeElement('span', '8%','49%', '4%', '10%', '', '', 'none', 'white', 'fixed', false);
KeyFrameD.id = "NewReleaseSource";
KeyFrame.appendChild(KeyFrameA);
KeyFrame.appendChild(KeyFrameB);
KeyFrame.appendChild(KeyFrameC);
KeyFrame.appendChild(KeyFrameD);
KeyFrameC.style.fontWeight = "700";
KeyFrameD.style.fontWeight = "700";
KeyFrameC.appendChild(document.createTextNode("MusicBrainz"));
KeyFrameD.appendChild(document.createTextNode("Test Data"));
KeyFrame.style.zIndex = "99";
TrackListCopyFrame.appendChild(KeyFrame);
TrackListCopyInnerFrame = makeElement('div', '', '', '75%', '90%', '10%', '', '', '#736DAB', 'relative', true);
TrackListCopyInnerFrameScroll = makeElement('div', '', '', '100%', '100%', '', '', '', '', 'relative', true);
TrackListCopyFrame.style.zIndex = "99";
var trackList = getElementsByClass('releasebegin');
releaseCopyTitleLine = trackList[0].cloneNode(true);
trackList = getElementsByClass("track");
releaseCopyTracklist = trackList[0].parentNode.parentNode.cloneNode(true);
TrackListCopyInnerFrameScroll.style.overflowY = "auto";
TrackListCopyInnerFrameScroll.style.overflowX = "none";
var x = releaseCopyTracklist.getElementsByTagName("tr");
rReleaseTrackCount = x.length-1;
zz = x[0].getElementsByTagName("td").length;
var cloner = document.createElement("tr");
for(var i =0;i<zz;i++) {
var y = makeElement('td','','','','','','','','#A3AA8C','',false);
y.style.border = '1px thin #000';
cloner.appendChild(y);
if(i == 0) {
y.align = "center";
}
else if(i == zz-1) {
y.align = "right";
}
}
var z = x[0].parentNode;
y = cloner.getElementsByTagName("td")[0];
var a = "";
for(i =rReleaseTrackCount-1;i>-1;i--) {
y.innerHTML = i+1;
x[i].class = "";
a = cloner.cloneNode(true);
a.id = "NewTrack_"+i;
z.insertBefore(a,x[i+1])
}
cloner = null;
closeTargetSame = makeButton('Same Release', 'large');
closeTargetDifferent = makeButton('Different Releases', 'large');
closeTargetNotsure = makeButton('Not Sure', 'large');
TrackListCopyInnerFrame.appendChild(closeTargetSame);
TrackListCopyInnerFrame.appendChild(closeTargetDifferent);
TrackListCopyInnerFrame.appendChild(closeTargetNotsure);
TrackListCopyInnerFrame.appendChild(releaseCopyTitleLine);
TrackListCopyInnerFrameScroll.appendChild(releaseCopyTracklist);
TrackListCopyInnerFrame.appendChild(TrackListCopyInnerFrameScroll);
TrackListCopyFrame.appendChild(TrackListCopyInnerFrame);
closeTargetSame.addEventListener('click', function() {
processDiscogsReleaseVerified(currentVerified);
currentlyViewing = "";
document.getElementById("NewReleaseWindow").style.display = "none";
}, false);
closeTargetDifferent.addEventListener('click', function() {
popupActive = false;
currentlyViewing = "";
document.getElementById("NewReleaseWindow").style.display = "none";
}, false);
closeTargetNotsure.addEventListener("click", function() {
document.getElementById("KeyFrame").style.display = "none";
popupActive = false;
openIframe();
}, false);
document.body.appendChild(TrackListCopyFrame);
}
function checkLength(newTitle) {
if (encodeURI(newTitle).indexOf("%") != -1) {
var count = encodeURI(newTitle).split("%").length - 1;
if (count == 0) count++;
count = count + encodeURI(newTitle).length - (count * 3);
} else {
count = newTitle.length;
}
return count;
}
function formDiscogs(dURL, dNumber, dTrust) {
// dNumber: Which item of dType (which artist or label)
// For type == release, it's always 0.
var x = dURL.split("/");
if (x[3] == "release") dNumber = 0;
if (x[3] != "artist" && x[3] != "release" && x[3] != "label" && x[4] === undefined) {
if (debug === true) debugMessage("Bad Discogs request, skipping " + dURL);
} else getDiscogs(processDiscogs, x[3], x[4], dNumber, dTrust)
}
function getDiscogs(cb, dType, dQuery, dNumber, dTrust) {
// Discogs API forums: http://www.discogs.com/help/forums/board/1082
// Discogs API docs: http://www.discogs.com/help/api
// cb: callback
// dQuery: what to look up at Discogs
// dType: what type of request (artist, release, label)
// dNumber: Which item of dType (which artist or label)
// dTrust: boolean: true: url already existed in MB
// false: url came from Google or elsewhere
var requestURL = "http://www.discogs.com/" + dType + "/" + dQuery + "/";
var requestKey = "?f=xml&api_key=" + DiscogsKey;
if (debug === true) debugMessage("Requesting " + requestURL + requestKey);
if(dTrust == false) StatusOUp();
// We send trusted requests before the status indicators exist, this
// stores their count so they can be added in when the status indicator
// does exist. If it's false, it's coming from a request after the indicator
// already exists, so we can add it directly.
else preStatusOCount++;
GM_xmlhttpRequest({
method: 'GET',
url: requestURL + requestKey,
onload: function(responseDetails) {
if(dTrust == false) StatusIUp();
else preStatusICount++;
if (debug === true) debugMessage("Response received for " + requestURL);
var parser = new DOMParser();
var dom = parser.parseFromString(responseDetails.responseText, "application/xml");
cb(requestURL, dType, dom, dNumber, dTrust);
}
});
}
function processDiscogs(requestURL, dType, dom, dNumber, dTrust) {
if (debug === true) debugMessage('Starting processing of Discogs '+dType+' info');
switch (dType) {
case 'artist':
updateUser('artist','Discogs', 'has returned information on '+vArtist[dNumber], 'status');
processDiscogsArtist(requestURL, dom, dNumber, dTrust);
break;
case 'release':
if(dTrust == true)
updateUser('artist','Discogs', 'has returned information on a Discogs release listing', 'status');
else
updateUser('artist','Discogs', 'has returned information on a possible Discogs release listing', 'status');
processDiscogsRelease(requestURL, dom, dTrust);
break;
case 'label':
// Do nothing, we won't be requesting any labels
// as there's no useful info on them at Discogs.
default:
}
}
function processDiscogsArtist(requestURL, dom, dNumber, dTrust) {
// Process any artist urls
if (debug === true) debugMessage("Processing Discogs artist info for "+vArtist[dNumber]);
var x = dom.getElementsByTagName("urls")[0];
if (!x) {} else x = x.getElementsByTagName("url");
if (!x) {} else for (var i = 0; i < x.length; x++) {
if (!isIn(x[i], 'artist')) {
updateUser('artist', 'DiscogsFound', 'found a possible AR URL for ' + vArtist[dNumber] + ":", 'left', x[i], 1);
}
}
}
function processDiscogsRelease(requestURL, dom, dTrust) {
var x = dom.getElementsByTagName("tracklist")[0];
if (!x) {
if (debug === true) debugMessage('Processing Discogs release info, received data not valid');
} else {
if (debug === true) debugMessage('Processing Discogs release info, valid data received');
// We got useable info from Discogs
var zed = storedRelease.length;
storedRelease[zed] = [];
var currentReleaseDataStorage = storedRelease[zed];
// Put the release data from Discogs into storage
currentReleaseDataStorage['site'] = 'Discogs';
currentReleaseDataStorage['dom'] = dom;
currentReleaseDataStorage['source'] = requestURL;
currentReleaseDataStorage['info'] = [];
x = x.getElementsByTagName("track");
var DtrackCount = x.length;
for (var i = 0; i < DtrackCount; i++) {
currentReleaseDataStorage['info'][i] = [];
currentReleaseDataStorage['info'][i][0] = x[i].getElementsByTagName("title")[0].textContent;
currentReleaseDataStorage['info'][i][1] = x[i].getElementsByTagName("duration")[0].textContent;
}
if (debug === true) debugMessage('Discogs release: not trusted');
// Basic sanity check to see if track counts match
if (DtrackCount != rReleaseTrackCount) {
if (debug === true) debugMessage("Discogs release: " + DtrackCount + "tracks, release has " +rReleaseTrackCount + " tracks, ignoring release");
// flush the data, they don't match
currentReleaseDataStorage = null;
}
else {
// Was this a url we already knew about?
if (dTrust === true) {
if (debug === true) debugMessage('Discogs release: trusted');
processDiscogsReleaseVerified(zed);
} else {
currentReleaseDataStorage['confidence'] = 100;
updateUser('artist', 'DiscogsFound', 'found a possible matching release at Discogs', 'center', requestURL, '', '', '', '', '', '', zed);
}
}
}
}
function setInfo(dataArrayLoc) {
var z = "";
document.getElementById("NewReleaseSource").innerHTML = storedRelease[dataArrayLoc]['site'];
var trackTDs = document.getElementById('NewTrack_1').getElementsByTagName("td").length;
for (var i = 0; i < storedRelease[dataArrayLoc]['info'].length-1; i++) {
z = document.getElementById('NewTrack_'+i);
zTitle = z.getElementsByTagName("td")[1];
zTime = z.getElementsByTagName("td")[trackTDs-1];
zTitle.innerHTML = storedRelease[dataArrayLoc]['info'][i][0];
zTime.innerHTML = storedRelease[dataArrayLoc]['info'][i][1];
}
currentlyViewing = storedRelease[dataArrayLoc]['source'];
currentVerified = dataArrayLoc;
document.getElementById("NewReleaseWindow").style.display = "inline";
}
function processDiscogsReleaseVerified(i) {
addTrackTimesColumn(i);
}
function addTrackTimesColumn(dataArrayLoc) {
trackTimes = getElementsByClass("length",getElementsByClass("releasetracks")[0]);
var newTrackTitle = document.createElement('td');
newTrackTitle.id = "ReleaseArray_" + dataArrayLoc + "_Title";
newTrackTitle.style.border = "1px solid #000000";
// Avoid horizontal bars in time fields
if (storedRelease[dataArrayLoc]['site'].length < 11) {
var k = storedRelease[dataArrayLoc]['site'];
var i = k.length;
while (i < 11) {
k = " " + k + " ";
i += 2;
}
newTrackTitle.innerHTML = k;
} else {
newTrackTitle.innerHTML = storedRelease[dataArrayLoc]['site'];
}
var x = document.getElementById("originalTimesTitle");
x.parentNode.insertBefore(newTrackTitle, x);
for (i = 0; i < trackTimes.length; i++) {
trackTimes[i].style.border = "1px solid #000000";
var newTrackTime = document.createElement('td');
newTrackTime.id = "ReleaseArray_"+ dataArrayLoc + "_Time_" + "_" + i;
newTrackTime.appendChild(document.createTextNode(storedRelease[dataArrayLoc]['info'][i][1]));
newTrackTime.align = "right";
newTrackTime.style.border = "1px solid #000000";
trackTimes[i].parentNode.insertBefore(newTrackTime, trackTimes[i]);
trackTimes[i].addEventListener('mouseover',
function(event) {
originalTimesTitle.style.backgroundColor = '#CDD6FF';
},
false);
trackTimes[i].addEventListener('mouseout',
function(event) {
originalTimesTitle.style.backgroundColor = '#FFFFFF';
},
false);
newTrackTime.addEventListener('mouseover',
function(event) {
newTrackTitle.style.backgroundColor = '#CDD6FF';
},
false);
newTrackTime.addEventListener('mouseout',
function(event) {
newTrackTitle.style.backgroundColor = '#FFFFFF';
},
false);
}
}
function getDiscogsA(gU, gD, vaNumber) {
if (!isIn(gU, 'artist')) {
updateUser('artist','Google', 'has returned information on Discogs.', 'status');
formDiscogs(gU, vaNumber, false)
}
}
function getDiscogsR(gU, gD, vaNumber) {
if (!isIn(gU, 'release')) {
updateUser('release','Google', 'has returned information on Discogs.', 'status');
formDiscogs(gU, 0, false)
}
}
function getDiscogsL(gU, gD, vaNumber) {
if (!isIn(gU, 'label')) {
updateUser('label','Google', 'has returned information on Discogs.', 'status');
formDiscogs(gU, vaNumber, false)
}
}
function getMBArtist(mbid, vanumber) {
// artist-rels+label-rels could be added in here later
if (debug === true) debugMessage('Getting ' + vanumber + ' http://musicbrainz.org/ws/1/artist/' + mbid + '?type=xml&inc=url-rels', 1);
StatusOUp();
GM_xmlhttpRequest({
method: 'GET',
url: 'http://musicbrainz.org/ws/1/artist/' + mbid + '?type=xml&inc=url-rels',
onload: function(responseDetails) {
StatusIUp();
var parserA = new DOMParser();
var maDiv = parserA.parseFromString(responseDetails.responseText, "application/xml");
mb = maDiv.getElementsByTagName('artist')[0];
vArtist[vanumber] = mb.getElementsByTagName('name')[0].textContent;
vMBID[vanumber] = mb.getAttribute('id');;
if (!mb.getElementsByTagName('name')[0]) vArtistType[vanumber] = 'unknown';
else vArtistType[vanumber] = mb.getAttribute('type');;
var vv = mb.getElementsByTagName('life-span')[0];
if (!vv) {
vArtistDatesB[vanumber] = "";
vArtistDatesD[vanumber] = "";
} else {
vArtistDatesB[vanumber] = vv.getAttribute('begin');
vArtistDatesD[vanumber] = vv.getAttribute('end');
if (vArtistDatesB[vanumber] === null) vArtistDatesB[vanumber] = "";
if (vArtistDatesD[vanumber] === null) vArtistDatesD[vanumber] = "";
}
vv = maDiv.getElementsByTagName("relation-list")[0];
if (!vv) {} else {
vv = vv.getElementsByTagName("relation");
if (!vv) {} else {
var artistURLs = [];
for (xxx = 0, www = 0; xxx < vv.length; xxx++) {
if (vv[xxx].getAttribute('target').slice(0, 7) == "http://") {
artistURLs[www] = vv[xxx].getAttribute('target');
if(artistURLs[www].match("discogs") != null) formDiscogs(artistURLs[www], vanumber, true);
www++;
}
}
MBURLs = MBURLs.concat(artistURLs);
}
}
StatusIUp();
updateUser('artist','MusicBrainz', 'has returned information on ' + vArtist[vanumber] + '.', 'status');
}
});
}
var artistLookup = function() {
if (debug === true) debugMessage('Sending MB artist lookup request for ' + vArtist[VACounter2]);
VACounter2++;
getMBArtist(vMBID[(VACounter2 - 1)], (VACounter2 - 1));
}
var RealSearch = function() {
switch (counter) {
case 0:
if (debug === true) debugMessage('Case 0');
if (VARelease === false) {
seenURLs = seenURLs.concat(MBURLs);
counter++;
googleIt(getWikipediaA, siteWikipedia, "\'" + rArtist + "\'", rArtist);
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
if (VACounter == 0) {
seenURLs = seenURLs.concat(MBURLs);
}
googleIt(getWikipediaA, siteWikipedia, "\'" + vArtist[VACounter] + "\'", vArtist[VACounter], VACounter);
googleIt(getDiscogsA, siteDiscogs, "\'" + vArtist[VACounter] + "\'", vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 1:
if (debug === true) debugMessage('Case 1');
if (VARelease === false) {
counter++;
googleIt(getWikipediaA, siteWikipedia, "inurl:" + rArtist.replace(" ", "_") + "%20Discography%20OR%20singer%20OR%20band", rArtist);
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getWikipediaA, siteWikipedia, "inurl:" + vArtist[VACounter].replace(" ", "_") + "%20Discography%20OR%20singer%20OR%20band", vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 2:
if (debug === true) debugMessage('Case 2');
if (VARelease === false) {
counter++;
googleIt(getWikipediaA, siteWikipedia, "inurl:" + rArtist.replace(" ", "_") + "_(band)", rArtist);
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getWikipediaA, siteWikipedia, "inurl:" + vArtist[VACounter].replace(" ", "_") + "_(band)", vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 3:
if (debug === true) debugMessage('Case 3');
if (VARelease === false) {
counter++;
googleIt(getWikipediaA, siteWikipedia, "allinanchor:" + rArtist.replace(" ", "_") + "%20band", rArtist);
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getWikipediaA, siteWikipedia, "allinanchor:" + vArtist[VACounter].replace(" ", "_") + "%20band", vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 4:
if (debug === true) debugMessage('Case 4');
counter++;
googleIt(getWikipediaR, siteWikipedia, "allinanchor:" + rRelease, rRelease);
break;
case 5:
if (debug === true) debugMessage('Case 5');
if (VARelease === false) {
counter++;
googleIt(getWikipediaR, siteWikipedia, "\'" + rRelease + "\'" + " \'" + rArtist + "\'", rArtist);
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getWikipediaR, siteWikipedia, "\'" + rRelease + "\'" + " \'" + vArtist[VACounter] + "\'", vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 6:
if (debug === true) debugMessage('Case 6');
counter++;
googleIt(getWikipediaR, siteWikipedia, "inurl:" + rRelease.replace(" ", "_"), rRelease);
break;
case 7:
if (debug === true) debugMessage('Case 7');
if (counter3 < MBrLabel.length) {
if (MBrLabel[counter2] == undefined) {
counter3++;
counter2 = 0;
} else {
switch (counter2) {
case 0:
googleIt(getWikipediaL, siteWikipedia, "\'" + MBrLabel[counter2] + "\'" + "%20label%20OR%20%20records%20OR%20%20music", MBrLabel[counter2], counter2);
counter2++;
break;
case 1:
googleIt(getWikipediaL, siteWikipedia, "allinanchor:" + MBrLabel[counter2], MBrLabel[counter2], counter2);
counter2++;
break;
case 2:
googleIt(getWikipediaL, siteWikipedia, "inurl:" + MBrLabel[counter2].replace(" ", "_"), MBrLabel[counter2], counter2);
if (counter3 == (MBrLabel.length - 1) && counter2 == 2) counter++;
counter2 = 0;
counter3++;
break;
default:
}
}
} else {
counter++;
}
break;
case 8:
if (debug === true) debugMessage('Case 8');
counter2 = 0;
counter3 = 0;
if (VARelease === false) {
googleIt(getJamendoArtist, siteJamendo, rArtist, rArtist);
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getJamendoArtist, siteJamendo, vArtist[VACounter], vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 9:
if (debug === true) debugMessage('Case 9');
if (VARelease === false) {
googleIt(getPureVolume, sitePureVolume, rArtist, rArtist);
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getPureVolume, sitePureVolume, vArtist[VACounter], vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 10:
if (debug === true) debugMessage('Case 10');
if (VARelease === false) {
googleIt(getMySpaceArtist, siteMySpace, rArtist, rArtist);
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getMySpaceArtist, siteMySpace, vArtist[VACounter], vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 11:
if (debug === true) debugMessage('Case 11');
if (counter2 < MBrLabel.length) {
if (MBrLabel[counter2] == undefined) {
counter2++;
} else {
googleIt(getMySpaceLabel, siteMySpace, MBrLabel[counter2] + "%20label%20OR%20%20records%20OR%20%20music", MBrLabel[counter2], counter2);
googleIt(getDiscogsL, siteDiscogs, MBrLabel[counter2], MBrLabel[counter2], counter2);
counter2++;
if (counter2 == (MBrLabel.length - 1)) counter++;
}
} else {
counter++;
}
break;
case 12:
if (debug === true) debugMessage('Case 12');
counter2 = 0;
googleIt(getCDBaby, siteCDBaby, rRelease, rRelease);
googleIt(getDiscogsR, siteDiscogs, "\'" + rRelease + "\'", rRelease);
counter++;
break;
case 13:
if (debug === true) debugMessage('Case 13');
var typeCheck = new RegExp("Soundtrack");
if (typeCheck.test(MBrType)) googleIt(getIMDbRelease, siteIMDb, rRelease, rRelease);
else StatusODown();
counter++;
break;
case 14:
if (debug === true) debugMessage('Case 14');
if (VARelease === false) {
googleIt(getIMDbArtist, siteIMDb, rArtist, rArtist);
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleIt(getIMDbArtist, siteIMDb, vArtist[VACounter], vArtist[VACounter], VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 15:
if (debug === true) debugMessage('Case 15');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "huge");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "huge", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 16:
if (debug === true) debugMessage('Case 16');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "xxlarge");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "xxlarge", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 17:
if (debug === true) debugMessage('Case 17');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "xlarge");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "xlarge", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 18:
if (debug === true) debugMessage('Case 18');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "large");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "large", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 19:
if (debug === true) debugMessage('Case 19');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "medium");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "medium", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 20:
if (debug === true) debugMessage('Case 20');
if (VARelease === false) {
googleImage(getOzonImage, siteOzon, rRelease + "%20" + rArtist, "small");
counter++;
} else if (VARelease === true) {
if (VACounter != 0) {
// This won't catch all of them, but it's still much less time and bandwidth-wasting
while (vArtist[VACounter] == vArtist[(VACounter - 1) && VACounter < (vArtist.length - 1)]) VACounter++;
}
googleImage(getOzonImage, siteOzon, rRelease + "%20" + vArtist[VACounter], "small", VACounter);
VACounter++;
if (VACounter == (vArtist.length - 1)) {
VACounter = 0;
counter++;
}
}
break;
case 21:
if (debug === true) debugMessage('Case 21');
counter++;
getFreebase();
break;
default:
}
}
function StartSearching() {
loadAnnotation();
stripSite();
drawSite();
flipAnnotation();
makeTracklistMaster()
addTrackHighlights();
addTrackTitlesRow();
addReleaseTitleEditCell();
addTrackTimeEditCells();
addTrackTitleEditCells();
stripChangeLinkText();
if (debug === false) checkUpdate();
if (firsttime) firstTimeUse();
document.cursor = "default";
StatusOUp();
StatusIUp();
// Get artist info
VACounter2 = 0;
for (k = 0; k < vArtist.length; k++) {
if (debug === true) debugMessage('Queing MB artist lookup request for ' + vArtist[k]);
window.setTimeout(artistLookup, timeDelay);
timeDelay = timeDelay + delayTime;
}
if (debug === true) debugMessage('Finished looking up artist(s)');
// Give MB time to return results, and concat to do its thing
timeDelay = timeDelay + ((delayTime * vArtist.length) / 2);
// Avoid swamping the browser on VA releases
if (VARelease === true) {
delayTime = delayTime * vaDelay;
updateUser('release','MusicBrainz', 'has returned information on the release.', 'status');
runCount = (engineCount * vArtist.length);
} else {
runCount = engineCount;
updateUser('release','MusicBrainz', 'has returned information on the release.', 'status');
}
for(i=0;i<preStatusOCount;i++) { StatusOUp(); }
for(i=0;i<preStatusICount;i++) { StatusIUp(); }
for (mb = 0; mb < ((MBrLabel.length * 4) + runCount); mb++) {
window.setTimeout(RealSearch, timeDelay);
timeDelay = timeDelay + delayTime;
}
function loadAnnotation() {
var annotationNode = getElementsByClass("annotation");
if (annotationNode[0]) {
annotationNode = annotationNode[0].getElementsByTagName("td");
annotationString = annotationNode[0].innerHTML;
// cover case of once-existing, no longer existing annotation
if (annotationString.slice(0, 28) == "Annotation last modified by ") annotationString = "";
} else annotationString = "";
}
function firstTimeUse(urldest) {
openTarget.src = 'http://wiki.musicbrainz.org/BrianFreud/Uberscript';
openTarget.style.display = "inline";
closeTarget.style.display = "inline";
var x = getElementsByClass('asin');
GM_setValue('firsttime', false);
if (x[0]) x[0].style.visibility = "collapse";
}
}
debugAnnotationHTML = false;
debugAnnotationMarkup = false;
version = "Geordie - Beta 9 – Userscripts.org";
engineCount = 25;
delayTime = 2000; // Do not set lower than 1000
counter = 0;
vaDelay = 1.3;
// To do:
// Fix last \n issue in annotations
// Tie okay button in popup prompts back to indicator button
// Fix status issues with Discogs
// update/add in Amazon engine
// add in MusicMoz engine
// write AR processing engine
// OL issue
// fix Bnn engine and add in
// add in label processing for MB data
// add dates check
// Freebase returns dates as yyyy-mm-dd
// MB returns dates as yyyy-mm-dd
