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

    +158

    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
    96. 96
    97. 97
    98. 98
    // weclome to main-menu-hover.js
    function load(){
    	var url = window.location;
    	var m1 = document.getElementById("m1");
    	var m2 = document.getElementById("m2");
    	var m3 = document.getElementById("m3");
    	var m4 = document.getElementById("m4");
    	//var m5 = document.getElementById("m5");
    	var mm1 = document.getElementById("mm1");
    	var mm2 = document.getElementById("mm2");
    	var mm3 = document.getElementById("mm3");
    	var mm4 = document.getElementById("mm4");
    	var mm5 = document.getElementById("mm5");
    	var mm6 = document.getElementById("mm6");
    	var mm7 = document.getElementById("mm7");
    var mm8 = document.getElementById("mm8");
    	if (m1.href == url){
    	m1.style.color = "#ffc12b";
    	//m1.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat top center";
    	m1.style.textDecoration = "none";
    	}
    	if (m2.href == url){
    	m2.style.color = "#ffc12b";
    	m2.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m2.style.textDecoration = "none";
    	}
    	if (m3.href == url){
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (m4.href == url){
    	m4.style.color = "#ffc12b";
    	m4.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m4.style.textDecoration = "none";
    	}
    	if (m5.href == url || url.href.indexOf(m5.href)!=-1){
    	m5.style.color = "#ffc12b";
    	m5.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg2.png)no-repeat center center";
    	m5.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm1.href)!=-1){
    	mm1.style.color = "#741f0c";
    	mm1.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm2.href)!=-1){
    	mm2.style.color = "#741f0c";
    	mm2.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm3.href)!=-1){
    	mm3.style.color = "#741f0c";
    	mm3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm4.href)!=-1){
    	mm4.style.color = "#741f0c";
    	mm4.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm5.href)!=-1){
    	mm5.style.color = "#741f0c";
    	mm5.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm6.href)!=-1){
    	mm6.style.color = "#741f0c";
    	mm6.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    	if (url.href.indexOf(mm7.href)!=-1){
    	mm7.style.color = "#741f0c";
    	mm7.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
        if (url.href.indexOf(mm8.href)!=-1){
    	mm8.style.color = "#741f0c";
    	mm8.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/bg-min-menu-h.png)no-repeat center center";
    	m3.style.color = "#ffc12b";
    	m3.style.background = "url(%absolute_url_path%/wp-content/themes/%pattern%/images/menu-h-bg1.png)no-repeat center center";
    	m3.style.textDecoration = "none";
    	}
    }

    Пришел проект на поддержку... Сразу отказался=)
    Естественно вкрапления %_some_text_% от меня.
    Файл назывался main-menu-hover.js

    iHateBidlocod, 30 Мая 2014

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var percent = 0;
    setInterval(function() {
        if(percent < 100) {
            percent += 10;
            showprogress(percent);
        }
    }, 50);

    Прогресс-бар асинхронной загрузки картинки

    kissarat, 30 Мая 2014

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function FindPosOfStr(str1, str2) {
    	for (i = 0; i <= str1.length; i++) {
    		comp = str1.substring(i, str1.length);
    		comp = comp.substring(0, str2.length);
    		if (comp == str2) {
    			return i;
    			break;
    		}
    	}
    	return -1;
    }

    Вот такое вот веселье встретилось в одном проекте. Кто-то был сильно пьян и забыл про indexOf

    _rMX_, 22 Мая 2014

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

    +154

    1. 1
    2. 2
    3. 3
    function deleteCookie(name, path, domain) {
    	if (getCookie(name)) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-1970 00:00:00 GMT';
    }

    ...

    gost, 21 Мая 2014

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var turn = 0;
    		function turn_over() {
    			var text = document.getElementById('turn-over-in').value;
    			var first_letter = text.charAt(0).toLowerCase();
    			var last_letter = text.charAt(text.length-1).toUpperCase();
    			var new_text = first_letter + text.substr(1,text.length-2) + last_letter;
    			var text_array = new_text.split('');
    			var inside_out = text_array.reverse();
    			var turn_over_text = inside_out.join('');
    			document.getElementById('turn-over-out').value = turn_over_text;
    <...>

    Задача: развернуть строку текста (Абв->Вба).

    gost, 21 Мая 2014

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function chksremail(t) {
    	if (t.value!='' && (t.value.indexOf('@')<1 || t.value.indexOf('.')<1 || t.value.length<4 || t.value.indexOf(' ')!=-1)) {
    		if (t.value.indexOf('@')<1) alert('Вы ввели неправильный адрес электронной почты! Адрес электронной почты должен обязательно содержать символ "@".');
    		else if (t.value.indexOf('.')<1) alert('Вы ввели неправильный адрес электронной почты! Адрес электронной почты должен обязательно содержать точку (".").');
    		else if (t.value.length<4) alert('Вы ввели неправильный адрес электронной почты! Адрес электронной почты должен обязательно содержать минимум 4 символа.');
    		else if (t.value.indexOf(' ')!=-1) alert('Вы ввели неправильный адрес электронной почты! Адрес электронной почты не может содержать пробелы.');
    		t.focus();
    		return false;
    	}
    	return true;
    }

    $%&$@^@#$^@rlu.ru/rlu.js

    gost, 21 Мая 2014

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

    +153

    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
    function b_copy(p) {
    	var f=0;
    	if (window.clipboardData&&window.clipboardData.setData) {
    		var ind=p.innerHTML;
    		ind=ind.replace(/&gt;/g,'>');
    		ind=ind.replace(/&lt;/g,'<');
    		ind=ind.replace(/&quot;/g,'"');
    		ind=ind.replace(/&amp;/g,'&');
    		window.clipboardData.setData('Text',ind);
    		if (window.clipboardData.getData('Text')==ind) {
    			alert('Код успешно скопирован в буфер обмена.');
    			f=1;
    		}
    	}
    	if (f==0) {
    		if (typeof (window.getSelection)=='function') {
    			window.getSelection().selectAllChildren(p);
    		}
    		else {
    			var r=document.body.createTextRange();
    			r.moveToElementText(p);
    			r.select();
    		}
    		alert('Нажмите кнопку "Ok", а затем клавиши CTRL+C, чтобы скопировать код в буфер обмена.');
    	}
    }

    Продолжаем искать говнокод на страницах левых сайтов.

    http://ping-admin.ru/pa.js

    gost, 21 Мая 2014

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

    +156

    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
    $(document).ready(function(){
                if(document.location.href.indexOf("coding")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(1).addClass("activ_line2");
                }
                if(document.location.href.indexOf("portfolio")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(2).addClass("activ_line2");
                }
                if(document.location.href.indexOf("graphika")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(3).addClass("activ_line2");
                }
                if(document.location.href.indexOf("seo-yandex-google")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(4).addClass("activ_line2");
                }
                if(document.location.href.indexOf("kuchniy")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(5).addClass("activ_line2");
                }
                if(document.location.href=="http://catine.ru/")
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(0).addClass("activ_line2");
                }
    			var min = false;
    			$(document).scroll(function() {
    				if($(document).scrollTop()>30&&!min)
    				{
    					$(".line2").toggleClass("header_max header_min");
    					min = true;
    				}
    				if($(document).scrollTop()<=30&&min)
    				{
    					$(".line2").toggleClass("header_max header_min");
    					min = false;
    				}
    			});
            });

    Блог начинающего веб-разработчика...

    TRANE73, 20 Мая 2014

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

    +162

    1. 1
    var errorIsShown = false; // если уже показана ошибка, то зачем опять показывать сообщение об ошибке (ведь если чего то не так.. то логично, что ошибки ещё будут...)

    |Mesi

    И еще больше замечательных комментариев: http://study.mesi.ru/_layouts/elrportal/assessment/JScript/Other.js

    alyxbit, 19 Мая 2014

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

    +154

    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
    (function () {
    
        if (location.pathname === "/") {
            document.body.id = 'front-page';
        }
        else {
            var path = window.location.pathname.replace('/index.php/', ''),
                splittedPath = path.split('/') || ['', ''],
                category = splittedPath[0],
                subcategory = '';
    
            for (var i = 1; i < splittedPath.length; i++) {
                subcategory += ('-' + splittedPath[i]);
            }
    
            if (category && (typeof category === 'string')) {
                document.body.classList.add('page-' + category);
            }
    
            if (subcategory && (typeof subcategory === 'string')) {
                document.body.classList.add('page-' + subcategory.replace(/^[-]/, ''));
            }
        }
    
    })();

    Сей замысловатый код призван добавить уникальный класс в body для каждой страницы прямо из урла. Предназначалось в качестве костыля для джумлы, так как через пых не работало, а разбираться никто не стал :)

    DrDre, 19 Мая 2014

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