User:TheSpacebook/lifeline

From Wikipedia, the free encyclopedia
lifeline
DescriptionSubtle in-text geolocated suicide crisis telephone number.
StatusMostly stable
Version1.0
UpdatedApril 19, 2024
    (10 days ago)
Source
Beta
Lifeline script
Click here to test in HTML

A script and template to subtly embed a suicide crisis telephone number into a line of text. It assumes the number based on the geolocation of the IP and maps it to a number. The telephone numbers have been sourced from List of suicide crisis lines. The script also aims to mitigate WP:NOTDIRECTORY and WP:NODISCLAIMERS when discussions around this topic arise.

The intended usage is: {{lifeline|[prefix]|[suffix]|[default text]}}. With the parameter [country] to display the name of the country if needed, and [country.caps] if, for example, "the Netherlands" needs to be capitalized into "The Netherlands".

Example usage[edit]

If used in the Suicide methods article[edit]

These include support, access to treatment, and calling a crisis hotline{{lifeline|, such as | in [country]|}}.

Would render in the US as: These include support, access to treatment, and calling a crisis hotline, such as 998 in the USA.

Would render in the UK as: These include support, access to treatment, and calling a crisis hotline, such as 0800 689 5652 in the UK.

Would render if not found as: These include support, access to treatment, and calling a crisis hotline.

Questions may arise if a VPN is detected, on whether it should default or display the country data of that VPN. To err on the side of caution, the VPN country data should just be displayed.

How it works[edit]

The script assumes the geolocation of the user by their IP address. It will return the ISO 3166-1 alpha-2 code, which is mapped to the suicide crisis telephone number of that country. It will output the telephone number.

Script[edit]

The last stable version of the script: version 1

The last stable version of the HTML tester: version 2.1

Version history
Version Description
Version 1 Fetches the country code using an external service.
Current unstable version (this one) Completed

Fetches the country using Geo.country.

"country" refers to the name of country, previously it referred to the country code, which has been replaced with "country_code".

Parameter for [country], to allow for expansion, making it more precise and subtle. For example {{lifeline|, such as | in [country]|}} renders as ", such as 998 in the USA"

Tasks:

Script Template
Confirm what format Geo.country outputs in. Parameter for 'default text' to display if there isn’t a number available/if the script fails.
Parameter to allow the number to be prefixed and suffixed, if one is found. Unique to each usage.
Add option for [country.caps] for if starting a sentence which will capitalise the "the" in: the UK, the USA, the Philippines, the Bahamas, the Netherlands, and the United Arab Emirates

Script[edit]

