Content deleted Content added
Ohconfucius (talk | contribs) m syntax error |
Ohconfucius (talk | contribs) No edit summary Tag: Reverted |
||
Line 1:
// <nowiki>
function ohc_flagcruft() {
const txt = document.editform.wpTextbox1;
// Utility: perform global regex replacement on textarea
function applyRegex(pattern, replacement) {
txt.value = txt.value.replace(pattern, replacement);
}
// Normalize flag/country templates
applyRegex(/\{\{(\s?country\s?|\sflag\s?)\|/gi, '{{Flag|');
//country templates that deliver a linked mini flag icon
applyRegex(/\{\{(Austria|Chile|China|Algeria|Iraq|Italy|Japan|New Zealand|Philippines|Tunisia)\}\}/g, '$1');
//from parameter within football templates
applyRegex(/(\|\s?(?:club|)nat\s?=\s?)[^|}]+(?=[\|}])/gi, '$1');
//strip bare icons
applyRegex(/\{\{\s*flag ?icon\s*(?:image|)\|(?:[^{}]+|)\}\}[ ]*/gi, '');
applyRegex(/\[\[(File|image):(Flag of |Bandera)[^|\]]+\.svg(?:\|[^\]]+)?\|\d{2,3}px(?:\|[^\]]+)?\]\][ ]?/gi, '');
applyRegex(/\[\[\s*Image:Med \d\.png\s*\|\d\d?\s*px\s*\]\][ ]*/gi, '');
//strip bare facilities icons
applyRegex(/\[\[(File|image):Feature (parking|suburban buses)\.svg(?:\|[^\]]+)?\|\d\d?px(?:\|[^\]]+)?\]\][ ]?/gi, '');
// Map of regex fragments to country names
//This format is consistent with your desired schema: [[<variants>], <canonical country name>],
const countryMap = new Map([
[['ABW', 'ARU', 'Aruba'], 'Aruba'],
[['AFG', 'Afghanistan'], 'Afghanistan'],
[['AGO', 'ANG', 'Angola'], 'Angola'],
[['AHO', 'Netherlands Antilles'], 'Netherlands Antilles'],
[['AIA', 'Anguilla'], 'Anguilla'],
[['ALA', 'Åland Islands'], 'Åland Islands'],
[['ALB', 'Albania'], 'Albania'],
[['AND', 'Andorra'], 'Andorra'],
[['ANT', 'Antigua and Barbuda'], 'Antigua and Barbuda'],
[['ARE', 'UAE', 'United Arab Emirates'], 'United Arab Emirates'],
[['ARG', 'Argentina'], 'Argentina'],
[['ARM', 'Armenia'], 'Armenia'],
[['ASM', 'SAM', 'ASA', 'American Samoa'], 'American Samoa'],
[['ATA', 'Antarctica'], 'Antarctica'],
[['ATF', 'French Southern Territories'], 'French Southern Territories'],
[['ATG', 'Antigua and Barbuda'], 'Antigua and Barbuda'],
[['AUS', 'Australia'], 'Australia'],
[['AUT', 'Austria'], 'Austria'],
[['AZE', 'Azerbaijan'], 'Azerbaijan'],
[['BDI', 'Burundi'], 'Burundi'],
[['BEL', 'Belgium'], 'Belgium'],
[['BEN', 'Benin'], 'Benin'],
[['BES', 'Bonaire, Sint Eustatius and Saba'], 'Bonaire, Sint Eustatius and Saba'],
[['BFA', 'BUR', 'Burkina Faso'], 'Burkina Faso'],
[['BGD', 'BAN', 'Bangladesh'], 'Bangladesh'],
[['BGR', 'BUL', 'Bulgaria'], 'Bulgaria'],
[['BHN', 'BHR', 'Bahrain'], 'Bahrain'],
[['BHS', 'BAH', 'Bahamas'], 'Bahamas'],
[['BIH', 'Bosnia and Herzegovina'], 'Bosnia and Herzegovina'],
[['BLM', 'Saint Barthélemy'], 'Saint Barthélemy'],
[['BLR', 'Belarus'], 'Belarus'],
[['BLZ', 'BIZ', 'Belize'], 'Belize'],
[['BMU', 'BER', 'Bermuda'], 'Bermuda'],
[['BOL', 'Bolivia'], 'Bolivia'],
[['BRA', 'Brazil'], 'Brazil'],
[['BRB', 'BAR', 'Barbados'], 'Barbados'],
[['BRN', 'BRU', 'Brunei'], 'Brunei'],
[['BTN', 'BHU', 'Bhutan'], 'Bhutan'],
[['BVT', 'Bouvet Island'], 'Bouvet Island'],
[['BWA', 'BOT', 'Botswana'], 'Botswana'],
[['BIR', 'Burma'], 'Burma'],
[['CAF', 'Central African Republic'], 'Central African Republic'],
[['CAN', 'Canada'], 'Canada'],
[['CCK', 'Cocos (Keeling) Islands'], 'Cocos (Keeling) Islands'],
[['CHE', 'SUI', 'SWI', 'Switzerland'], 'Switzerland'],
[['CHL', 'CHI', 'Chile'], 'Chile'],
[['CHN', 'PRC', "People's Republic of China", 'China'], 'China'],
[['CIV', "Côte d'Ivoire"], "Côte d'Ivoire"],
[['CMR', 'Cameroon'], 'Cameroon'],
[['COD', 'Democratic Republic of the Congo'], 'Democratic Republic of the Congo'],
[['COG', 'CGO', 'Republic of the Congo', 'Congo, Republic of the'], 'Republic of the Congo'],
[['COK', 'Cook Islands'], 'Cook Islands'],
[['COL', 'Colombia'], 'Colombia'],
[['COM', 'Comoros'], 'Comoros'],
[['CPV', 'Cape Verde'], 'Cape Verde'],
[['CRI', 'CRC', 'Costa Rica'], 'Costa Rica'],
[['CUB', 'Cuba'], 'Cuba'],
[['CUR', 'CUW', 'Curaçao'], 'Curaçao'],
[['CXR', 'Christmas Island'], 'Christmas Island'],
[['CYM', 'CAY', 'Cayman Islands'], 'Cayman Islands'],
[['CYP', 'Cyprus'], 'Cyprus'],
[['CSA', 'CSK', 'Czechoslovakia'], 'Czechoslovakia'],
[['CZE', 'Czech Republic'], 'Czech Republic'],
[['DDR', 'East Germany'], 'East Germany'],
[['DEU', 'GER', 'Nazi Germany', 'Germany'], 'Germany']
[['DJI', 'Djibouti'], 'Djibouti'],
[['DMA', 'Dominica'], 'Dominica'],
[['DNK', 'DEN', 'Denmark'], 'Denmark'],
[['DOM', 'Dominican Republic'], 'Dominican Republic'],
[['DZA', 'ALG', 'Algeria'], 'Algeria'],
[['ECU', 'Ecuador'], 'Ecuador'],
[['EGY', 'Egypt'], 'Egypt'],
[['ENG', 'England'], 'England'],
[['ERI', 'Eritrea'], 'Eritrea'],
[['ESH', 'Western Sahara'], 'Western Sahara'],
[['ESP', 'SPA', 'SPN', 'Spain'], 'Spain'],
[['EST', 'Estonia'], 'Estonia'],
[['ETH', 'Ethiopia'], 'Ethiopia'],
[['FIN', 'Finland'], 'Finland'],
[['FJI', 'FIJ', 'Fiji'], 'Fiji'],
[['FLK', 'Falkland Islands'], 'Falkland Islands'],
[['FRA', 'France'], 'France'],
[['FRG', 'West Germany'], 'West Germany'],
[['FRO', 'Faroe Islands'], 'Faroe Islands'],
[['FSM', 'Federated States of Micronesia', 'Micronesia'], 'Federated States of Micronesia'],
[['GAB', 'Gabon'], 'Gabon'],
[['GBR', 'GRB', 'UK', 'UKGBI', 'United Kingdom'], 'United Kingdom'],
[['GBR2', 'Great Britain'], 'Great Britain'],
[['GDR', 'East Germany'], 'East Germany'],
[['GEO', 'Georgia'], 'Georgia'],
[['GGY', 'Guernsey'], 'Guernsey'],
[['GHA', 'Ghana'], 'Ghana'],
[['GIB', 'Gibraltar'], 'Gibraltar'],
[['GIN', 'GUI', 'Guinea'], 'Guinea'],
[['GLP', 'Guadeloupe'], 'Guadeloupe'],
[['GMB', 'GAM', 'Gambia', 'The Gambia'], 'Gambia'],
[['GNB', 'GBS', 'Guinea-Bissau'], 'Guinea-Bissau'],
[['GNQ', 'GEQ', 'Equatorial Guinea'], 'Equatorial Guinea'],
[['GRC', 'GRE', 'Greece'], 'Greece'],
[['GRD', 'GRN', 'Grenada'], 'Grenada'],
[['GRL', 'Greenland'], 'Greenland'],
[['GTM', 'GUA', 'Guatemala'], 'Guatemala'],
[['GUF', 'French Guiana'], 'French Guiana'],
[['GUM', 'Guam'], 'Guam'],
[['GUY', 'Guyana'], 'Guyana'],
[['HKG', 'Hong Kong'], 'Hong Kong'],
[['HMD', 'Heard Island and McDonald Islands'], 'Heard Island and McDonald Islands'],
[['HND', 'HON', 'Honduras'], 'Honduras'],
[['HRV', 'CRO', 'Croatia'], 'Croatia'],
[['HTI', 'HAI', 'Haiti'], 'Haiti'],
[['HUN', 'Hungary'], 'Hungary'],
[['IDN', 'INA', 'Indonesia'], 'Indonesia'],
[['IMN', 'IOM', 'Isle of Man'], 'Isle of Man'],
[['IND', 'India'], 'India'],
[['IOT', 'British Indian Ocean Territory'], 'British Indian Ocean Territory'],
[['IRL', 'Ireland'], 'Ireland'],
[['IRN', 'IRI', 'Iran'], 'Iran'],
[['IRQ', 'Iraq'], 'Iraq'],
[['ISL', 'Iceland'], 'Iceland'],
[['ISR', 'Israel'], 'Israel'],
[['ITA', 'Italy'], 'Italy'],
[['JAM', 'Jamaica'], 'Jamaica'],
[['JEY', 'Jersey'], 'Jersey'],
[['JOR', 'Jordan'], 'Jordan'],
[['JPN', 'JAP', 'Japan'], 'Japan'],
[['KAZ', 'Kazakhstan'], 'Kazakhstan'],
[['KEN', 'Kenya'], 'Kenya'],
[['KGZ', 'Kyrgyzstan'], 'Kyrgyzstan'],
[['KHM', 'CAM', 'Cambodia'], 'Cambodia'],
[['KIR', 'Kiribati'], 'Kiribati'],
[['KNA', 'SKN', 'Saint Kitts and Nevis'], 'Saint Kitts and Nevis'],
[['KOR', 'ROK', 'South Korea', 'Republic of Korea', 'Korea'], 'Korea'],
[['KWT', 'KUW', 'Kuwait'], 'Kuwait'],
[['LAO', 'Laos'], 'Laos'],
[['LBN', 'LIB', 'Lebanon'], 'Lebanon'],
[['LBR', 'Liberia'], 'Liberia'],
[['LBY', 'LBA', 'Libya'], 'Libya'],
[['LCA', 'Saint Lucia'], 'Saint Lucia'],
[['LIE', 'Liechtenstein'], 'Liechtenstein'],
[['LKA', 'SRI', 'Sri Lanka'], 'Sri Lanka'],
[['LSO', 'LES', 'Lesotho'], 'Lesotho'],
[['LIT', 'LTU', 'Lithuania'], 'Lithuania'],
[['LUX', 'Luxembourg'], 'Luxembourg'],
[['LVA', 'LAT', 'Latvia'], 'Latvia'],
[['MAC', 'Macao'], 'Macao'],
[['MAF', 'Saint Martin'], 'Saint Martin'],
[['MAR', 'Morocco'], 'Morocco'],
[['MCO', 'MON', 'Monaco'], 'Monaco'],
[['MDA', 'MLD', 'Moldova'], 'Republic of Moldova'],
[['MDG', 'MAD', 'Madagascar'], 'Madagascar'],
]);
// Apply dynamic regex replacements using the map
for (const [aliases, country] of countryMap.entries()) {
const alt = aliases.map(x => x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
const pattern = new RegExp(`\\{\\{(?:[Ff]lag(?:country|u?)\\|[ ]*(${alt})|${alt})(?:\\|[^{}]+|)\\}\\}`, 'g');
applyRegex(pattern, country);
}
}
function ohc_flagcruft_2Bretired(){
var txt=document.editform.wpTextbox1;
Line 55 ⟶ 242:
regex(/\{\{(?:[Ff]lag(?:country|u?)\|[ ]*(CHL|CHI|Chile)|CHL|CHI)(?:\|[^{}]+|)\}\}/g, 'Chile');
regex(/\{\{(?:[Ff]lag(?:country|u?)\|[ ]*(CHN|PRC|(?:People\'s Republic of |)China)|CHN|PRC)(?:\|[^{}]+|)\}\}/g, 'China');
regex(/\{\{(?:[Ff]lag(?:country|u?)\|[ ]*(CIV|Côte d\'Ivoire)|CIV)(?:\|[^{}]+|)\}\}/g, 'Côte d\'Ivoire');
regex(/\{\{(?:[Ff]lag(?:country|u?)\|[ ]*(CMR|Cameroon)|CMR)(?:\|[^{}]+|)\}\}/g, 'Cameroon');
regex(/\{\{(?:[Ff]lag(?:country|u?)\|[ ]*(COD|Democratic Republic of the Congo)|COD)(?:\|[^{}]+|)\}\}/g, 'Democratic Republic of the Congo');
|