Gmail Filter From Email Button

Adds a "Filter All" button to the left of the received time on gmail emails. Clicking it does the same thing as the "filter messages like this" menu button.

  1. // ==UserScript==
  2. // @name Gmail Filter From Email Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Adds a "Filter All" button to the left of the received time on gmail emails. Clicking it does the same thing as the "filter messages like this" menu button.
  6. // @author Patrick Daniel
  7. // @match https://mail.google.com/mail/u/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant none
  10. // @require https://code.jquery.com/jquery-3.7.0.min.js
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. //'use strict';
  16. const NewEL = (tag, prop) => Object.assign(document.createElement(tag), prop);
  17.  
  18. document.addEventListener("mousemove", e => {
  19. //$(document).on("click mousedown mouseup focus blur keydown change", console.log("move"));
  20. //console.log($(".gH.bAk"));
  21.  
  22. if(document.querySelector(".gH.bAk span") && !document.querySelector(".gH.bAk span button")){
  23. var email = document.querySelector(".go")?.textContent?.replace('<', '')?.replace('>', '');
  24. var url = `https://mail.google.com/mail/u/1/#create-filter/from=${encodeURIComponent(email)}&sizeoperator=s_sl&sizeunit=s_smb`
  25. const EL_btn = NewEL("button", {
  26. textContent: "Filter All",
  27. onclick() {
  28. window.location.href = url;
  29. //window.open(url);
  30. //window.focus();
  31. //window.open(url, '_blank');
  32. },
  33. });
  34. $(document.querySelector(".gH.bAk span")).prepend(EL_btn);
  35. }
  36. if(document.querySelector(".gH.bAk span button").attributes.length == 0){
  37. document.querySelector(".gH.bAk span button").setAttribute('style', `border-radius: 10px; font-size: medium; margin: 0 5px; border: solid #cdcdcd 1px; background: #f1f1f1; padding: 3px 13px;`)
  38. }
  39. })
  40.  
  41. /*const observer = new MutationObserver(m => {
  42. console.log(m);
  43. console.log($)
  44. });
  45. observer.observe(document.body, {
  46. childList: true,
  47. subtree: true
  48. });*/
  49. })();