GMX standalone window view

Set option to open email in standalone window (gmx / web.de)

目前為 2021-02-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GMX standalone window view
// @name:de      GMX Standalone-Fensteransicht
// @name:fr      GMX email - fenêtre séparée
// @namespace    https://github.com/Procyon-b
// @version      0.6.7
// @description  Set option to open email in standalone window (gmx / web.de)
// @description:de Stellen Sie die Option so ein, dass E-Mails im eigenständigen Fenster geöffnet werden (gmx / web.de)
// @description:fr Réactiver l'ouverture des emails dans une fenêtre popup (gmx / web.de)
// @author       Achernar
// @match        https://3c.gmx.net/mail/client/*
// @match        https://3c-bap.gmx.net/mail/client/*
// @include      https://3c-bs.gmx.tld/mail/client/*
// @match        https://3c.web.de/mail/client/*
// @match        https://3c-bap.web.de/mail/client/*
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

(function() {
"use strict";

if ( /^\/mail\/client\/(home|folder|search)/.test(location.pathname) ) document.addEventListener('DOMContentLoaded', function(){
  const maxRetry=40;
  var e, r, retry=maxRetry;

  function toggle(ev) {
    if (!e) return;
    var v=(typeof ev == 'object')? !phx.vars.enableStandaloneView : ev;
    e.checked=v;
    phx.vars.enableStandaloneView=v;
    try{
      GM_setValue('option', v);
    }catch(er){
      window.sessionStorage._popup_=v;
      }
  }

  function addChk() {
    if (!(r=document.querySelector('.widget.menubar .button-container.left'))) {
      if (retry--) {
        setTimeout(addChk,10);
        }
      return;
      }
    retry=maxRetry;
    e=document.createElement('input');
    e.type='checkbox';
    e.id='standaloneView';
    e.title='Standalone view';
    e.style='margin-top: 6px;';
    r.appendChild(e);
    e.onclick=toggle;
    try{
      toggle(GM_getValue('option',true));
    }catch(er){
      let v=window.sessionStorage._popup_;
      if (v === undefined) v=true;
      else v=JSON.parse(v);
      toggle(v);
      }
  }

  addChk();

  const obs = new MutationObserver(function(mutL){
    for (let mut of mutL) {
      for (let el of mut.addedNodes) {
        if (el.classList && el.classList.contains('menubar')) {
          r=document.querySelector('.widget.menubar .button-container.left');
          addChk();
          return;
          }
        }
      }
    });

  var t=document.querySelector('#panel-mail-table .panel-body form');
  if (t) {
    obs.observe(t, {subtree: false, childList: true, attributes: false} );
    t.addEventListener('click', function(ev){
      var tg=ev.target, li;
      if (tg.classList.contains('mail-open')
          || ( (tg.classList.contains('hoverMenu-icon') || tg.classList.contains('hover-menu-element') )  && ( (li=tg.closest('li')) && li.dataset.oaoHover=='open' )) ) {
        if (phx.vars.enableStandaloneView) {
          ev.stopPropagation();
          let mId=ev.target.closest('tr[data-oao-mailid]');
          let u=location.origin+location.pathname.replace(/search\/[^;]+;/,'folder;')+'?folderId='+mId.attributes['data-folderid'].value+'#';
          let w=Math.min( Math.max(1024, t.scrollWidth) ,1400);
          window.open(u, mId.attributes['data-oao-mailid'].value ,'width='+w+',height=600');
          }
        }
      },
      {capture: true} );
    }

});

if (window.name && (window.name.length==20) && window.name.startsWith('tmai') ) {
  let h='#action/mailDisplay/mailId/'+window.name+'/page/0';

  window.onhashchange=function(){
    if (location.href.includes('#') && (location.hash != h) ) location.hash=h;
    }

  if (location.href.includes('#')) {
    location.hash='#';
    location.hash=h;
    }

  let st=document.createElement('style');
  st.innerText='#navigation, #section-0, .section-1 .prev, .section-1 .next, .section-1 .menubar, .ad, div#mail-instant-reply, #maillist, #selectionCountMessage {display: none !important;} .section-1 {left: 0 !important;} .mail-display-wrapper {top: 0 !important;left: 0 !important;} html.can-have-sky .section-content {margin-right: 0 !important;} .section-1 > .section-container {bottom:0 !important;} div#system-message > div {display: block !important}';
  (document.head || document.documentElement).appendChild(st);

  function ready(){
    let c=-20;
    function setTitle() {
      let t=document.querySelector('.section-1 .mail-subject dd');
      if (t) {
        document.title=document.title.split('-')[0]+' - '+t.innerText;
        t=document.querySelector('#fullscreen');
        t && t.addEventListener('click', function(ev){
          window.close();
          }, {capture: true});
        }
      else c++ && setTimeout(setTitle, 100);
      }
    setTitle();
    document.body.addEventListener('click', function(ev){
      if (ev.target.id=='fullscreen') window.close();
      }, {capture: true});

    document.body.addEventListener('keydown', function(ev){
      ev.stopPropagation();
      });
    }

  if (document.readyState != 'loading') ready();
  else document.addEventListener('DOMContentLoaded', ready);
  }

})();