From 01b96cd4f1342e302a34af6d9675fbe22ddfec7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Wed, 28 Mar 2012 23:56:32 +0200 Subject: [PATCH] 2008-11-04 --- discogs_importer.user.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/discogs_importer.user.js b/discogs_importer.user.js index 993747a..c816cd0 100644 --- a/discogs_importer.user.js +++ b/discogs_importer.user.js @@ -7,7 +7,7 @@ // Script Update Checker // -- http://userscripts.org/scripts/show/20145 var version_scriptNum = 36376; // Change this to the number given to the script by userscripts.org (check the address bar) -var version_timestamp = 1225755854433; // Used to differentiate one version of the script from an older one. Use the Date.getTime() function to get a value for this. +var version_timestamp = 1225801014805; // Used to differentiate one version of the script from an older one. Use the Date.getTime() function to get a value for this. try { function updateCheck(forced) {if((forced)||(parseInt(GM_getValue("lastUpdate", "0")) + 86400000 <= (new Date().getTime()))) {try {GM_xmlhttpRequest({method: "GET",url: "http://userscripts.org/scripts/review/" + version_scriptNum + "?" + new Date().getTime(),headers: {'Cache-Control': 'no-cache'},onload: function(xhrResponse) {GM_setValue("lastUpdate", new Date().getTime() + ""); var rt = xhrResponse.responseText.replace(/ ?/gm, " ").replace(/
  • /gm, "\n").replace(/<[^>]*>/gm, ""); var scriptName = (/@name\s*(.*?)\s*$/m.exec(rt))[1]; GM_setValue("targetScriptName", scriptName); if (parseInt(/version_timestamp\s*=\s*([0-9]+)/.exec(rt)[1]) > version_timestamp) {if (confirm("There is an update available for the Greasemonkey script \"" + scriptName + ".\"\nWould you like to go to the install page now?")) {GM_openInTab("http://userscripts.org/scripts/show/" + version_scriptNum);}} else if (forced) {alert("No update is available for \"" + scriptName + ".\"");}}});} catch (err) {if (forced) {alert("An error occurred while checking for updates:\n" + err);}}}} GM_registerMenuCommand(GM_getValue("targetScriptName", "???") + " - Manual Update Check", function() {updateCheck(true);}); updateCheck(false); } catch(e) {} @@ -33,8 +33,14 @@ GM_xmlhttpRequest({ insertLinks(releases); } }); +/* +var xmlhttp = new XMLHttpRequest(); +xmlhttp.onreadystatechange = function() { var releases = parseReleases(xmlhttp.responseXML); insertLinks(releases);}; +xmlhttp.open("GET", url, true); +xmlhttp.send(null); +*/ -// Analyze Discogs data and cook the import URL +// Analyze Discogs data and cook the import URL function parseReleases(xmldoc) { var releases = []; @@ -73,7 +79,7 @@ function parseReleases(xmldoc) { // Track position and release number var trackPosition = trackNode.getElementsByTagName("position").item(0).textContent; var releaseNumber = 1; - var tmp = trackPosition.match(/^(\d)(?=-\d*)/); + var tmp = trackPosition.match(/^(\d)(?=(-|\.)\d*)/); if (tmp && tmp[0]) { releaseNumber = tmp[0]; } @@ -84,7 +90,9 @@ function parseReleases(xmldoc) { releases[releaseNumber-1].tracks = []; } - releases[releaseNumber-1].tracks.push(track); + // Trackposition is empty e.g. for release title + if (trackPosition != "" && trackPosition != null) + releases[releaseNumber-1].tracks.push(track); } // Fill releases info