ProtonMail - remove forced signature

Removes the forced ProtonMail signature from the 'New message' textboxes

  1. // ==UserScript==
  2. // @name ProtonMail - remove forced signature
  3. // @namespace darkred
  4. // @version 2023.6.1
  5. // @description Removes the forced ProtonMail signature from the 'New message' textboxes
  6. // @author darkred
  7. // @license MIT
  8. // @include https://mail.protonmail.com/*
  9. // @include https://mail.proton.me/*
  10. // @include https://protonirockerxow.onion/*
  11. // @include https://protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion/*
  12. // @grant none
  13. // @require https://greasyfork.org/scripts/21927-arrive-js/code/arrivejs.js
  14. // @supportURL https://github.com/darkred/Userscripts/issues
  15. // @icon https://proton.me/favicons/favicon.ico
  16. // ==/UserScript==
  17.  
  18. const elementToWatch = 'iframe[title="Email composer"]';
  19. document.arrive(elementToWatch, function () {
  20. let iframe = this.contentDocument; // refers to the newly created element
  21.  
  22. const config = {
  23. childList: true,
  24. subtree: true
  25. };
  26.  
  27. const callback = function(mutationList, observer) {
  28. mutationList.forEach( (mutation) => {
  29. mutation.addedNodes.forEach( (node) => {
  30.  
  31. const refNode = 'protonmail_signature_block';
  32.  
  33. if (node.className === refNode) {
  34.  
  35. // DOM STRUCTURE:
  36. //
  37. // The 2 previous element siblings of the main signature element, '.protonmail_signature_block', both contain a <div> element with a <br> inside, i.e. <br> = <div> \ <br> ) :
  38. // <div> \ <br> | <div> \ <br> | .protonmail_signature_block
  39. //
  40. // The '.protonmail_signature_block' itself has either 3 or 2 <div> children which can be:
  41. //
  42. // (when user signature doesn't exist) the (empty) user signature , and the proton signature
  43. // .protonmail_signature_block-user.protonmail_signature_block-empty | .protonmail_signature_block-proton
  44. //
  45. // (when user signature exists) the user signature , 1 <div> \ <br> , and the signature itself
  46. // .protonmail_signature_block-user | <div> \ <br> | .protonmail_signature_block-proton
  47. //
  48. // The script's functionality is:
  49. // 1a. If user signature exists(=it's not empty), to remove the <div> \ <br> element before the last element ('.protonmail_signature_block-proton') ...
  50. // 1b. ... otherwise to remove the 2 <div> \ <br> elements before the main/reference '.protonmail_signature_block' element.
  51. // 2. To remove the last element ('.protonmail_signature_block-proton') itself.
  52. //
  53. // See DOM screenshots: https://imgur.com/a/VEI4nDQ
  54.  
  55.  
  56. const signatureProton = '.protonmail_signature_block-proton';
  57.  
  58.  
  59. if (!node.firstElementChild.classList.contains('protonmail_signature_block-empty')){
  60. node.querySelector(signatureProton).previousElementSibling.remove();
  61. } else {
  62. node.previousElementSibling.remove();
  63. node.previousElementSibling.remove();
  64. }
  65.  
  66. node.querySelector(signatureProton).remove();
  67.  
  68.  
  69. observer.disconnect();
  70. }
  71. });
  72.  
  73. });
  74. };
  75.  
  76. const observer = new MutationObserver(callback);
  77. observer.observe(iframe, config);
  78.  
  79. });