1. JavaScript / Говнокод #25671

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function htmlspecialchars (s) {
        const el = document.createElement('span');
        el.innerText = s;
        return el.innerHTML.replace(/<br>/g, "\n");
    }

    Почему в жепаскрипте нет прямого доступа к этой функции? Почему я должен для этого работать с DOM или сам писать эту поеботу на рагулярках? Почему асё так анально?

    O4epegHou_nemyx, 10 Июня 2019

    Комментарии (121)
  2. JavaScript / Говнокод #25653

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    <script>
            window["flags"] = {
            "purcTOFlag": "true" == "true" ? true : false,
            "ENBL_CANCEL_POLICY": "true" == "true" ? true : false,
            "ENBL_BACKUP_CHECK_OLD_DEVICES": "false" == "true" ? true : false,
            "ENBL_DIRECT_ACCESS_LINKS": "true" == "true" ? true : false,
            "ENBL_NEW_ABG_URL": "true" == "true" ? true : false,
            "cr_9839666": "true" == "true" ? true : false,
            "cubaCRFlag": "true" == "true" ? true : false,
            "cubaMultiCityCRFlag": "true" == "true" ? true : false,
            "youthCRFlag": "true" == "true" ? true : false,
            "ENABLE_AFOP_MODE": "true" == "true" ? true : false,
            "SHARE_ITINERARY_ON_FACEBOOK": "false" == "true" ? true : false,
            "cr_11668201": "true" == "true" ? true : false,
            "hotelCRFlag": "true" == "true" ? true : false,
            "cr_adoshareitinerary": "false" == "true" ? true : false,
            "ROUNDOFF_AMOUNT_FOR_US_EDITION": "true" == "true" ? true : false,
            "hideSeatPromotionalBanner": "true" == "true" ? true : false,
            "enablePremiumRougeCR": "true" == "true" ? true : false,
            "availFareSplit": "true" == "true" ? true : false,
            "improvedMixedCabin": "true" == "true" ? true : false,
            "adoPassengerPrepopulate": "true" == "true" ? true : false,
            "adoIataInformation": "true" == "true" ? true : false,
            "premiumRougeSeatSelection": "true" == "true" ? true : false,
            "displayIntlTerminal": "true" == "true" ? true : false,
            "continueDisabledLightboxIsEnabled": "true" == "true" ? true : false,
            "createAeroplanFromConf": "true" == "true" ? true : false,
            "contOnAvailPage": "true" == "true" ? true : false,
            "alpiSpecialAssistanceCRFlag": "true" == "true" ? true : false,
            "removePaxTitle": "false" == "true" ? true : false,
            "perDiemInsurance": "true" == "true" ? true : false,
            "isVisaCheckoutEnabled": "true" == "true" ? true : false,
            "isCashRewardEnabled": "true" == "true" ? true : false,
            "masterPassCRFlag": "true" == "true" ? true : false,
            "masterPassAllowedEdition": "CA\-en:CA\-fr:CA\-zh",
            "youthphase2CRFlag": "true" == "true" ? true : false,
            "isCitylistPerfEnabled": "true" == "true" ? true : false,
            "isSingleTravelOptionEnabled": "false" == "true" ? true : false,
            "retainPaymentInformation": "true" == "true" ? true : false,
            "hotelChildAgeCR": "true" == "true" ? true : false,
            "displayGeoFirst": "true" == "true" ? true : false,
            "displayDiscAvail": "true" == "true" ? true : false,
            "premiumRougeUpsell": "true" == "true" ? true : false,
            "enableReplaceOpinionLabs": "true" == "true" ? true : false,
            "displayOalRef": "true" == "true" ? true : false,
            "newTravelOptionsLayoutFlag": "true" == "true" ? true : false,
            "hotelWidgetAPI": "true" == "true" ? true : false,
            "enableCombinedPhoneNo": "true" == "true" ? true : false,
            "hideTripSummaryForMobile": "true" == "true" ? true : false,
            "enableSecureAttribute": "true" == "true" ? true : false,
            "enhancedPreviewSeatMap": "true" == "true" ? true : false,
            "enhancedSeatMap": "true" == "true" ? true : false,
            "firstClassCabinCR": "true" == "true" ? true : false,
             .
             .
    }

    Taken from aircanada.com. Enjoy!

    devfromhell, 31 Мая 2019

    Комментарии (88)
  3. JavaScript / Говнокод #25650

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    <template>
      <div class="side-effects">
        <div class="side-effects__text" v-html="text"></div>
      </div>
    </template>
    
    <script>
        export default {
          name: 'SideEffects',
          data () {
            return {
              text: '<strong>JORNAY PM can cause serious side effects, including: </strong>' +
            '<ul>' +
            '<li>' +
            '<strong>Abuse and dependence.</strong> JORNAY PM contains methylphenidate. JORNAY PM, other methylphenidate-containing products, and\n' +
            'amphetamines have a high chance for abuse and can cause physical and psychological dependence. Your healthcare provider should check\n' +
            'you or your child for signs of abuse and dependence before and during treatment with JORNAY PM.' +
            '<ul>' +
            '<li>Tell your healthcare provider if you or your child has ever abused or been dependent on alcohol, prescription medicines, or street\n' +
            'drugs. </li>' +
            '<li> Your healthcare provider can tell you more about the differences between physical and psychological dependence and drug addiction. </li>' +
            '</ul>' +
            '</li>' +
            '<li>' +
            '<p class="mb-0"><strong>Heart-related problems, including:</strong></p>' +
            '<ul>' +
            '<li>sudden death, stroke, and heart attack in adults</li>' +
            '<li>sudden death in children who have heart problems or heart defects</li>' +
            '<li> increased blood pressure and heart rate </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Your healthcare provider should check you or your child carefully for heart problems before starting JORNAY PM. Tell your healthcare provider\n' +
            'if you or your child has any heart problems, heart defects, or high blood pressure.' +
            ' <p>Your healthcare provider should check your or your child’s blood pressure and heart rate regularly during treatment with JORNAY PM. </p>' +
            '<p><strong>Call your healthcare provider right away or go to the nearest hospital emergency room right away if you or your child has any signs of\n' +
            'heart problems such as chest pain, shortness of breath, or fainting during treatment with JORNAY PM. </strong></p>' +
            '<ul>' +
            '<li>' +
            '<strong>Mental (psychiatric) problems, including:</strong>' +
            '<ul>' +
            '<li>new or worse behavior and thought problems</li>' +
            '<li>new or worse bipolar illness</li>' +
            '<li>new psychotic symptoms (such as hearing voices, or seeing or believing things that are not real) or new manic symptoms </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Tell your healthcare provider about any mental problems you or your child has, or about a family history of suicide, bipolar illness, or\n' +
            'depression. ' +
            '<p><strong>Call your healthcare provider right away if you or your child have any new or worsening mental symptoms or problems during treatment\n' +
            'with JORNAY PM, especially hearing voices, seeing or believing things that are not real, or new manic symptoms</strong></p>' +
            '<strong>JORNAY PM can cause other serious side effects, including:</strong>' +
            '<ul>' +
            '<li>See <strong>“What is the most important information I should know about JORNAY PM?” </strong></li>' +
            '<li><strong>Painful and prolonged erections (priapism). </strong>Priapism has happened in males who take products that contain methylphenidate. If you or\n' +
            'your child develops priapism, get medical help right away</li>' +
            '<li>' +
            '<strong>Circulation problems in fingers and toes (peripheral vasculopathy, including Raynaud’s phenomenon). Signs and symptoms may\n' +
            'include:</strong>' +
            '<ul>' +
            '<li>fingers or toes may feel numb, cool, or painful</li>' +
            '<li> fingers or toes may change color from pale, to blue, to red </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Tell your healthcare provider if you or your child has numbness, pain, skin color change, or sensitivity to temperature in the fingers or toes. ' +
            '<strong>Call your healthcare provider right away if you or your child has any signs of unexplained wounds appearing on fingers or toes during\n' +
            'treatment with JORNAY PM.</strong>' +
            '<ul>' +
            '<li>' +
            '<strong>Slowing of growth (height and weight) in children</strong> Children should have their height and weight checked often during treatment with\n' +
            'JORNAY PM. JORNAY PM treatment may be stopped if your child is not gaining weight or height. ' +
            '</li>' +
            '</ul>' +
            '<strong>The most common side effects of methylphenidate products in children, adolescents, and adults with ADHD include:</strong>' +
            '<ul>' +
            '<li>decreased appetite</li>' +
            '<li>stomach pain</li>' +
            '<li>irritability</li>' +
            '<li>trouble sleeping</li>' +
            '<li>weight loss</li>' +
            '<li>mood swings (affect lability)</li>' +
            '<li>nausea</li>' +
            '<li>anxiety</li>' +
            '<li>increased heart rate</li>' +
            '<li>vomiting</li>' +
            '<li>dizziness</li>' +
            '<li>increased blood pressure</li>' +
            '<li>indigestion</li>' +
            '</ul>' +
            '<strorg>The most common side effects of JORNAY PM in children age 6 to 12 with ADHD include: </strorg>';
            }
          }
        }
    </script>

    Так вот зачем нужна data и v-html (VueJS)

    websbkinfo, 30 Мая 2019

    Комментарии (4)
  4. JavaScript / Говнокод #25608

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    /* ... */
      if  (kindmusic64[7].checked == true)
      {
        var number = Math.floor(Math.random() * 41);
        switch(number)
        {
          case 0: redradio[0].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 1: redradio[0].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 2: redradio[0].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 3: redradio[1].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 4: redradio[1].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 5: redradio[1].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 6: redradio[1].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 7: redradio[1].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 8: redradio[1].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 9: redradio[2].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 10: redradio[2].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 11: redradio[2].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 12: redradio[2].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 13: redradio[2].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 14: redradio[2].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 15: redradio[3].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 16: redradio[3].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 17: redradio[3].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 18: redradio[0].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 19: redradio[0].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 20: redradio[0].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 21: redradio[1].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 22: redradio[1].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 23: redradio[1].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 24: redradio[1].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 25: redradio[2].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 26: redradio[2].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 27: redradio[2].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 28: redradio[3].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 29: redradio[3].checked = true; greenradio[2].checked = true; blueradio[1].checked = true;  break;
          case 30: redradio[0].checked = true; greenradio[0].checked = true; blueradio[0].checked = true;  break;
          case 31: redradio[1].checked = true; greenradio[1].checked = true; blueradio[1].checked = true;  break;
          case 32: redradio[2].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 33: redradio[3].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 34: redradio[0].checked = true; greenradio[3].checked = true; blueradio[2].checked = true;  break;
          case 35: redradio[0].checked = true; greenradio[2].checked = true; blueradio[2].checked = true;  break;
          case 36: redradio[1].checked = true; greenradio[3].checked = true; blueradio[3].checked = true;  break;
          case 37: redradio[2].checked = true; greenradio[0].checked = true; blueradio[2].checked = true;  break;
          case 38: redradio[3].checked = true; greenradio[1].checked = true; blueradio[3].checked = true;  break;
          case 39: redradio[2].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 40: redradio[3].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 41: redradio[2].checked = true; greenradio[0].checked = true; blueradio[3].checked = true;  break;
          case 42: redradio[0].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 43: redradio[1].checked = true; greenradio[2].checked = true; blueradio[3].checked = true;  break;
          case 44: redradio[0].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 45: redradio[1].checked = true; greenradio[0].checked = true; blueradio[3].checked = true;  break;
          case 46: redradio[1].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
          case 47: redradio[2].checked = true; greenradio[3].checked = true; blueradio[1].checked = true;  break;
          case 48: redradio[2].checked = true; greenradio[0].checked = true; blueradio[1].checked = true;  break;
          case 49: redradio[3].checked = true; greenradio[1].checked = true; blueradio[2].checked = true;  break;
          case 48: redradio[3].checked = true; greenradio[1].checked = true; blueradio[0].checked = true;  break;
          case 49: redradio[3].checked = true; greenradio[2].checked = true; blueradio[0].checked = true;  break;
    /* ... */

    https://olgusha.ru/javascript/colors.htm, да ещё написано, что попробуйте протестировать способность вашего компьютера сочинять музыку и выбирать случайным образом цвета.

    unicorn, 18 Мая 2019

    Комментарии (21)
  5. JavaScript / Говнокод #25594

    +5

    1. 1
    2. 2
    3. 3
    #vCardRoom > div.v-card__text > div > div > form > div > div.flex.xs12 > div > div > div.v-text-field__details > div > div > div {
        font-size: 16px;
    }

    anuxa, 07 Мая 2019

    Комментарии (37)
  6. JavaScript / Говнокод #25584

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function managerLogin(){
    	... //Запрос для входа менеджера
    	cookie.set('MANAGERSESSID', response.MANAGERSESSID);
           ...
    }
    
    function userLogin(){
    	... //Запрос для входа пользователя
    	cookie.set('LKSESSID', response.LKSESSID);
           ...
    }

    Фронтендер решил что бэки слишком медленные и тупые и поэтому теперь он сам будет заниматься менеджментом сессии.
    До этого был бэкер который тоже свои сесии изобретал, кое как починили.
    Но теперь у нас вместо одной сессии две.
    Теоретически их может быть больше.
    Код написан на react с очень большим кол-ом native js.
    Что посоветуете человеке?

    petrun, 03 Мая 2019

    Комментарии (4)
  7. JavaScript / Говнокод #25582

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    findWeight(product) {
            try {
                return product.attributes.filter(e => {
                    return e.attribute.name === 'Вес';
                })[0].value + ' гр.';
            }catch (e) {
    
            }
        }

    WhiterBlack, 02 Мая 2019

    Комментарии (14)
  8. JavaScript / Говнокод #25571

    0

    1. 1
    2. 2
    https://habr.com/ru/post/449368/
    Ко-ко-ко-ко-ко-кой багор )))

    KJlueHTcKuu_nemyx, 25 Апреля 2019

    Комментарии (56)
  9. JavaScript / Говнокод #25517

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    function isSpam(comment) {
        // quick and dirty filter agains guest spam
        // it can reject normal links, but who cares...
        if ((comment.user_id == 1) && comment.text.match('http://'))
                return true;
    
        if ((comment.user_id == 25580) && ((comment.text.match('^, http')) ||
                                           (comment.text.match(',  , http')) ||
                                           (comment.text.match('&lt;strong&gt;')) ||
                                           (comment.text.match('^&lt;a href=')) ||
                                           (comment.text.match('^comment[0-9]+,')) ||
                                           (comment.text.match('storefocus')) ||
                                           (comment.text.match('.*Хрюкни, свинособака')) ||
                                           (comment.text.match('.*<span style')) ||
                                           (comment.text.replace(/\s*/g, '').match('viagra|cialis|levitra')) ||
                                           (comment.text.match('-[0-9a-fA-F]{4}\.pdf'))))
                return true;
        return false;
    }

    http://gcode.cx/ngk/#!/settings

    Какой анскилл )))

    OCETuHCKuu_nemyx, 06 Апреля 2019

    Комментарии (19)
  10. JavaScript / Говнокод #25506

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    else {
            // на всякий случай возвращаем true в случае некоторых экзотических браузеров
            flashinstalled = true;
        }
    return flashinstalled;

    https://csdrop.org/
    main.js
    Просто из за комментария ☺

    GreatMASTERcpp, 04 Апреля 2019

    Комментарии (8)