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

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

    +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
    96. 96
    97. 97
    98. 98
    99. 99
    package main
    
    import (
    	"io"
    	"fmt"
    	"log"
    	"bytes"
    	"strings"
    	"net/http"
    	"net/http/httputil"
    	"net/url"
    )
    
    func UpdateResponse(r *http.Response) error {
    	for k, v := range r.Header {
    		newValue := strings.Replace(v[0], "umnico.com", "umnico.*****.ru", -1)
    		r.Header[k][0] = newValue
    	}
    	b, err := io.ReadAll(r.Body)
    	if(err == nil) {
    		bodyText := strings.Replace(string(b), "://umnico.com", "://umnico.*****.ru", -1);
    		if(strings.Contains(bodyText, "</head><body>")) {
    			injectedStyle := `<style>
    			.nav-menu.hidden, .widget__preview-container--tech-support {
    				display: none !important;
    			}
    			</style>`
    			bodyText = strings.Replace(bodyText, "</head><body>", injectedStyle + "</head><body>", -1);
    		}
    		if(strings.Contains(bodyText, "</body></html>")) {
    			injectedScript := `<script>
    			fetch('/api/user').then((response) => { 
    				return response.json().then((data) => {
    					//alert(data.user.id);
    					if(data.user.id != 12345) {
    						const style = document.createElement('style');
    						style.textContent = '.im__chat-buttons{display:none!important;}';
    						document.head.appendChild(style);
    					}
    					return true;
    				}).catch((err) => {
    					console.log(err);
    				}) 
    			});
    			var currentDialogId = 0;
    			function checkDialogControls() {
    				if(location.pathname.indexOf('app/deals/inbox/details/') > 0 || location.pathname.indexOf('app/deals/active/details/') > 0) {
    					if(location.pathname.indexOf('app/deals/active/details/') > 0) {
    						var dialogId = location.pathname.split('app/deals/active/details/')[1];
    					} else {
    						var dialogId = location.pathname.split('app/deals/inbox/details/')[1];
    					}
    					var chatIndicator = document.querySelector('.im-aside-section.im-aside-section__toolbox');
    					if(chatIndicator != null) {
    						var injectedControls = document.querySelector('.im-aside-section.injected-controls');
    						if(injectedControls == null) {
    							chatIndicator.insertAdjacentHTML('afterend', '<div class="im-aside-section injected-controls"><div><button type="button" class="button" style="width:100%;" onclick="window.parent.postMessage(\'openBookingModalByUmnicoId('+dialogId+')\', \'*\');">Оформить бронь</button></div><div style="margin-top:5px;"><button type="button" class="button button_attention" style="width:100%;" onclick="window.parent.postMessage(\'openLeadTaskModalByUmnicoId('+dialogId+')\', \'*\');">Задача</button></div></div>');
    						} else {
    							if(currentDialogId != dialogId) {
    								injectedControls.remove();
    							}
    						}
    						currentDialogId = parseInt(dialogId);
    					}
    				}
    			}
    
    			setInterval(checkDialogControls, 100);
    			</script>`
    			bodyText = strings.Replace(bodyText, "</body></html>", injectedScript + "</body></html>", -1);
    		}
    		
    		if(strings.Contains(bodyText, "window.location.hostname != \"localhost\"")) {
    			bodyText = strings.Replace(bodyText, "window.location.hostname != \"localhost\"", "window.location.hostname != \"localhost\" && window.location.hostname != \"umnico.*****.ru\"", -1);
    		}
    		
    		buf := bytes.NewBufferString(bodyText)
    		r.Body = io.NopCloser(buf)
    		r.Header["Content-Length"] = []string{fmt.Sprint(buf.Len())}
    	}
    	return nil
    }
    
    func main() {
    	target, err := url.Parse("https://umnico.com:443")
    	if err != nil {
    		log.Fatal(err)
    	}
    	proxy := httputil.NewSingleHostReverseProxy(target)
    	proxy.ModifyResponse = UpdateResponse
    	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    		req.Host = req.URL.Host
    		proxy.ServeHTTP(w, req)
    	})
    	err = http.ListenAndServe("127.0.0.1:8803", nil)
    	if err != nil {
    		panic(err)
    	}
    }

    Мой код для проксирования одного из SaaS-сервисов, с целью встраивания в интерфейс последнего кастомных кнопок. Взглянул спустя пару месяцев и ужаснулся.

    rotoeb, 17 Мая 2024

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

    +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
    /// <summary>
    /// перобразуем DateTime? в DateTime, если не получается, то возвращаем текущую дату
    /// </summary>
    /// <param name="date"></param>
    /// <returns></returns>
    private DateTime DateTimeHelper(DateTime? date)
    {
        try
        {
            return (DateTime)date;
        }
        catch
        {
            return DateTime.Now;
        }
    }

    reemind, 03 Мая 2024

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