MusicBrainz: Add flags before country names in release events

By stars Last update Sep 11, 2011 — Installed 661 times.

There are 3 previous versions of this script.

// ==UserScript==
// @name		MusicBrainz: Add flags before country names
// @description		A script which adds the flag of the country before the country names.
// @version		2011-09-11
// @author		-
// @namespace		df069240-fe79-11dc-95ff-0800200c9a66
//
// @include		http://*musicbrainz.org/label/*
// @include		http://*musicbrainz.org/release/*
// @include		http://*musicbrainz.org/release-group/*
// @include		http://*musicbrainz.org/artist/*
// @include		http://*musicbrainz.org/recording/*
// @include		http://*musicbrainz.org/tracklist/*
// @include		http://*musicbrainz.org/collection/*

// ==/UserScript==
//**************************************************************************//

// Set to 'true' to use the current flag of Germany for East Germany
var eastgermany = false;

// Set to 'true' to use the EU flag for Europe
var europe = false;

// Set to 'true' to use the UN flag for [Worldwide]
var worldwide = false;

// Set to 'true' to replace the country code with the flag.
// When false, this will put the flag before the code.
var replaceccode = false;

// Set to 'true' to replace the country name with the flag.
// When false, this will put the flag before the name.
var replacecname = false;

//**************************************************************************//

var all = document.getElementsByTagName("abbr");
for (var i = all.length - 1; i >= 0; i--) {
//	var cc = all[i].text.toLowerCase().replace(/^\s*|\s*$/g,'');
	var cname = all[i].title;
	var cc = getcountry(cname);

	if (cc) {
		var img = document.createElement('img');
		var url = geturl(cc);
		img.setAttribute('src', url); // 'http://i.hbtronix.de/flags/' + cc + '.png');
		img.setAttribute('title', cname);
		img.style.borderRight = 'solid white 3px';
		if (replaceccode) {
			all[i].parentNode.replaceChild(img, all[i]);
		} else {
			all[i].parentNode.insertBefore(img, all[i]);
		}
	}
}

var all = document.getElementsByTagName("dt");
for (var i = 0; i < all.length; i++) {
	if (all[i].innerHTML == "Country:") {
		var nextSibling = all[i].nextSibling;
		while (nextSibling && nextSibling.nodeType != 1) {
			nextSibling = nextSibling.nextSibling;
		}
		var cname = nextSibling.innerHTML;
		var cc = getcountry(cname);
		if (cc) {
			var img = document.createElement('img');
			var url = geturl(cc);
			img.setAttribute('src', url); //'http://i.hbtronix.de/flags/' + cc + '.png');
			img.setAttribute('title', cname);
			var dd = document.createElement('dd');
			dd.appendChild(img);
			var tnode = document.createTextNode(" "+cname);
			if (!replacecname) {
				dd.appendChild(tnode);
			}
			all[i].parentNode.replaceChild(dd, nextSibling);
		}
	}

}