<script>
    async function displaylifeline() {
      const country_code = Geo.country; //Confirm the format this returns. Needs to be ISO-2-letter code.
      let lifeline;
      let country;
      switch (country_code) {

case 'DZ':
    lifeline = '0021 3983 2000 58';
    country = 'Algeria';
    break;

case 'AR':
    lifeline = '998';
    country = 'Argentina';
    break;

case 'AM':
    lifeline = '112';
    country = 'Armenia';
    break;

case 'AU':
    lifeline = '13 11 14';
    country = 'Australia';
    break;

case 'AT':
    lifeline = '112';
    country = 'Austria';
    break;

case 'AZ':
    lifeline = '112';
    country = 'Azerbaijan';
    break;

case 'BS':
    lifeline = '322–2763';
    country = 'the Bahamas';
    break;

case 'BH':
    lifeline = '999';
    country = 'Bahrain';
    break;

case 'BD':
    lifeline = '999';
    country = 'Bangladesh';
    break;

case 'BB':
    lifeline = '(246) 4299999';
    country = 'Barbados';
    break;

case 'BY':
    lifeline = '112';
    country = 'Belarus';
    break;

case 'BE':
    lifeline = 'NL: 1813 / FR: 080032123';
    country = 'Belgium';
    break;

case 'BA':
    lifeline = '0800-300303';
    country = 'Bosnia and Herzegovina';
    break;

case 'BO':
    lifeline = '911';
    country = 'Bolivia';
    break;

case 'BW':
    lifeline = '3911270';
    country = 'Botswana';
    break;

case 'BR':
    lifeline = '188';
    country = 'Brazil';
    break;

case 'BN':
    lifeline = '145';
    country = 'Brunei';
    break;

case 'BG':
    lifeline = '112';
    country = 'Bulgaria';
    break;

case 'CA':
    lifeline = '988';
    country = 'Canada';
    break;

case 'CL':
    lifeline = '*4141';
    country = 'Chile';
    break;

case 'CN':
    lifeline = '400 821 1215';
    country = 'China';
    break;

case 'CO':
    lifeline = '106';
    country = 'Colombia';
    break;

case 'CR':
    lifeline = '(506) 2272–3774';
    country = 'Costa Rica';
    break;

case 'HR':
    lifeline = '48 33 888';
    country = 'Croatia';
    break;

case 'CY':
    lifeline = '8000 7773';
    country = 'Cyprus';
    break;

case 'CZ':
    lifeline = '731 197 477';
    country = 'Czechia';
    break;

case 'DK':
    lifeline = '70 201 201';
    country = 'Denmark';
    break;

case 'EG':
    lifeline = '762 1602';
    country = 'Egypt';
    break;

case 'EE':
    lifeline = '116 006';
    country = 'Estonia';
    break;

case 'FJ':
    lifeline = '132454';
    country = 'Fiji';
    break;

case 'FI':
    lifeline = '09 2525 0111';
    country = 'Finland';
    break;

case 'FR':
    lifeline = '3114';
    country = 'France';
    break;

case 'DE':
    lifeline = '030-44 01 06 07';
    country = 'Germany';
    break;

case 'GE':
    lifeline = '112';
    country = 'Georgia';
    break;

case 'GH':
    lifeline = '2332 444 71279';
    country = 'Ghana';
    break;

case 'GI':
    lifeline = '116123';
    country = 'Gibraltar';
    break;

case 'GR':
    lifeline = '1018';
    country = 'Greece';
    break;

case 'GL':
    lifeline = '314';
    country = 'Greenland';
    break;

case 'GY':
    lifeline = '(+592) 223–0001';
    country = 'Guyana';
    break;

case 'HK':
    lifeline = '2896 0000';
    country = 'Hong Kong';
    break;

case 'HU':
    lifeline = '116–123';
    country = 'Hungary';
    break;

case 'IS':
    lifeline = '552 2218';
    country = 'Iceland';
    break;

case 'IN':
    lifeline = '+91 9999666555';
    country = 'India';
    break;

case 'ID':
    lifeline = '1500–567';
    country = 'Indonesia';
    break;

case 'IR':
    lifeline = '123';
    country = 'Iran';
    break;

case 'IE':
    lifeline = '116 123';
    country = 'Ireland';
    break;

case 'IL':
    lifeline = '1201';
    country = 'Israel';
    break;

case 'IT':
    lifeline = '800 86 00 22';
    country = 'Italy';
    break;

case 'JP':
    lifeline = '0800-300-8355';
    country = 'Japan';
    break;

case 'JO':
    lifeline = '911';
    country = 'Jordan';
    break;

case 'KR':
    lifeline = '1588–9191';
    country = 'Korea';
    break;

case 'KE':
    lifeline = '+254 722 178 177';
    country = 'Kenya';
    break;

case 'XK':
    lifeline = '080012345';
    country = 'Kosovo';
    break;

case 'LV':
    lifeline = '+371 27722292';
    country = 'Latvia';
    break;

case 'LB':
    lifeline = '1564';
    country = 'Lebanon';
    break;

case 'LR':
    lifeline = '6534308';
    country = 'Liberia';
    break;

case 'LT':
    lifeline = '116 123';
    country = 'Lithuania';
    break;

case 'LU':
    lifeline = '+352 45 45 45';
    country = 'Luxembourg';
    break;

case 'MY':
    lifeline = '15999';
    country = 'Malaysia';
    break;

case 'MT':
    lifeline = '179';
    country = 'Malta';
    break;

case 'MU':
    lifeline = '+230 800 93 93';
    country = 'Mauritius';
    break;

case 'MX':
    lifeline = '(55) 5259–8121';
    country = 'Mexico';
    break;

case 'MA':
    lifeline = '+212 (5) 22 87 47 40';
    country = 'Morocco';
    break;

case 'NP':
    lifeline = '1166';
    country = 'Nepal';
    break;

case 'NL':
    lifeline = '0800 0113';
    country = 'the Netherlands';
    break;

case 'NZ':
    lifeline = '09 5222 999';
    country = 'New Zealand';
    break;

case 'NO':
    lifeline = '116 123';
    country = 'Norway';
    break;

case 'PK':
    lifeline = '(92) 0311 7786264';
    country = 'Pakistan';
    break;

case 'PH':
    lifeline = '1553';
    country = 'the Philippines';
    break;

case 'PL':
    lifeline = '800 70 2222';
    country = 'Poland';
    break;

case 'PT':
    lifeline = '225 50 60 70';
    country = 'Portugal';
    break;

case 'PE':
    lifeline = '(01) 498-2711';
    country = 'Peru';
    break;

case 'RO':
    lifeline = '116 123';
    country = 'Romania';
    break;

case 'RU':
    lifeline = '8495051';
    country = 'Russia';
    break;

case 'RS':
    lifeline = '0800–300–303';
    country = 'Serbia';
    break;

case 'SG':
    lifeline = '6389 2222';
    country = 'Singapore';
    break;

case 'SK':
    lifeline = '112';
    country = 'Slovakia';
    break;

case 'SI':
    lifeline = '116 123';
    country = 'Slovenia';
    break;

case 'ZA':
    lifeline = '0800 567 567';
    country = 'South Africa';
    break;

case 'ES':
    lifeline = '024';
    country = 'Spain';
    break;

case 'LK':
    lifeline = '011 057 2222662';
    country = 'Sri Lanka';
    break;

case 'VC':
    lifeline = '(784) 456 1044';
    country = 'Saint Vincent and the Grenadines';
    break;

case 'SD':
    lifeline = '(249) 11–555–253';
    country = 'Sudan';
    break;

case 'SE':
    lifeline = '90101';
    country = 'Sweden';
    break;

case 'CH':
    lifeline = '143';
    country = 'Switzerland';
    break;

case 'TW':
    lifeline = '1925';
    country = 'Taiwan';
    break;

case 'TH':
    lifeline = '1323';
    country = 'Thailand';
    break;

case 'TO':
    lifeline = '23000';
    country = 'Tonga';
    break;

case 'TT':
    lifeline = '(868) 645 2800';
    country = 'Trinidad and Tobago';
    break;

case 'TR':
    lifeline = '183';
    country = 'Turkey';
    break;

case 'UA':
    lifeline = '7333';
    country = 'Ukraine';
    break;

case 'AE':
    lifeline = '920033360';
    country = 'the United Arab Emirates';
    break;

case 'GB':
    lifeline = '0800 689 5652';
    country = 'the UK';
    break;

case 'US':
    lifeline = '998';
    country = 'the USA';
    break;

case 'UY':
    lifeline = '08000767';
    country = 'Uruguay';
    break;

 default:

    lifeline = ' ';

}

      document.body.innerText = lifeline + country;

    }

    displaylifeline();
 </script>

