[relationship_shortcuts] Remove Windows EOL from code.

This commit is contained in:
Aurélien Mino 2015-07-18 22:59:15 +02:00
parent 5ca16c0591
commit c1eec66549

View file

@ -1,162 +1,162 @@
// ==UserScript== // ==UserScript==
// @name Display shortcut for relationships on MusicBrainz // @name Display shortcut for relationships on MusicBrainz
// @description Display icon shortcut for relationships of release-group, release, recording and work: e.g. Amazon, Discogs, Wikipedia, ... links. This allows to access some relationships without opening the entity page. // @description Display icon shortcut for relationships of release-group, release, recording and work: e.g. Amazon, Discogs, Wikipedia, ... links. This allows to access some relationships without opening the entity page.
// @version 2013.01.30.1 // @version 2013.01.30.1
// @author Aurelien Mino <aurelien.mino@gmail.com> // @author Aurelien Mino <aurelien.mino@gmail.com>
// @licence GPL (http://www.gnu.org/copyleft/gpl.html) // @licence GPL (http://www.gnu.org/copyleft/gpl.html)
// @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/mb_relationship_shortcuts.user.js // @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/mb_relationship_shortcuts.user.js
// @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/mb_relationship_shortcuts.user.js // @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/mb_relationship_shortcuts.user.js
// @include http*://*musicbrainz.org/artist/* // @include http*://*musicbrainz.org/artist/*
// @include http*://*musicbrainz.org/release-group/* // @include http*://*musicbrainz.org/release-group/*
// @include http*://*musicbrainz.org/label/* // @include http*://*musicbrainz.org/label/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// ==/UserScript== // ==/UserScript==
// Definitions: relations-type and corresponding icons we are going to treat // Definitions: relations-type and corresponding icons we are going to treat
var relationsIconsURLs = { var relationsIconsURLs = {
'url': { 'url': {
"amazon asin": "http://amazon.fr/favicon.ico", "amazon asin": "http://amazon.fr/favicon.ico",
"discogs": "http://static.discogs.com/images/favicon.ico", "discogs": "http://static.discogs.com/images/favicon.ico",
"wikidata": "https://bits.wikimedia.org/favicon/wikidata.ico", "wikidata": "https://bits.wikimedia.org/favicon/wikidata.ico",
"imdb": "http://www.imdb.com/favicon.ico", "imdb": "http://www.imdb.com/favicon.ico",
"creative commons licensed download": "http://creativecommons.org/favicon.ico", "creative commons licensed download": "http://creativecommons.org/favicon.ico",
"cover art link": "http://cdcovers.to/favicon.ico", "cover art link": "http://cdcovers.to/favicon.ico",
"secondhandsongs": "http://secondhandsongs.com/art/favicon.png", "secondhandsongs": "http://secondhandsongs.com/art/favicon.png",
"lyrics": "http://www.nomy.nu/img/lyrics-icon.gif" "lyrics": "http://www.nomy.nu/img/lyrics-icon.gif"
}, },
'release-group': { 'release-group': {
"single from": "http://www.amaesingtools.com/images/left_arrow_icon.gif" "single from": "http://www.amaesingtools.com/images/left_arrow_icon.gif"
}, },
'release': { 'release': {
"part of set": "http://web.archive.org/web/20060709091901/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-inter.png", "part of set": "http://web.archive.org/web/20060709091901/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-inter.png",
"remaster": "http://web.archive.org/web/20060708200714/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-www.png", "remaster": "http://web.archive.org/web/20060708200714/http://wiki.musicbrainz.org/-/musicbrainz/img/moin-www.png",
} }
}; };
var incOptions = { var incOptions = {
'release-group': [ 'release-group-rels', 'url-rels' ], 'release-group': [ 'release-group-rels', 'url-rels' ],
'release': [ 'release-rels', 'url-rels', 'discids' ], 'release': [ 'release-rels', 'url-rels', 'discids' ],
'recording': [ 'work-rels' ], 'recording': [ 'work-rels' ],
'work': [ 'url-rels' ] 'work': [ 'url-rels' ]
}; };
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant // prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
this.$ = this.jQuery = jQuery.noConflict(true); this.$ = this.jQuery = jQuery.noConflict(true);
if (!unsafeWindow) unsafeWindow = window; if (!unsafeWindow) unsafeWindow = window;
$(document).ready(function(){ $(document).ready(function(){
// Get pageType (label or artist) // Get pageType (label or artist)
var parent = new Object(); var parent = new Object();
var child = new Object(); var child = new Object();
if (m = window.location.href.match("\/artist\/(.{36})[^\/]*$")) { if (m = window.location.href.match("\/artist\/(.{36})[^\/]*$")) {
parent.type = 'artist'; parent.type = 'artist';
parent.mbid = m[1]; parent.mbid = m[1];
child.type = 'release-group'; child.type = 'release-group';
} else if (m = window.location.href.match("\/(release-group|label)\/(.{36})$")) { } else if (m = window.location.href.match("\/(release-group|label)\/(.{36})$")) {
parent.type = m[1]; parent.type = m[1];
parent.mbid = m[2]; parent.mbid = m[2];
child.type = 'release'; child.type = 'release';
} else if (m = window.location.href.match("\/artist/(.{36})\/(releases|recordings|works)")) { } else if (m = window.location.href.match("\/artist/(.{36})\/(releases|recordings|works)")) {
parent.type = 'artist'; parent.type = 'artist';
parent.mbid = m[1]; parent.mbid = m[1];
child.type = m[2].replace(/s$/, ''); child.type = m[2].replace(/s$/, '');
} else { } else {
// Not supported // Not supported
return; return;
} }
var mbidRE = /(release|release-group|work)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/; var mbidRE = /(release|release-group|work)\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/;
// Determine target column // Determine target column
var columnindex = 0; var columnindex = 0;
$("table.tbl tbody tr[class!='subh']").each(function() { $("table.tbl tbody tr[class!='subh']").each(function() {
$(this).children("td").each(function() { $(this).children("td").each(function() {
if ($(this).find("a").attr("href") !== undefined && $(this).find("a").attr("href").match(mbidRE)) { return false }; if ($(this).find("a").attr("href") !== undefined && $(this).find("a").attr("href").match(mbidRE)) { return false };
columnindex++; columnindex++;
}); });
return false; return false;
}); });
// Set MBID to row in tables to get easiest fastest access // Set MBID to row in tables to get easiest fastest access
$("table.tbl tr[class!='subh']").each(function() { $("table.tbl tr[class!='subh']").each(function() {
var $tr = $(this); var $tr = $(this);
$tr.children("th:eq("+columnindex+")").after("<th style='width: 150px;'>Relationships</th>"); $tr.children("th:eq("+columnindex+")").after("<th style='width: 150px;'>Relationships</th>");
$tr.children("td:eq("+columnindex+")").after("<td class='relationships'></td>"); $tr.children("td:eq("+columnindex+")").after("<td class='relationships'></td>");
$(this).find("a").each(function() { $(this).find("a").each(function() {
var href = $(this).attr("href"); var href = $(this).attr("href");
if (m = href.match(mbidRE)) { if (m = href.match(mbidRE)) {
$tr.attr("id", m[2]); $tr.attr("id", m[2]);
return false; return false;
} }
}); });
}); });
// Call the MB webservice // Call the MB webservice
var url = '/ws/2/' + child.type + '?' + parent.type + "=" + parent.mbid + '&inc=' + incOptions[child.type].join("+") + '&limit=100'; var url = '/ws/2/' + child.type + '?' + parent.type + "=" + parent.mbid + '&inc=' + incOptions[child.type].join("+") + '&limit=100';
mylog('wsurl: ' + url); mylog('wsurl: ' + url);
$.get(url, function(data, textStatus, jqXHR) { $.get(url, function(data, textStatus, jqXHR) {
// Parse each child // Parse each child
$(data).find(child.type).each(function() { $(data).find(child.type).each(function() {
var mbid = $(this).attr("id"); var mbid = $(this).attr("id");
// URL relationships // URL relationships
$(this).find("relation-list[target-type='url'] relation").each(function() { $(this).find("relation-list[target-type='url'] relation").each(function() {
var reltype = $(this).attr("type"); var reltype = $(this).attr("type");
var target = $(this).children("target").text(); var target = $(this).children("target").text();
if (relationsIconsURLs['url'].hasOwnProperty(reltype)) { if (relationsIconsURLs['url'].hasOwnProperty(reltype)) {
$("#" + mbid + " td.relationships").append( $("#" + mbid + " td.relationships").append(
"<a href='" + target.replace(/'/g,"&apos;") + "'>" "<a href='" + target.replace(/'/g,"&apos;") + "'>"
+ "<img style='max-height: 15px;' src='" + relationsIconsURLs['url'][reltype] + "' />&nbsp;" + "<img style='max-height: 15px;' src='" + relationsIconsURLs['url'][reltype] + "' />&nbsp;"
+ "</a>" + "</a>"
); );
} }
}); });
// Other relationships // Other relationships
$(this).find("relation-list[target-type!='url']").each(function() { $(this).find("relation-list[target-type!='url']").each(function() {
var targettype = $(this).attr("target-type").replace("release_group", "release-group"); var targettype = $(this).attr("target-type").replace("release_group", "release-group");
var relations = {}; var relations = {};
$(this).children("relation").each(function() { $(this).children("relation").each(function() {
var reltype = $(this).attr("type"); var reltype = $(this).attr("type");
var target = $(this).children("target").text(); var target = $(this).children("target").text();
var url = (targettype == 'url') ? target : "/" + targettype + "/" + target; var url = (targettype == 'url') ? target : "/" + targettype + "/" + target;
if (relationsIconsURLs[targettype].hasOwnProperty(reltype)) { if (relationsIconsURLs[targettype].hasOwnProperty(reltype)) {
if (!relations.hasOwnProperty(reltype)) relations[reltype] = [url]; if (!relations.hasOwnProperty(reltype)) relations[reltype] = [url];
else relations[reltype].push(url); else relations[reltype].push(url);
} }
}); });
$.each(relations, function(reltype, urls) { $.each(relations, function(reltype, urls) {
var html = ""; var html = "";
if (urls.length < -1) { if (urls.length < -1) {
html += "<img src='" + relationsIconsURLs[targettype][reltype] + "' />(" + urls.length + ")&nbsp;" html += "<img src='" + relationsIconsURLs[targettype][reltype] + "' />(" + urls.length + ")&nbsp;"
} else { } else {
$.each(urls, function(index, url) { $.each(urls, function(index, url) {
html += "<a href='" + url + "'><img src='" + relationsIconsURLs[targettype][reltype] + "' /></a>&nbsp;"; html += "<a href='" + url + "'><img src='" + relationsIconsURLs[targettype][reltype] + "' /></a>&nbsp;";
}); });
} }
$("#" + mbid + " td.relationships").append(html); $("#" + mbid + " td.relationships").append(html);
}); });
}); });
}); });
}); });
}); });
function mylog(text) { function mylog(text) {
if (unsafeWindow.console) { if (unsafeWindow.console) {
unsafeWindow.console.log(text); unsafeWindow.console.log(text);
} }
} }