function getcountry(name) {
	var c = new Object();

	c['Afghanistan'] ='af';
	c['Åland Islands'] ='ax';
	c['Albania'] ='al';
	c['Algeria'] ='dz';
	c['American Samoa'] ='as';
	c['Andorra'] ='ad';
	c['Angola'] ='ao';
	c['Anguilla'] ='ai';
//	c['Antarctica'] = 'aq';
	c['Antigua and Barbuda'] ='ag';
	c['Argentina'] ='ar';
	c['Armenia'] ='am';
	c['Aruba'] ='aw';
	c['Australia'] ='au';
	c['Austria'] ='at';
	c['Azerbaijan'] ='az';
	c['Bahamas'] ='bs';
	c['Bahrain'] ='bh';
	c['Bangladesh'] ='bd';
	c['Barbados'] ='bb';
	c['Belarus'] ='by';
	c['Belgium'] ='be';
	c['Belize'] ='bz';
	c['Benin'] ='bj';
	c['Bermuda'] ='bm';
	c['Bhutan'] ='bt';
	c['Bolivia'] ='bo';
	c['Bosnia and Herzegovina'] ='ba';
	c['Botswana'] ='bw';
	c['Bouvet Island'] ='bv';
	c['Brazil'] ='br';
	c['British Indian Ocean Territory'] ='io';
	c['Brunei Darussalam'] ='bn';
	c['Bulgaria'] ='bg';
	c['Burkina Faso'] ='bf';
	c['Burundi'] ='bi';
	c['Cambodia'] ='kh';
	c['Cameroon'] ='cm';
	c['Canada'] ='ca';
	c['Cape Verde'] ='cv';
	c['Cayman Islands'] ='ky';
	c['Central African Republic'] ='cf';
	c['Chad'] ='td';
	c['Chile'] ='cl';
	c['China'] ='cn';
	c['Christmas Island'] ='cx';
	c['Cocos (Keeling) Islands'] ='cc';
	c['Colombia'] ='co';
	c['Comoros'] ='km';
	c['Congo'] ='cg';
	c['Congo, The Democratic Republic of the'] ='cd';
	c['Cook Islands'] ='ck';
	c['Costa Rica'] ='cr';
	c['Côte d\'Ivoire'] ='ci';
	c['Croatia'] ='hr';
	c['Cuba'] ='cu';
	c['Cyprus'] ='cy';
	c['Czech Republic'] ='cz';
	c['Denmark'] ='dk';
	c['Djibouti'] ='dj';
	c['Dominica'] ='dm';
	c['Dominican Republic'] ='do';
	c['Ecuador'] ='ec';
	c['Egypt'] ='eg';
	c['El Salvador'] ='sv';
	c['Equatorial Guinea'] ='gq';
	c['Eritrea'] ='er';
	c['Estonia'] ='ee';
	c['Ethiopia'] ='et';
	c['Falkland Islands (Malvinas)'] ='fk';
	c['Faroe Islands'] ='fo';
	c['Fiji'] ='fj';
	c['Finland'] ='fi';
	c['France'] ='fr';
	c['French Guiana'] ='gf';
	c['French Polynesia'] ='pf';
	c['French Southern Territories'] ='tf';
	c['Gabon'] ='ga';
	c['Gambia'] ='gm';
	c['Georgia'] ='ge';
	c['Germany'] ='de';
	c['Ghana'] ='gh';
	c['Gibraltar'] ='gi';
	c['Greece'] ='gr';
	c['Greenland'] ='gl';
	c['Grenada'] ='gd';
	c['Guadeloupe'] ='fr';
	c['Guam'] ='gu';
	c['Guatemala'] ='gt';
//	c['Guernsey'] ='gg';
	c['Guinea'] ='gn';
	c['Guinea-Bissau'] ='gw';
	c['Guyana'] ='gy';
	c['Haiti'] ='ht';
	c['Heard Island and McDonald Islands'] ='hm';
	c['Vatican City State (Holy See)'] ='va';
	c['Honduras'] ='hn';
	c['Hong Kong'] ='hk';
	c['Hungary'] ='hu';
	c['Iceland'] ='is';
	c['India'] ='in';
	c['Indonesia'] ='id';
	c['Iran, Islamic Republic of'] ='ir';
	c['Iraq'] ='iq';
	c['Ireland'] ='ie';
//	c['Isle of Man'] ='im';
	c['Israel'] ='il';
	c['Italy'] ='it';
	c['Jamaica'] ='jm';
	c['Japan'] ='jp';
//	c['Jersey'] ='je';
	c['Jordan'] ='jo';
	c['Kazakhstan'] ='kz';
	c['Kenya'] ='ke';
	c['Kiribati'] ='ki';
	c['Korea (North), Democratic People\'s Republic of'] ='kp';
	c['Korea (South), Republic of'] ='kr';
	c['Kuwait'] ='kw';
	c['Kyrgyzstan'] ='kg';
	c['Lao People\'s Democratic Republic'] ='la';
	c['Latvia'] ='lv';
	c['Lebanon'] ='lb';
	c['Lesotho'] ='ls';
	c['Liberia'] ='lr';
	c['Libyan Arab Jamahiriya'] ='ly';
	c['Liechtenstein'] ='li';
	c['Lithuania'] ='lt';
	c['Luxembourg'] ='lu';
	c['Macao'] ='mo';
	c['Macedonia, The Former Yugoslav Republic of'] ='mk';
	c['Madagascar'] ='mg';
	c['Malawi'] ='mw';
	c['Malaysia'] ='my';
	c['Maldives'] ='mv';
	c['Mali'] ='ml';
	c['Malta'] ='mt';
	c['Marshall Islands'] ='mh';
	c['Martinique'] ='fr';
	c['Mauritania'] ='mr';
	c['Mauritius'] ='mu';
	c['Mayotte'] ='yt';
	c['Mexico'] ='mx';
	c['Micronesia, Federated States of'] ='fm';
	c['Moldova'] ='md';
	c['Monaco'] ='mc';
	c['Mongolia'] ='mn';
	c['Montenegro'] ='me';
	c['Montserrat'] ='ms';
	c['Morocco'] ='ma';
	c['Mozambique'] ='mz';
	c['Myanmar'] ='mm';
	c['Namibia'] ='na';
	c['Nauru'] ='nr';
	c['Nepal'] ='np';
	c['Netherlands'] ='nl';
	c['Netherlands Antilles'] ='an';
	c['New Caledonia'] ='nc';
	c['New Zealand'] ='nz';
	c['Nicaragua'] ='ni';
	c['Niger'] ='ne';
	c['Nigeria'] ='ng';
	c['Niue'] ='nu';
	c['Norfolk Island'] ='nf';
	c['Northern Mariana Islands'] ='mp';
	c['Norway'] ='no';
	c['Oman'] ='om';
	c['Pakistan'] ='pk';
	c['Palau'] ='pw';
	c['Palestinian Territory'] ='ps';
	c['Panama'] ='pa';
	c['Papua New Guinea'] ='pg';
	c['Paraguay'] ='py';
	c['Peru'] ='pe';
	c['Philippines'] ='ph';
	c['Pitcairn'] ='pn';
	c['Poland'] ='pl';
	c['Portugal'] ='pt';
	c['Puerto Rico'] ='pr';
	c['Qatar'] ='qa';
	c['Reunion'] ='re';
	c['Romania'] ='ro';
	c['Russian Federation'] ='ru';
	c['Rwanda'] ='rw';
	c['Saint Barthélemy'] ='fr';
	c['Saint Helena'] ='sh';
	c['Saint Kitts and Nevis'] ='kn';
	c['Saint Lucia'] ='lc';
	c['Saint Martin'] ='fr';
	c['Saint Pierre and Miquelon'] ='pm';
	c['Saint Vincent and The Grenadines'] ='vc';
	c['Samoa'] ='ws';
	c['San Marino'] ='sm';
	c['Sao Tome and Principe'] ='st';
	c['Saudi Arabia'] ='sa';
	c['Senegal'] ='sn';
	c['Serbia'] ='rs';
	c['Seychelles'] ='sc';
	c['Sierra Leone'] ='sl';
	c['Singapore'] ='sg';
	c['Slovakia'] ='sk';
	c['Slovenia'] ='si';
	c['Solomon Islands'] ='sb';
	c['Somalia'] ='so';
	c['South Africa'] ='za';
	c['South Georgia and the South Sandwich Islands'] ='gs';
	c['Spain'] ='es';
	c['Sri Lanka'] ='lk';
	c['Sudan'] ='sd';
	c['Suriname'] ='sr';
	c['Svalbard and Jan Mayen'] ='sj';
	c['Swaziland'] ='sz';
	c['Sweden'] ='se';
	c['Switzerland'] ='ch';
	c['Syrian Arab Republic'] ='sy';
	c['Taiwan'] ='tw';
	c['Tajikistan'] ='tj';
	c['Tanzania, United Republic of'] ='tz';
	c['Thailand'] ='th';
	c['Timor-Leste'] ='tl';
	c['Togo'] ='tg';
	c['Tokelau'] ='tk';
	c['Tonga'] ='to';
	c['Trinidad and Tobago'] ='tt';
	c['Tunisia'] ='tn';
	c['Turkey'] ='tr';
	c['Turkmenistan'] ='tm';
	c['Turks and Caicos Islands'] ='tc';
	c['Tuvalu'] ='tv';
	c['Uganda'] ='ug';
	c['Ukraine'] ='ua';
	c['United Arab Emirates'] ='ae';
	c['United Kingdom'] ='gb';
	c['United States'] ='us';
	c['United States Minor Outlying Islands'] ='um';
	c['Uruguay'] ='uy';
	c['Uzbekistan'] ='uz';
	c['Vanuatu'] ='vu';
	c['Venezuela'] ='ve';
	c['Viet Nam'] ='vn';
	c['Virgin Islands, British'] ='vg';
	c['Virgin Islands, U.S.'] ='vi';
	c['Wallis and Futuna'] ='wf';
	c['Western Sahara'] ='eh';
	c['Yemen'] ='ye';
	c['Zambia'] ='zm';
	c['Zimbabwe'] ='zw';

	c['Czechoslovakia (historical, 1918-1992)'] = 'cz';
	c['Serbia and Montenegro (historical, 2003-2006)'] = 'cs';
	c['Yugoslavia (historical, 1918-2003)'] = 'cs';

	if (eastgermany == true) {
		c['East Germany (historical, 1949-1990)'] = 'de';
	}
	if (europe == true) {
		c['Europe'] = 'europeanunion';
	}
	if (worldwide == true) {
		c['[Worldwide]'] = 'xw';
	}

	if (c[name]) {
		return c[name];
	} else {
		return false;
	}
}

function geturl(code) {
	if (code == "xw") {
		return "http://upload.wikimedia.org/wikipedia/commons/0/01/Icons-flag-unitednations.png";
	} else {
		return 'http://i.hbtronix.de/flags/' + code + '.png';
	}
}