Greasy Fork

Greasy Fork is available in English.

Yahoo Mail Fixer

Various improvements/fixes for Yahoo Mail

当前为 2024-06-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Yahoo Mail Fixer
// @namespace    https://github.com/def00111
// @version      2.1
// @description  Various improvements/fixes for Yahoo Mail
// @author       def00111
// @match        https://mail.yahoo.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mail.yahoo.com
// @grant        GM_addStyle
// @noframes
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(() => {
  'use strict';

  // https://stackoverflow.com/a/4403189/8851282
  const minimizeData = content => {
    content = content.replace( /\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g, '' );
    // now all comments, newlines and tabs have been removed
    content = content.replace( / {2,}/g, ' ' );
    // now there are no more than single adjacent spaces left
    // now unnecessary: content = content.replace( /(\s)+\./g, ' .' );
    content = content.replace( / ([{:}]) /g, '$1' );
    content = content.replace( /([;,]) /g, '$1' );
    content = content.replace( / !/g, '!' );
    return content;
  };

  const cssText = minimizeData(`
    #Atom .iy_FF {
      overflow-x: auto !important;
    }
    #Atom :is(.H_3DVPV, .H_tQ, .H_1HK53Y, .H_ZIFfAM) {
      height: auto !important;
    }
    #Atom :is(.W_3v3uk, .W_3nHoX, .W_7iGr) {
      width: auto !important;
    }
    div[class*="bg_png_mask"]:empty {
      min-height: auto !important;
    }
    #basic-mail-app-container {
      & td[class="V_GM W_3n93F p_R o_h G_e"]:has(> a[href^="/b/settings/"]) + td > #norrin-optin {
        display: inline-block !important;
      }
      & table:has(#messageListContainer > div > #gam-iframe-basic-mail > #gpt-iframe) {
        height: 100vh;
      }
      & td:has(> div > #gam-iframe-basic-mail > #gpt-iframe),
      & #messageListContainer > div:has(> #gam-iframe-basic-mail > #gpt-iframe),
      & #norrin-optin {
        display: none !important;
      }
    }
    #mail-app-container {
      & section[role="banner"] > div[role="navigation"]:has(ul[data-test-id="tab-list"][data-test-count="0"]) {
        display: none !important;
      }
      & a[data-test-id="redirect-to-full-view-right-rail-btn"] {
        position: static !important;
      }
      & div[data-test-id="epoch-schedule-list-container"]:has(div[data-test-id="event-list-in-day-view-container"]) {
        overflow-y: auto !important;
      }
      & .message-view[data-test-expanded="true"] {
        overflow-x: auto;
      }
      & span[data-test-id="more-less-label"] {
        margin-right: 16px;
      }
      & div[data-test-id="mail-right-rail"]:has(div[data-test-id="gam-iframe"]:only-child) div:has(> div[data-test-id="gam-iframe"] > #gpt-iframe),
      & #mail-app-component div:has(> div[data-test-id="gam-iframe"] > #gpt-iframe),
      & div[data-test-id="mail-right-rail"] > div:has(> div[data-test-id="right-rail-hidead-btn"]),
      & span[data-test-id="settings-link-label"],
      & div:has(> article > a[data-test-id="bottom-sticky-pencil-ad"]),
      & div[data-test-id="contact-card"] + div[data-test-id="gam-iframe"] {
        display: none !important;
      }
      & #mail-app-component:has(div > div[data-test-id="gam-iframe"] > #gpt-iframe) div.H_74JI:has(> span > span.D_X) {
        height: 100% !important;
      }
      & div[data-test-id="mail-right-rail"]:has(div[data-test-id="gam-iframe"]:only-child) div[data-test-id="comms-properties-bar"] {
        border-left: 1px solid #e0e4e9;
        position: absolute;
        right: 0;
      }
      & #mail-app-component:has(+ div[data-test-id="mail-right-rail"] div[data-test-id="gam-iframe"]:only-child) div[data-test-id="search-header"] {
        box-sizing: border-box;
      }
      & div[data-test-id="search-header"] + div[data-test-id="mail-reader-toolbar"] > div[data-test-id="message-toolbar"] {
        max-width: none !important;
      }
      & #mail-app-component:has(+ div[data-test-id="mail-right-rail"] div[data-test-id="gam-iframe"]:only-child) div:is([data-test-id="message-toolbar"], [data-test-id="search-header"]),
      & #mail-app-component:has(+ div[data-test-id="mail-right-rail"] div[data-test-id="gam-iframe"]:only-child) > div > div > div > .compose-header div:is([data-test-id="compose-header-top-bar"], [data-test-id="container-from"]) {
        max-width: calc(100% - var(--ymf-comms-properties-bar-width));
      }
      @media only screen and (max-width: 1400px) {
        & div[data-test-id="message-toolbar"] button span.t_l {
          display: none !important;
        }
      }
    }
  `);

  if (typeof GM_addStyle == "function") {
    GM_addStyle(cssText);
  }

  const config = {
    childList: true,
    subtree: true
  };

  const sel = `div[data-test-id="mail-right-rail"]:has(div[data-test-id="gam-iframe"]:only-child) div[data-test-id="comms-properties-bar"]`;
  const sel2 = `div[data-test-id="mail-right-rail"] > div:has(> div[data-test-id="right-rail-hidead-btn"])`;

  let styleEl = null;
  const addStyle = el => {
    const style = window.getComputedStyle(el);
    if (!styleEl) {
      styleEl = document.createElement("style");
      document.head.append(styleEl);
    }
    styleEl.textContent = `:root { --ymf-comms-properties-bar-width: ${style.width}; }`;
  };

  document.addEventListener("DOMContentLoaded", () => {
    if (!observer1._disconnected) {
      observer1.disconnect();
      observer1._disconnected = true;
    }
    if (location.pathname.split("/", 2)[1] == "d") {
      const node = document.body.querySelector(sel);
      if (node) {
        const node2 = document.body.querySelector(sel2);
        if (node2) {
          const style = window.getComputedStyle(node2);
          if (style.display == "none") {
            addStyle(node);
          } else {
            resizeObserver.observe(node);
            // resizeObserver._observing = true;
          }
        }
      } else {
       observer2.observe(document.body, config);
      }
    }
  }, {
   once: true
  });

  window.onload = () => {
    if (resizeObserver._observing) {
      resizeObserver.disconnect();
      resizeObserver._observing = false;
    }
    if (location.pathname.split("/", 2)[1] == "d") {
      const node = document.body.querySelector(sel);
      if (node) {
        addStyle(node);
      }
    }
  };

  const resizeObserver = new ResizeObserver(([entry]) => {
    if (document.contains(entry.target)) {
      addStyle(entry.target);
    }
    resizeObserver.unobserve(entry.target);
    resizeObserver._observing = false;
  });
  resizeObserver._observing = false;

  const observer1 = new MutationObserver(() => {
    if (!document.body) return;
    const node = document.body.querySelector(sel);
    if (node) {
      observer1.disconnect();
      observer1._disconnected = true;
      resizeObserver.observe(node);
      resizeObserver._observing = true;
    }
  });
  observer1._disconnected = false;
  observer1.observe(document, config);

  const observer2 = new MutationObserver(() => {
    const node = document.body.querySelector(sel);
    if (node) {
       observer2.disconnect();
       addStyle(node);
    }
  });

  if (typeof GM_addStyle == "undefined") {
    const observer = new MutationObserver(() => {
      if (document.head) {
        const style = document.createElement("style");
        style.textContent = cssText;
        document.head.append(style);
        observer.disconnect();
      }
    });
    observer.observe(document, config);
  }
})();