1. Лучший говнокод

    В номинации:
    За время:
  2. JavaScript / Говнокод #14209

    +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
    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
    if (/mail\/\?r=mail\/message_list/gim.test(location.href)) {
    		var ihoho = $($('form')[1]).parent().clone(true);
    		var myNickName = $($('li.sep_bl:has("a[href*=\'/mysite/\']")').find("a")[0]).prop("title");
    		eval('var prrtrns = /<b style="color:navy;">' + myNickName + '<\\/b>/gim;');
    		$($('form')[1]).parent().remove();
    		$($('.blue_wrap_block')[0]).after(ihoho);
    		var xls = $($($('form')[1]).find("input[type*='submit']")[0]);
    		xls.prop('type', 'button');
    		xls[0].setAttribute('onclick', 'var temp_tT = this.parentNode.parentNode.texttT.value; var rrr = this.parentNode.parentNode.r.value;var sid = this.parentNode.parentNode.sid.value;var CK = this.parentNode.parentNode.CK.value;var texttT = this.parentNode.parentNode.texttT.value;var Link_id = this.parentNode.parentNode.Link_id.value;var user = this.parentNode.parentNode.user.value;$.ajax({type:"POST",url: "http://spaces.ru/mail/?",data: {r:rrr,user:user,CK:CK,sid:sid,Link_id: Link_id,texttT:texttT},success:function(){document.forms[1].texttT.value = "";}});');
    		xls[0].setAttribute('name', 'okletsgo');
    		xls[0].setAttribute('style', 'display:none');
    		$('#navi').before("<script></script>");
    		document.forms[1].setAttribute('onkeypress', 'function lovly(e) { if (e.keyCode == 87 && e.altKey) document.forms[1].texttT = temp_tT; if (e.keyCode == 13 && !e.shiftKey && !e.ctrlKey) document.forms[1].okletsgo.click(); } lovly(event)');
    		$('.t-bg3').each(function(i) {
    					$(this).html($(this).html().replace(/<b style="color:darkmagenta;">Я<\/b>/gim, '<b style="color:navy;"><img src="http://spaces.ru/i//man_on.gif" alt="(ON)"/> <span style="text-decoration:underline">' + myNickName + '</span></b>').replace("<div class=\"overfl_hid service_links_block service_links_block_top clear\">", "<div style='display:none'>"));
    		}); //replace("<div class=\"left font0 avatar_wrap padd_right\">", '<div style="display:none">').
    		var reloadedMail = function(data) {
    			var dt = '';
    			$($(data).find("form")[1]).parent().each(function() {
    				dt = this.outerHTML;
    			});
    			data = data.replace(dt, "");
    			$(data).find('.t-bg3').each(function(i) {
    				if ($(this).html().replace(/Link_id=([0-9]+)/gim) != $($('.main').find('.t-bg3')[i]).html().replace(/Link_id=([0-9]+)/gim)) 
    				{
    					$($('.main').find('.t-bg3')[i]).html($(this).html().replace(/<b style="color:darkmagenta;">Я<\/b>/gim, '<b style="color:navy;"><img src="http://spaces.ru/i//man_on.gif" alt="(ON)"/> <span style="text-decoration:underline">' + myNickName + '</span></b>').replace("<div class=\"overfl_hid service_links_block service_links_block_top clear\">", "<div style='display:none'>"));
    					if ($(this).html().match(prrtrns) && settings.ajaxMailNotifications) {
    						$('#navi').before('<audio preload="auto" autoplay src="http://driverjs.webservis.ru/income.ogg"></audio>');
    					}
    				}
    			});
    		}
    		var reloadMail = function() {
    			$.ajax({
    				url: location.href,
    				success: reloadedMail
    			});
    			setTimeout(reloadMail, settings.ajaxTimeout);
    		}
    		reloadMail();
    	}

    Что? Разработчики сайта не сделали отправку/принятие сообщений на AJAX?!
    Поправим! Юзерскрипт порешает все.
    //P.S. ЭТО КАК-ТО работает. Правда.

    Efog, 10 Декабря 2013

    Комментарии (2)
  3. PHP / Говнокод #14203

    +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
    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
    php_sapi_name() === 'cli' or exit('Only CLI mode allowed');
    
    getenv('API_HOST') or exit(<<<EOT
    
      To run tests you should setup "API_HOST" environment variable.
      Try follow in bash command line:
    
      $ export API_HOST=<api_host>
      cd path/to/tests
      php direct_report_problem.php
    
    
    EOT
    );
    
    defined('API_ENDPOINT') || define('API_ENDPOINT', getenv('API_HOST') . '/webservice/index.php');
    
    $method = API_ENDPOINT . '?op=...';
    
    $describe = function ($msg, $test) {
        printf("\n\n[%s]\n\n%s\n\n", $msg, shell_exec($test()));
        sleep(2);
    };
    
    $describe('Cannot upload empty report', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report note', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report image', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload all data direct report note, image, sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' -F [email protected]'
        . ' -F [email protected]'
        . ' ' . $method;
    });

    __proto__, 10 Декабря 2013

    Комментарии (24)
  4. PHP / Говнокод #14184

    +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
    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
    //...
    $_GET = safe_data ($_GET, 'query');
    // Ниже по коду
    $_GET = safe_data ($_GET, 'query');
    $result = mysql_query ('SELECT * FROM ' . $dblist . ' WHERE id=\'' . $_GET['id'] . '\' LIMIT 1', $link);
    $_POST = mysql_fetch_array ($result);
    $_POST = safe_data ($_POST, 'display');
    
    // safe_data, убраны пустые строки и лишние {}
    function safe_data ($firste, $second)
    {
      if ($second == 'query')
      {
        if (is_array ($firste))
        {
          foreach ($firste as $safedatafor => $safedatasry)
          {
            if (get_magic_quotes_gpc ())
              $safedatasry = stripslashes ($safedatasry);
            
            $firste[$safedatafor] = addslashes ($safedatasry);
          }
          return $firste;
        }
    
        if (get_magic_quotes_gpc ())
          $safedatasry = stripslashes ($safedatasry);
    
        $firste = addslashes (stripslashes ($firste));
        return $firste;
      }
    
      if ($second == 'display')
      {
        if (is_array ($firste))
        {
          foreach ($firste as $safedatafor => $safedatasry)
            $firste[$safedatafor] = htmlspecialchars (stripslashes ($safedatasry), ENT_QUOTES);
    
          return $firste;
        }
        $firste = htmlspecialchars (stripslashes ($firste), ENT_QUOTES);
      }
    
      return $firste;
    }

    Из AutoBoss 3.0 Professional
    Разработчики http://www.curve2.com/ - в настоящее время показывает пустую страницу
    Мои глаза (>_<)

    psycho-coder, 06 Декабря 2013

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

    +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
    App.ns.SomeClass.prototype = {
        addMessage: function(status, msg, timeDelay) {
            if (status === false || status === this.STATUS_ERROR) {
                status = this.STATUS_ERROR;
                delay = timeDelay || 5; // default delay of msg box for error is 5 seconds. 
            }
            if (!timeDelay) {
                // 1 character - 1/7 sec 
                delay = msg.length / 7;
                if ((delay < 3) && !(timeDelay)) {
                    delay = 3;
                } else if ((delay > 30) && !(timeDelay)) {
                    delay = 30;
                    }
            }
            // показываем messagebox
        }
    };

    Кручу-верчу, запутать хочу.

    Elvenfighter, 24 Ноября 2013

    Комментарии (4)
  6. PHP / Говнокод #14112

    +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
    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
    //поменяет src картинки на cid и вернет массив с дополнительными секциями тела письма
    function convert_image_src($text, &$new_section_arr){
    	global $_SERVER;
    	
    	//расчленяем текст на куски по img
    	$new_src_arr=array();//массив путей к картинкам
    	$arrTmp=explode("<img", $text);
    	$explode_str=array("\\\"", "\"", "'");
    	
    	for($i=1; $i<sizeof($arrTmp); $i++){
    		$arrTmp2=explode("src=", $arrTmp[$i]);
    		
    		for($j=1; $j<sizeof($arrTmp2); $j++){
    			for($k=0; $k<sizeof($explode_str); $k++){
    				if(substr($arrTmp2[$j], 0, strlen($explode_str[$k]))==$explode_str[$k]){
    					$arrTmp3=explode($explode_str[$k], $arrTmp2[$j]);
    					
    					//считать можем только картинки с того же сервера  - остальные побоку
    					if(ref_is_server($arrTmp3[1])){
    						$old_src_arr[]=$arrTmp3[1];
    						$new_src_arr[]=convert_url_2_full_server($arrTmp3[1]);
    					}
    				}
    			}
    		}
    	}
    	
    	//теперь формируем новые секции
    	for($i=0; $i<sizeof($new_src_arr); $i++){
    		$file_arr=get_file_content($new_src_arr[$i], true);
    		if(strlen($file_arr[0])>0){
    			//запоминаем секцию
    			$new_section_arr[]=$file_arr[0];
    			//заменяем ссылку на cid
    			$text=str_replace($old_src_arr[$i], "cid:".$file_arr[1], $text);
    		}
    	}
    	
    	return $text;
    }

    Супер функция, которая парсит картинки в тексте и заменяет на, как я понял, новые ссылки уже на собственном сервере.
    Пока пытался разобраться, наступил когнитивный диссонанс.

    oooZinka, 20 Ноября 2013

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

    +153

    1. 1
    http://froland.ru/samodel/myart_js1.html

    Я хотел бы это развидеть.

    nsauk, 20 Ноября 2013

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

    +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
    // Высота шрифта
    
    	$lenHdr = mb_strlen( strip_tags($header), 'UTF-8');
    
    	$maxDefaultStrLen = 38;	// максимальное количество символов при заданном размере шрифта
    	$maxFontSize = 22;		// заданный размер шрифта
    
    	$fontSize = $maxFontSize;
    
    	if ( $lenHdr > $maxDefaultStrLen ) {
    
    		$k = ceil(sqrt(($lenHdr - $maxDefaultStrLen) + 0.25) - 0.5) + 2 ;
    
    		$k = ($k<3)? 3:$k;
    
    		$fontSize = $maxFontSize - ($k - 2)*2;
    
    		$fontSize = ($fontSize<12)? 12:$fontSize;
    	}

    Вот. Откопалось

    bot, 08 Ноября 2013

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

    +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
    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
    //Флаг установки поля "дальше"
    var AgreeRes = function () {
        var res             = true,
            people_count    = $('.bookingPassengersTitle').length,
            pcount          = 6,
            $pa             = $('.required.passport_term.checkPassportData.valid'),
            $pas            = $('.required.passposrt_num.valid')  ,
            $male           = $('.male.required.valid'),
            $ch             = $('.required.birth_date.checkBirth.valid') ,
            $nam            = $('.required.first_name.valid'),
            $name           = $('.required.sec_name.valid');
    
        var button_count = 0    +
                $pa.length      +
                $pas.length     +
                $male.length    +
                $ch.length      +
                $nam.length     +
                $name.length;
    
        res = button_count == people_count * pcount || button_count == 0;
        
        if (  $('.required.passport_term.checkPassportData.valid, ' +
                '.required.passposrt_num.valid, ' +
                '.male.required.valid, ' +
                '.required.birth_date.checkBirth.valid, ' +
                '.required.first_name.valid, ' +
                '.required.sec_name.valid').length > 0 ) {
            if (res == false
                || $pa.val().trim().toString()      === ""
                || $pas.val().trim().toString()     === ""
                || $male.val().trim().toString()    === ""
                || $ch.val().trim().toString()      === ""
                || $nam.val().trim().toString()     === ""
                || $name.val().trim().toString()    === "") {
    
                res = false;
            }
        }
    
        return res;
    }

    Клиентская валидация контролов

    sladkijBubaleh, 17 Октября 2013

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

    +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
    27. 27
    28. 28
    function Recalc(index) {
                var url = window.location.pathname + "?";
                var data = "DepartureDate=" + $("#AvailabilityList_" + index + "__DepartureDate").val()
    				 + "&DepartureTime=" + $("#AvailabilityList_" + index + "__DepartureTime").val()
                + "&ArrivalDate=" + $("#AvailabilityList_" + index + "__ArrivalDate").val()
                + "&ArrivalTime=" + $("#AvailabilityList_" + index + "__ArrivalTime").val()
                + "&FromCode=" + $("#AvailabilityList_" + index + "__FromCode").val()
                + "&ToCode=" + $("#AvailabilityList_" + index + "__ToCode").val()
                + "&ShipCode=" + $("#AvailabilityList_" + index + "__ShipCode").val()
                + "&ProviderCode=" + $("#AvailabilityList_" + index + "__ProviderCode").val()
                + "&Duration=" + $("#AvailabilityList_" + index + "__Duration").val()
                + "&AdultCount=" + $("#AvailabilityList_" + index + "__AdultCount").val()
                + "&ChildCount=" + $("#AvailabilityList_" + index + "__ChildCount").val()
                + "&FerryID=" + $("#AvailabilityList_" + index + "__FerryID").val()
                + "&Auto=" + $("#AvailabilityList_" + index + "__Auto").val()
                + "&FareCode=" + $("#AvailabilityList_" + index + "__FareCode").val()
                + "&Years[0]=" + $("#AvailabilityList_" + index + "__Years_0_").val()
                + "&Years[1]=" + $("#AvailabilityList_" + index + "__Years_1_").val()
                + "&Years[2]=" + $("#AvailabilityList_" + index + "__Years_2_").val()
                + "&Years[3]=" + $("#AvailabilityList_" + index + "__Years_3_").val()
                + "&Years[4]=" + $("#AvailabilityList_" + index + "__Years_4_").val()
                + "&Years[5]=" + $("#AvailabilityList_" + index + "__Years_5_").val()
                + "&Years[6]=" + $("#AvailabilityList_" + index + "__Years_6_").val()
                + "&Years[7]=" + $("#AvailabilityList_" + index + "__Years_7_").val()
                + "&Years[8]=" + $("#AvailabilityList_" + index + "__Years_8_").val()
                + "&Index=" + index;
                return data;
            }

    Back-end asp.net mvc, кому интересно

    sladkijBubaleh, 16 Октября 2013

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

    +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
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    function compare_date(start_day, start_hour, start_min, end_day, end_hour, end_min)
    {
      var start_ = start_day.split('-');
      var end_ = end_day.split('-');
    
      if (start_[2] > end_[2]) return false;
      else {
        if (start_[2] == end_[2]) {
          if (start_[1] > end_[1]) return false;
          else {
            if (start_[1] == end_[1]) {
              if (start_[0] > end_[0]) return false;
              else {
                if (start_[0] == end_[0]) {
                  if (parseFloat(start_hour) > parseFloat(end_hour)) return false;
                  else {
                    if (parseFloat(start_hour) == parseFloat(end_hour)) {
                      if (parseFloat(start_min) > parseFloat(end_min)) return false;
                      else {
                        if (parseFloat(start_min) == parseFloat(end_min)) return false;
                        else return true;
                      }
                    }
                    else return true;
                  }
                }
                else return true;
              }
            }
            else return true;
          }
        }
        else return true;
      }
    }

    Откопал функцию-велосипед для сравнения двух дат. Возвращает true, если вторая дата позже первой.

    MikleSmart, 27 Сентября 2013

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