mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-14 12:22:26 +00:00
Code cleanup: replaced tabs by spaces.
This commit is contained in:
parent
0dc0770ba2
commit
8419ef2368
1 changed files with 65 additions and 65 deletions
|
@ -26,33 +26,33 @@ if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
// On Musicbrainz website
|
// On Musicbrainz website
|
||||||
if (window.location.href.match(/(musicbrainz\.org)/)) {
|
if (window.location.href.match(/(musicbrainz\.org)/)) {
|
||||||
|
|
||||||
$add_disc_dialog = $('div.add-disc-dialog');
|
$add_disc_dialog = $('div.add-disc-dialog');
|
||||||
//$add_disc_dialog.find('div.tabs ul.tabs').append('<li><a class="discogs" href="#discogs">Discogs import</a></li>');
|
//$add_disc_dialog.find('div.tabs ul.tabs').append('<li><a class="discogs" href="#discogs">Discogs import</a></li>');
|
||||||
|
|
||||||
var innerHTML = '<div class="add-disc-tab discogs" style="display: none">';
|
var innerHTML = '<div class="add-disc-tab discogs" style="display: none">';
|
||||||
innerHTML += '<p>Use the following fields to search for a Discogs release.</p>';
|
innerHTML += '<p>Use the following fields to search for a Discogs release.</p>';
|
||||||
innerHTML += '<div class="pager" style="width: 100%; text-align: right; display: none;"><a href="#prev"><<</a><span class="pager"></span><a href="#next">>></a></div>';
|
innerHTML += '<div class="pager" style="width: 100%; text-align: right; display: none;"><a href="#prev"><<</a><span class="pager"></span><a href="#next">>></a></div>';
|
||||||
innerHTML += '<div style="display: none;" class="tracklist-searching import-message"><p><img src="/static/images/icons/loading.gif" /> Searching...</p></div>';
|
innerHTML += '<div style="display: none;" class="tracklist-searching import-message"><p><img src="/static/images/icons/loading.gif" /> Searching...</p></div>';
|
||||||
innerHTML += '<div style="display: none;" class="tracklist-no-results import-message"><p>No results</p></div>';
|
innerHTML += '<div style="display: none;" class="tracklist-no-results import-message"><p>No results</p></div>';
|
||||||
innerHTML += '<div style="display: none;" class="tracklist-error import-message"><p>An error occured: <span class="message"> </span></p></div></div>';
|
innerHTML += '<div style="display: none;" class="tracklist-error import-message"><p>An error occured: <span class="message"> </span></p></div></div>';
|
||||||
//$add_disc_dialog.find('div.add-disc-tab:last').after(innerHTML);
|
//$add_disc_dialog.find('div.add-disc-tab:last').after(innerHTML);
|
||||||
|
|
||||||
// On Discogs website
|
// On Discogs website
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
magnifyLinks();
|
magnifyLinks();
|
||||||
|
|
||||||
// Release page?
|
// Release page?
|
||||||
if (window.location.href.match( /discogs\.com\/(.*\/?)release\/(\d+)$/) ) {
|
if (window.location.href.match( /discogs\.com\/(.*\/?)release\/(\d+)$/) ) {
|
||||||
|
|
||||||
// Discogs Webservice URL
|
// Discogs Webservice URL
|
||||||
var discogsReleaseId = window.location.href.match( /discogs\.com\/(.*\/?)release\/(\d+)$/)[2];
|
var discogsReleaseId = window.location.href.match( /discogs\.com\/(.*\/?)release\/(\d+)$/)[2];
|
||||||
var discogsWsUrl = 'http://api.discogs.com/releases/' + discogsReleaseId;
|
var discogsWsUrl = 'http://api.discogs.com/releases/' + discogsReleaseId;
|
||||||
|
|
||||||
mylog(discogsWsUrl);
|
mylog(discogsWsUrl);
|
||||||
|
|
||||||
// Swith JQuery to MB's one, and save GreaseMonkey one
|
// Swith JQuery to MB's one, and save GreaseMonkey one
|
||||||
var GM_JQuery = $;
|
var GM_JQuery = $;
|
||||||
|
@ -79,7 +79,7 @@ $(document).ready(function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function magnifyLinks() {
|
function magnifyLinks() {
|
||||||
|
@ -119,9 +119,9 @@ function parseDiscogsRelease(data) {
|
||||||
var discogsRelease = data.data;
|
var discogsRelease = data.data;
|
||||||
|
|
||||||
var release = new Object();
|
var release = new Object();
|
||||||
release.discs = [];
|
release.discs = [];
|
||||||
|
|
||||||
// Release artist credit
|
// Release artist credit
|
||||||
release.artist_credit = new Array();
|
release.artist_credit = new Array();
|
||||||
$.each(discogsRelease.artists, function(index, artist) {
|
$.each(discogsRelease.artists, function(index, artist) {
|
||||||
var ac = {
|
var ac = {
|
||||||
|
@ -132,8 +132,8 @@ function parseDiscogsRelease(data) {
|
||||||
release.artist_credit.push(ac);
|
release.artist_credit.push(ac);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Release title
|
// Release title
|
||||||
release.title = discogsRelease.title;
|
release.title = discogsRelease.title;
|
||||||
|
|
||||||
// Release date
|
// Release date
|
||||||
if (discogsRelease.released) {
|
if (discogsRelease.released) {
|
||||||
|
@ -201,19 +201,19 @@ function parseDiscogsRelease(data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspect tracks
|
// Inspect tracks
|
||||||
var tracks = [];
|
var tracks = [];
|
||||||
|
|
||||||
$.each(discogsRelease.tracklist, function(index, discogsTrack) {
|
$.each(discogsRelease.tracklist, function(index, discogsTrack) {
|
||||||
// TODO: dectect disc title and set disc.title
|
// TODO: dectect disc title and set disc.title
|
||||||
|
|
||||||
var track = new Object();
|
var track = new Object();
|
||||||
|
|
||||||
track.title = discogsTrack.title;
|
track.title = discogsTrack.title;
|
||||||
track.duration = discogsTrack.duration;
|
track.duration = discogsTrack.duration;
|
||||||
|
|
||||||
// Track artist credit
|
// Track artist credit
|
||||||
track.artist_credit = new Array();
|
track.artist_credit = new Array();
|
||||||
if (discogsTrack.artists) {
|
if (discogsTrack.artists) {
|
||||||
$.each(discogsTrack.artists, function(index, artist) {
|
$.each(discogsTrack.artists, function(index, artist) {
|
||||||
var ac = {
|
var ac = {
|
||||||
|
@ -225,24 +225,24 @@ function parseDiscogsRelease(data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track position and release number
|
// Track position and release number
|
||||||
var trackPosition = discogsTrack.position;
|
var trackPosition = discogsTrack.position;
|
||||||
var releaseNumber = 1;
|
var releaseNumber = 1;
|
||||||
|
|
||||||
// Skip special tracks
|
// Skip special tracks
|
||||||
if (trackPosition.toLowerCase().match("^(video|mp3)")) {
|
if (trackPosition.toLowerCase().match("^(video|mp3)")) {
|
||||||
trackPosition = "";
|
trackPosition = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove "CD" prefix
|
// Remove "CD" prefix
|
||||||
trackPosition = trackPosition.replace(/^CD/i, "");
|
trackPosition = trackPosition.replace(/^CD/i, "");
|
||||||
|
|
||||||
// Multi discs e.g. 1.1 or 1-1
|
// Multi discs e.g. 1.1 or 1-1
|
||||||
var tmp = trackPosition.match(/^(\d+)(?=(-|\.)\d*)/);
|
var tmp = trackPosition.match(/^(\d+)(?=(-|\.)\d*)/);
|
||||||
|
|
||||||
if (tmp && tmp[0]) {
|
if (tmp && tmp[0]) {
|
||||||
releaseNumber = tmp[0];
|
releaseNumber = tmp[0];
|
||||||
} else {
|
} else {
|
||||||
// Vinyls disc numbering: A1, B3, ...
|
// Vinyls disc numbering: A1, B3, ...
|
||||||
tmp = trackPosition.match(/^([A-Za-z])\d*/);
|
tmp = trackPosition.match(/^([A-Za-z])\d*/);
|
||||||
if (tmp && tmp[0] && tmp[0] != "V") {
|
if (tmp && tmp[0] && tmp[0] != "V") {
|
||||||
|
@ -258,46 +258,46 @@ function parseDiscogsRelease(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create release if needed
|
// Create release if needed
|
||||||
if ( !release.discs[releaseNumber-1] ) {
|
if ( !release.discs[releaseNumber-1] ) {
|
||||||
release.discs.push(new Object());
|
release.discs.push(new Object());
|
||||||
release.discs[releaseNumber-1].tracks = [];
|
release.discs[releaseNumber-1].tracks = [];
|
||||||
release.discs[releaseNumber-1].format = release_format;
|
release.discs[releaseNumber-1].format = release_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trackposition is empty e.g. for release title
|
// Trackposition is empty e.g. for release title
|
||||||
if (trackPosition != "" && trackPosition != null)
|
if (trackPosition != "" && trackPosition != null)
|
||||||
release.discs[releaseNumber-1].tracks.push(track);
|
release.discs[releaseNumber-1].tracks.push(track);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mylog(release);
|
mylog(release);
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert links in Discogs page
|
// Insert links in Discogs page
|
||||||
function insertLink(release) {
|
function insertLink(release) {
|
||||||
|
|
||||||
var mbUI = document.createElement('div');
|
var mbUI = document.createElement('div');
|
||||||
mbUI.innerHTML = "<h3>MusicBrainz</h3>";
|
mbUI.innerHTML = "<h3>MusicBrainz</h3>";
|
||||||
mbUI.className = "section";
|
mbUI.className = "section";
|
||||||
|
|
||||||
var mbContentBlock = document.createElement('div');
|
var mbContentBlock = document.createElement('div');
|
||||||
mbContentBlock.className = "section_content";
|
mbContentBlock.className = "section_content";
|
||||||
mbUI.appendChild(mbContentBlock);
|
mbUI.appendChild(mbContentBlock);
|
||||||
|
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var edit_note = 'Imported from ' + window.location.href.replace(/http:\/\/(www\.|)discogs\.com\/(.*\/|)release\//, 'http://www.discogs.com/release/');
|
var edit_note = 'Imported from ' + window.location.href.replace(/http:\/\/(www\.|)discogs\.com\/(.*\/|)release\//, 'http://www.discogs.com/release/');
|
||||||
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
||||||
// Append search link
|
// Append search link
|
||||||
innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
||||||
|
|
||||||
mbContentBlock.innerHTML = innerHTML;
|
mbContentBlock.innerHTML = innerHTML;
|
||||||
var prevNode = document.body.querySelector("div.section.ratings");
|
var prevNode = document.body.querySelector("div.section.ratings");
|
||||||
prevNode.parentNode.insertBefore(mbUI, prevNode);
|
prevNode.parentNode.insertBefore(mbUI, prevNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeDiscogsJoinphrase(join) {
|
function decodeDiscogsJoinphrase(join) {
|
||||||
|
|
Loading…
Reference in a new issue