mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-13 20:02:27 +00:00
Move hardcoded musicbrainz url to a MBLinks property
This commit is contained in:
parent
3e16227cd9
commit
14179dda3f
1 changed files with 4 additions and 3 deletions
|
@ -28,6 +28,7 @@ var MBLinks = function (cachekey, expiration) {
|
|||
this.cache = {};
|
||||
this.expirationMinutes = parseInt(expiration);
|
||||
this.cache_key = cachekey;
|
||||
this.mb_server = '//musicbrainz.org';
|
||||
|
||||
this.initAjaxEngine = function () {
|
||||
var ajax_requests = this.ajax_requests;
|
||||
|
@ -62,7 +63,7 @@ var MBLinks = function (cachekey, expiration) {
|
|||
|
||||
this.createMusicBrainzLink = function (mb_url, mb_type) {
|
||||
return '<a href="' + mb_url + '" title="Link to MB ' + mb_type +
|
||||
'"><img src="//musicbrainz.org/static/images/entity/' + mb_type + '.png" /></a> ';
|
||||
'"><img src="' + this.mb_server + '/static/images/entity/' + mb_type + '.png" /></a> ';
|
||||
};
|
||||
|
||||
// Search for ressource 'url' on MB, for relation of type 'mb_type' (artist, release, label, release-group)
|
||||
|
@ -84,7 +85,7 @@ var MBLinks = function (cachekey, expiration) {
|
|||
} else {
|
||||
mblinks.ajax_requests.push($.proxy(function () {
|
||||
var context = this;
|
||||
$.getJSON('//musicbrainz.org/ws/2/url?resource=' + encodeURIComponent(context.url)
|
||||
$.getJSON(mblinks.mb_server + '/ws/2/url?resource=' + encodeURIComponent(context.url)
|
||||
+ '&inc=' + context.mb_type + '-rels',
|
||||
function (data) {
|
||||
if ('relations' in data) {
|
||||
|
@ -96,7 +97,7 @@ var MBLinks = function (cachekey, expiration) {
|
|||
var _type = context.mb_type.replace('-', '_');
|
||||
$.each(data['relations'], function (idx, relation) {
|
||||
if (_type in relation) {
|
||||
var mb_url = '//musicbrainz.org/' + context.mb_type + '/' + relation[_type]['id'];
|
||||
var mb_url = mblinks.mb_server + '/' + context.mb_type + '/' + relation[_type]['id'];
|
||||
if ($.inArray(mb_url, mblinks.cache[context.url].urls) == -1) { // prevent dupes
|
||||
mblinks.cache[context.url].urls.push(mb_url);
|
||||
mblinks.saveCache();
|
||||
|
|
Loading…
Reference in a new issue