User:Magnus Manske/ext-props.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
	This script "moves" the properties with external IDs to the side bar.
	TECH NOTE: To generate the list of properties with "URL fomatter" property, run:
	select distinct page_title from page,pagelinks where page_id=pl_from and pl_namespace=120 and pl_from_namespace=120 and pl_title='P1630';
*/
jQuery(document).ready ( function() {
	if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
	if ( mw.config.get('wgAction') != 'view' ) return ;
 
	$('#p-tb').after("<div class='portal vector-menu-portal' id='ext_ids'><h3>External properties</h3><div class='body'><ul></ul></div><div><a style='font-size:12px' href='#'>Toggle main display</a></div></div>")
	$('#ext_ids a').click ( function () { $('div.extid_prop_toggle').toggle(); return false } )
	
	function addPropToSidebar ( p ) {
		if ( $('#P'+p).length == 0 ) return ; // No such property
		var prop_link = $('#P'+p+' div.wikibase-statementgroupview-property-label').html() ;
		$('#P'+p+' div.wikibase-statementview-mainsnak div.wikibase-snakview-value').each ( function () {
			var o = $(this) ;
			$('#ext_ids ul').append ( "<li style='margin-bottom:3px'>" + prop_link + ":<br/>" + o.html() + "</li>" ) ;
		}) ;
		$('#P'+p).addClass('extid_prop_toggle').hide() ;
	}
	
	var props = [1015,1005,949,1207,212,213,214,220,227,231,233,234,235,236,243,244,245,247,267,268,269,270,271,345,347,349,350,351,352,353,354,356,359,373,374,377,380,381,396,402,409,424,428,434,435,436,454,455,458,464,476,477,480,481,486,492,493,494,496,497,502,508,535,536,539,549,557,563,586,587,590,592,593,594,597,599,600,604,605,625,627,628,630,633,637,638,640,646,648,650,651,652,653,661,662,665,668,671,673,675,677,683,685,686,687,691,698,699,701,709,715,716,717,718,721,723,724,727,731,732,733,745,757,758,759,761,763,764,781,791,804,809,815,818,819,821,824,827,829,830,838,839,842,843,845,846,850,860,861,863,864,865,866,867,882,884,886,888,889,892,893,894,902,905,906,907,918,920,932,933,935,938,939,946,947,950,951,959,960,961,962,966,982,998,1003,1004,1006,1007,1014,1025,1036,1042,1043,1044,1045,1047,1051,1053,1054,1055,1058,1059,1070,1076,1084,1085,1133,1138,1143,1144,1146,1153,1157,1182,1184,1185,1186,1187,1212,1214,1216,1217,1218,1219,1220,1222,1223,1224,1225,1226,1229,1232,1233,1234,1235,1237,1238,1239,1245,1248,1252,1254,1256,1258,1260,1263,1265,1266,1267,1273,1274,1280,1282,1284,1285,1286,1287,1288,1289,1291,1292,1296,1307,1311,1315,1320,1323,1330,1331,1338,1362,1367,1368,1375,1380,1381,1391,1394,1395,1396,1402,1407,1409,1415,1417,1422,1428,1430,1438,1439,1440,1447,1459,1461,1463,1466,1467,1469,1472,1473,1481,1483,1529,1550,1551,1556,1562,1563,1564,1565,1566,1573,1575,1580,1584,1585,1587,1599,1600,1602,1607,1612,1614,1615,1617,1624,1627,1631,1644,1648,1650,1651,1662,1667,1669,1670,1679,1695,1698,1699,1700,1702,1707,1710,1711,1712,1714,1717,1726,1727,1728,1732,1733,1735,1736,1738,1739,1741,1745,1746,1747,1748,1749,1751,1755,1760,1761,1763,1764,1769,1770,1771,1772,1788,1790,1794,1795,1802,1803,1804,1807,1808] ;
	$.each ( props , function ( dummy , p ) {
		addPropToSidebar(p) ;
	} ) ;
});