jcunews

Move GMailMessageViewToolbarButtonsToTopToolbar.user.js

Dec 1st, 2021 (edited)
1,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Move GMail Message View Toolbar Buttons To Top Toolbar
  3. // @namespace    https://greasyfork.org/en/users/85671-jcunews
  4. // @version      1.0.2
  5. // @license      AGPLv3
  6. // @author       jcunews
  7. // @description  https://www.reddit.com/r/userscripts/comments/r5m0rc/move_gmail_compose_buttons_to_top_of_conversation/
  8. // @match        https://mail.google.com/mail/*
  9. // @grant        none
  10. // @run-at       document-end
  11. // ==/UserScript==
  12.  
  13. (() => {
  14.   if (!document.body) return;
  15.   document.body.insertAdjacentHTML("beforeend", '<style> .cf.wS { display: none } </style>');
  16.   (new MutationObserver(
  17.     (btnTemplate, btns) => {
  18.       if ((btns = document.querySelectorAll(".amn > .ams")).length) {
  19.         if (
  20.           (btnTemplate = document.querySelector(".bzn .G-Ni:nth-child(2)")) &&
  21.           !document.querySelector(".btnShortcut")
  22.         ) {
  23.           btns.forEach((btn, i, newBtn) => {
  24.             newBtn = btnTemplate.cloneNode(true);
  25.             newBtn.dataset.btnindex = i;
  26.             newBtn.classList.add("btnShortcut");
  27.             newBtn.firstElementChild.removeAttribute("act");
  28.             newBtn.querySelector(".Bn").textContent = btn.textContent;
  29.             newBtn.addEventListener("click", function(ev) {
  30.               if (ev.button) return;
  31.               ev.stopImmediatePropagation();
  32.               ev.stopPropagation();
  33.               ev.preventDefault();
  34.               document.querySelectorAll(`.amn > .ams`)[this.dataset.btnindex].click();
  35.             }, true);
  36.             btnTemplate.parentNode.insertBefore(newBtn, btnTemplate);
  37.           });
  38.         }
  39.       } else document.querySelectorAll(".btnShortcut").forEach(e => e.remove());
  40.     }
  41.   )).observe(document.body, {childList: true, subtree: true});
  42. })();
  43.  
Add Comment
Please, Sign In to add comment