Template[edit]

This template will insert the suicide crisis telephone number relevant to the users geolocation, subtly in-text.

Usage[edit]

Use this template in-text, instead of a disclaimer or a banner. The is also default text if no number is found. It should be formatted like this:

{{lifeline|[prefix]|[suffix]|[default text]}}

Optional parameters[edit]

  • [country] – returns the name of the country if also needed.
  • [country.caps] – returns the name of the country with the first letter is capitalized, for cases such as "the Netherlands".

Default behavior[edit]

These include support, access to treatment, and calling a crisis hotline {{lifeline|, such as | in [country]|}}.

Would render in the United States of America as: These include support, access to treatment, and calling a crisis hotline, such as 998 in the USA.

HTML page for testing[edit]

To test the script in a HTML webpage, copy-and-paste it into a text editor, save it with the extension ".html", and then open it in a web browser.

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title></title>
</head>
<body>
 <script>
    async function fetchCountry() {
      try {
        const response = await fetch('https://ipapi.co/country_code');
        const country_code = await response.text();
        return country_code.trim(); 
      } catch (error) {

        console.error('Error fetching country:', error);

        return null;

      }

    }

    async function displaylifeline() {
      const country_code = await fetchCountry();
      let lifeline;
      let country;
      switch (country_code) {

case 'DZ':
    lifeline = '0021 3983 2000 58';
    country = 'Algeria';
    break;

case 'AR':
    lifeline = '998';
    country = 'Argentina';
    break;

case 'AM':
    lifeline = '112';
    country = 'Armenia';
    break;

case 'AU':
    lifeline = '13 11 14';
    country = 'Australia';
    break;

case 'AT':
    lifeline = '112';
    country = 'Austria';
    break;

case 'AZ':
    lifeline = '112';
    country = 'Azerbaijan';
    break;

case 'BS':
    lifeline = '322–2763';
    country = 'the Bahamas';
    break;

case 'BH':
    lifeline = '999';
    country = 'Bahrain';
    break;

case 'BD':
    lifeline = '999';
    country = 'Bangladesh';
    break;

case 'BB':
    lifeline = '(246) 4299999';
    country = 'Barbados';
    break;

case 'BY':
    lifeline = '112';
    country = 'Belarus';
    break;

case 'BE':
    lifeline = 'NL: 1813 / FR: 080032123';
    country = 'Belgium';
    break;

case 'BA':
    lifeline = '0800-300303';
    country = 'Bosnia and Herzegovina';
    break;

case 'BO':
    lifeline = '911';
    country = 'Bolivia';
    break;

case 'BW':
    lifeline = '3911270';
    country = 'Botswana';
    break;

case 'BR':
    lifeline = '188';
    country = 'Brazil';
    break;

case 'BN':
    lifeline = '145';
    country = 'Brunei';
    break;

case 'BG':
    lifeline = '112';
    country = 'Bulgaria';
    break;

case 'CA':
    lifeline = '988';
    country = 'Canada';
    break;

case 'CL':
    lifeline = '*4141';
    country = 'Chile';
    break;

case 'CN':
    lifeline = '400 821 1215';
    country = 'China';
    break;

case 'CO':
    lifeline = '106';
    country = 'Colombia';
    break;

case 'CR':
    lifeline = '(506) 2272–3774';
    country = 'Costa Rica';
    break;

case 'HR':
    lifeline = '48 33 888';
    country = 'Croatia';
    break;

case 'CY':
    lifeline = '8000 7773';
    country = 'Cyprus';
    break;

case 'CZ':
    lifeline = '731 197 477';
    country = 'Czechia';
    break;

case 'DK':
    lifeline = '70 201 201';
    country = 'Denmark';
    break;

case 'EG':
    lifeline = '762 1602';
    country = 'Egypt';
    break;

case 'EE':
    lifeline = '116 006';
    country = 'Estonia';
    break;

case 'FJ':
    lifeline = '132454';
    country = 'Fiji';
    break;

case 'FI':
    lifeline = '09 2525 0111';
    country = 'Finland';
    break;

case 'FR':
    lifeline = '3114';
    country = 'France';
    break;

case 'DE':
    lifeline = '030-44 01 06 07';
    country = 'Germany';
    break;

case 'GE':
    lifeline = '112';
    country = 'Georgia';
    break;

case 'GH':
    lifeline = '2332 444 71279';
    country = 'Ghana';
    break;

case 'GI':
    lifeline = '116123';
    country = 'Gibraltar';
    break;

case 'GR':
    lifeline = '1018';
    country = 'Greece';
    break;

case 'GL':
    lifeline = '314';
    country = 'Greenland';
    break;

case 'GY':
    lifeline = '(+592) 223–0001';
    country = 'Guyana';
    break;

case 'HK':
    lifeline = '2896 0000';
    country = 'Hong Kong';
    break;

case 'HU':
    lifeline = '116–123';
    country = 'Hungary';
    break;

case 'IS':
    lifeline = '552 2218';
    country = 'Iceland';
    break;

case 'IN':
    lifeline = '+91 9999666555';
    country = 'India';
    break;

case 'ID':
    lifeline = '1500–567';
    country = 'Indonesia';
    break;

case 'IR':
    lifeline = '123';
    country = 'Iran';
    break;

case 'IE':
    lifeline = '116 123';
    country = 'Ireland';
    break;

case 'IL':
    lifeline = '1201';
    country = 'Israel';
    break;

case 'IT':
    lifeline = '800 86 00 22';
    country = 'Italy';
    break;

case 'JP':
    lifeline = '0800-300-8355';
    country = 'Japan';
    break;

case 'JO':
    lifeline = '911';
    country = 'Jordan';
    break;

case 'KR':
    lifeline = '1588–9191';
    country = 'Korea';
    break;

case 'KE':
    lifeline = '+254 722 178 177';
    country = 'Kenya';
    break;

case 'XK':
    lifeline = '080012345';
    country = 'Kosovo';
    break;

case 'LV':
    lifeline = '+371 27722292';
    country = 'Latvia';
    break;

case 'LB':
    lifeline = '1564';
    country = 'Lebanon';
    break;

case 'LR':
    lifeline = '6534308';
    country = 'Liberia';
    break;

case 'LT':
    lifeline = '116 123';
    country = 'Lithuania';
    break;

case 'LU':
    lifeline = '+352 45 45 45';
    country = 'Luxembourg';
    break;

case 'MY':
    lifeline = '15999';
    country = 'Malaysia';
    break;

case 'MT':
    lifeline = '179';
    country = 'Malta';
    break;

case 'MU':
    lifeline = '+230 800 93 93';
    country = 'Mauritius';
    break;

case 'MX':
    lifeline = '(55) 5259–8121';
    country = 'Mexico';
    break;

case 'MA':
    lifeline = '+212 (5) 22 87 47 40';
    country = 'Morocco';
    break;

case 'NP':
    lifeline = '1166';
    country = 'Nepal';
    break;

case 'NL':
    lifeline = '0800 0113';
    country = 'the Netherlands';
    break;

case 'NZ':
    lifeline = '09 5222 999';
    country = 'New Zealand';
    break;

case 'NO':
    lifeline = '116 123';
    country = 'Norway';
    break;

case 'PK':
    lifeline = '(92) 0311 7786264';
    country = 'Pakistan';
    break;

case 'PH':
    lifeline = '1553';
    country = 'the Philippines';
    break;

case 'PL':
    lifeline = '800 70 2222';
    country = 'Poland';
    break;

case 'PT':
    lifeline = '225 50 60 70';
    country = 'Portugal';
    break;

case 'PE':
    lifeline = '(01) 498-2711';
    country = 'Peru';
    break;

case 'RO':
    lifeline = '116 123';
    country = 'Romania';
    break;

case 'RU':
    lifeline = '8495051';
    country = 'Russia';
    break;

case 'RS':
    lifeline = '0800–300–303';
    country = 'Serbia';
    break;

case 'SG':
    lifeline = '6389 2222';
    country = 'Singapore';
    break;

case 'SK':
    lifeline = '112';
    country = 'Slovakia';
    break;

case 'SI':
    lifeline = '116 123';
    country = 'Slovenia';
    break;

case 'ZA':
    lifeline = '0800 567 567';
    country = 'South Africa';
    break;

case 'ES':
    lifeline = '024';
    country = 'Spain';
    break;

case 'LK':
    lifeline = '011 057 2222662';
    country = 'Sri Lanka';
    break;

case 'VC':
    lifeline = '(784) 456 1044';
    country = 'Saint Vincent and the Grenadines';
    break;

case 'SD':
    lifeline = '(249) 11–555–253';
    country = 'Sudan';
    break;

case 'SE':
    lifeline = '90101';
    country = 'Sweden';
    break;

case 'CH':
    lifeline = '143';
    country = 'Switzerland';
    break;

case 'TW':
    lifeline = '1925';
    country = 'Taiwan';
    break;

case 'TH':
    lifeline = '1323';
    country = 'Thailand';
    break;

case 'TO':
    lifeline = '23000';
    country = 'Tonga';
    break;

case 'TT':
    lifeline = '(868) 645 2800';
    country = 'Trinidad and Tobago';
    break;

case 'TR':
    lifeline = '183';
    country = 'Turkey';
    break;

case 'UA':
    lifeline = '7333';
    country = 'Ukraine';
    break;

case 'AE':
    lifeline = '920033360';
    country = 'the United Arab Emirates';
    break;

case 'GB':
    lifeline = '0800 689 5652';
    country = 'the UK';
    break;

case 'US':
    lifeline = '998';
    country = 'the USA';
    break;

case 'UY':
    lifeline = '08000767';
    country = 'Uruguay';
    break;

 default:

    lifeline = ' ';

}
      document.body.innerText = lifeline + ' / ' + country;

    }

    displaylifeline();
 </script>
</body>
</html>