No HTTPS Security Warning

Displays a red bar as a security warning if the site does not have HTTPS

  1. // ==UserScript==
  2. // @name No HTTPS Security Warning
  3. // @name:pt-BR Aviso de Segurança sem HTTPS
  4. // @namespace about:addons
  5. // @version 1.0.1
  6. // @description Displays a red bar as a security warning if the site does not have HTTPS
  7. // @description:pt-BR Exibe uma barra vermelha como aviso de segurança caso o site não possua HTTPS
  8. // @author Diego Nascimento // greasyfork@nascimentodiego.com.br
  9. // @license MIT
  10. // @match *://*/*
  11. // @grant none
  12. // @homepageURL https://greasyfork.org/pt-BR/scripts/520671-no-https-security-warning
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18. // Verifica o idioma do navegador
  19. var userLang = (navigator.language || navigator.userLanguage).toLowerCase();
  20. // Define as mensagens com base no idioma
  21. var avisoTexto;
  22. var botaoTexto;
  23. if (userLang === 'pt-br') {
  24. avisoTexto = 'ALERTA DE SEGURANÇA: A página acessada não possui HTTPS. Os dados podem não estar protegidos!';
  25. botaoTexto = 'Fechar';
  26. } else {
  27. avisoTexto = 'SECURITY ALERT: You are accessing this page without HTTPS. Data may not be secure!';
  28. botaoTexto = 'Dismiss';
  29. }
  30.  
  31. // Verifica o protocolo da página atual
  32. if (window.location.protocol !== 'https:') {
  33. // Cria o container do aviso
  34. var avisoContainer = document.createElement('div');
  35. avisoContainer.style.position = 'fixed';
  36. avisoContainer.style.top = '0';
  37. avisoContainer.style.left = '0';
  38. avisoContainer.style.width = '100%';
  39. avisoContainer.style.padding = '10px';
  40. avisoContainer.style.backgroundColor = 'red';
  41. avisoContainer.style.color = 'white';
  42. avisoContainer.style.fontSize = '16px';
  43. avisoContainer.style.fontWeight = 'bold';
  44. avisoContainer.style.textAlign = 'center';
  45. avisoContainer.style.zIndex = '9999';
  46. avisoContainer.style.display = 'flex';
  47. avisoContainer.style.alignItems = 'center';
  48. avisoContainer.style.justifyContent = 'center';
  49. avisoContainer.style.boxSizing = 'border-box';
  50.  
  51. // Cria o texto do aviso
  52. var spanTexto = document.createElement('span');
  53. spanTexto.textContent = avisoTexto;
  54. spanTexto.style.marginRight = '20px';
  55.  
  56. // Cria um botão para dispensar o aviso
  57. var botaoFechar = document.createElement('button');
  58. botaoFechar.textContent = botaoTexto;
  59. botaoFechar.style.backgroundColor = 'white';
  60. botaoFechar.style.color = 'red';
  61. botaoFechar.style.border = 'none';
  62. botaoFechar.style.padding = '5px 10px';
  63. botaoFechar.style.cursor = 'pointer';
  64. botaoFechar.style.fontWeight = 'bold';
  65.  
  66. botaoFechar.addEventListener('click', function() {
  67. // Ao clicar no botão, remove o aviso e restaura a margem do body
  68. avisoContainer.remove();
  69. document.body.style.marginTop = '';
  70. });
  71.  
  72. avisoContainer.appendChild(spanTexto);
  73. avisoContainer.appendChild(botaoFechar);
  74.  
  75. // Adiciona o aviso ao body
  76. document.body.appendChild(avisoContainer);
  77.  
  78. // Ajusta a margem superior do body de acordo com a altura do aviso, empurrando o conteúdo para baixo
  79. var avisoHeight = avisoContainer.offsetHeight;
  80. document.body.style.marginTop = avisoHeight + 'px';
  81. }
  82. })();