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

    +170

    1. 1
    return (this.name == objToCompare.name) ? true : false;

    Из платного учебника по JS. 2350 рублей.

    Ceyce, 17 Июня 2010

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

    +148

    1. 1
    2. 2
    3. 3
    if (browser.opera && browser.version < 10.50) {
              parent.innerHTML = parent.innerHTML;
            }

    http://vkontakte.ru/js/player.js?10 (c)

    Back, 13 Июня 2010

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

    +184

    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
    function reverse_string(str, len) {
    	if (len == 1) {
    		return str.charAt(0);
    	}
    	if (len == 2) {
    		return str.charAt(1) + str.charAt(0);
    	}
    	if (len == 3) {
    		return str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 4) {
    		return str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 5) {
    		return str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 6) {
    		return str.charAt(5) + str.charAt(5) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 7) {
    		return str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 8) {
    		return str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 9) {
    		return str.charAt(8) + str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 10) {
    		return str.charAt(9) + str.charAt(8) + str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    };

    Переворачивание строки при помощи новейших технологий. Также ожидается движок (по содержанию конечно кусок говна, но по размерам похож), который позволит переворачивать строки любой длины (таким же методом). В-общем, прогноз неутешительный.

    eval, 11 Июня 2010

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

    +157

    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
    function month_to_number(a) {
    	if (a == 'Jan') {
    		a = '01';
    	}
    	if (a == 'Feb') {
    		a = '02';
    	}
    	if (a == 'Mar') {
    		a = '03';
    	}
    	if (a == 'Apr') {
    		a = '04';
    	}
    	if (a == 'May') {
    		a = '05';
    	}
    	if (a == 'Jun') {
    		a = '06';
    	}
    	if (a == 'Jul') {
    		a = '07';
    	}
    	if (a == 'Aug') {
    		a = '08';
    	}
    	if (a == 'Sep') {
    		a = '09';
    	}
    	if (a == 'Oct') {
    		a = '10';
    	}
    	if (a == 'Nov') {
    		a = '11';
    	}
    	if (a == 'Dec') {
    		a = '12';
    	}
    	return a;
    };

    eval, 10 Июня 2010

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var url = 'djvu_text?nd=808604175&hidx=0&print=1&page=-1&save=1';
    var params = url.split('=');
    var ndarr = params[1].split('&');
    var nd = ndarr[0];
    
    return nd;

    Легко и не навязчиво выдираем значение параметра из строки с URL

    Nexus, 08 Июня 2010

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

    +157

    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
    // ==UserScript==
    // @name           govnokod.ru.user.js
    // @description    highlight for new comments
    // @author         [email protected]
    // @include        http://govnokod.ru/*
    // ==/UserScript==
    
    if(!jQuery.cookie)
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    
    var there_href = document.location.href.match(/govnokod\.ru\/(\d+)/);
    if ( there_href ) // in topic
    	$(document).ready(function() {
    		var govnokod_n = there_href[1];
    		var cookiename = 'gk'+govnokod_n
    		var lastvisit = new Date(parseInt($.cookie(cookiename)));
    		var now = new Date();
    		var comments = $(".hcomment abbr").filter(function(index,elem) {
    			var date=new Date(elem.title.replace("T"," ").replace(/\+(\d\d):(\d\d)$/," GMT+$1$2"));
    			return date>lastvisit;
    		});
    		for (var i=0;i<comments.length;i++)
    		{
    			var elem = comments[i];
    			var header = elem.parentElement;
    			var block = elem.parentElement.parentElement;
    			block.style.background = '#FACE8D';
    			var anchor = document.createElement("a");
    			anchor.setAttribute('name','new_'+i);
    			block.insertBefore(anchor,block.firstChild);
    			
    			var prevlink = document.createElement("a");
    			if (i!=0)
    				prevlink.setAttribute('href','#new_'+(i-1));
    			prevlink.appendChild(document.createTextNode('⟵'));
    			header.insertBefore(prevlink,elem.nextSibiling);
    			
    			header.insertBefore(document.createTextNode(' '),elem.nextSibiling);
    			
    			var nextlink = document.createElement("a");
    			if (i!=comments.length-1)
    				nextlink.setAttribute('href','#new_'+(i+1));
    			nextlink.appendChild(document.createTextNode('⟶'));
    			header.insertBefore(nextlink,elem.nextSibiling);
    
    		}
    		
    		var new_comments_count = document.createElement("a");
    		if (comments.length)
    			new_comments_count.setAttribute('href','#new_0');
    		new_comments_count.appendChild(document.createTextNode(''+comments.length+' новых'));
    		var comments_count = $(".enrty-comments-count");
    		comments_count.text(comments_count.text().replace(/\)$/,', '));
    		comments_count.append(new_comments_count);
    		comments_count.append(')');
    		$.cookie(cookiename, now.valueOf(), { 'expires': 3 }); //помним, что имеется ограничение на размер куков.
    	});

    Наговнокодил подсвечивалку новых комментариев для говногод.ру. Смесь из обычного DOM и тутошнего jQuery. Сохранить как govnokod.ru.user.js. Тестировал только в опере.

    legolegs, 06 Июня 2010

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

    +165

    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
    <div style="font-size:30px; text-align: center;padding-top: 50px;">Число установок принципиально новой OS<br><b><span id="installCount">10324435</span></b></div>
            <script type="text/javascript">
            var memCount = 10584471;
            var memPerSec = 1.38176367782;
            function updateCount() {
              next = -(1000 / memPerSec)*Math.log(Math.random());
              memCountString = '' + memCount;
              len = memCountString.length;
              memCountString = memCountString.substr(0,len-6)+'<span style="font-size:30px"> </span>'+memCountString.substr(len-6,3)+'<span style="font-size:30px"> </span>'+memCountString.substr(len-3,3);
              document.getElementById('installCount').innerHTML = memCountString;
              memCount = memCount + 1;
              setTimeout(updateCount, next);
            }
            updateCount();
            </script>

    Помните на сайте знаменитой , принципиально новой http://bolgenos.ru/ есть табло сколько человек скачало ?
    Выше скрипт ЩИТалки :)
    Мало того что обман , так ещё и кривой

    TIMHOK, 05 Июня 2010

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

    +159

    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
    function countInt(int32)
    {
    	var n = int32;
    	if (n == 0) n = 1;
    	n = Math.abs(n);
    	var len = 0;
    	while (n > 0)
    	{
        	len++;
        	n = n / 10;
    		n = parseInt(n); 
    	}
    	return len;
    }
    function zeroAdder(int32)
    {
    	var str = '';
    	if (countInt(int32) == 1) str = '0';
    	str = str + int32;
    	return str;	
    }
    function pasteDT()
    {
    	d = new Date();
    	$('#element_4_1').attr('value',zeroAdder(d.getDate()));
    	$('#element_4_2').attr('value',zeroAdder(d.getMonth()+1));
    	$('#element_4_3').attr('value',zeroAdder(d.getFullYear()));
    	$('#element_5_1').attr('value',zeroAdder(d.getHours()));
    	$('#element_5_2').attr('value',zeroAdder(d.getMinutes()));
    	
    }

    Короче код для заполнения полей формы датой и временем.
    Функция countInt - исчисляет количество цифр в целом числе, даже в отрицательном.
    Функция zeroAdder - добавляет 0, если допустим первое число (1). Преобразовывает его в строку '01'.
    Как вы увидели, я использую jQuery, хотя Prototype как-то удобнее.

    increazon, 05 Июня 2010

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

    +180

    1. 1
    /^[a|b|c|d|e|f|g|h|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|@|\.|-]*$/gim

    Проверка валидности E-Mail от местного умельца.

    eval, 04 Июня 2010

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

    +158

    1. 1
    2. 2
    3. 3
    if ($('#block').is(':hidden')) {
    $('#block').toggle();
    }

    eval, 04 Июня 2010

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