// ==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.8.2
// @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
// @grant window.close
// ==/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);
}
if (window !== top) document.addEventListener('click', function(ev){
if ( (ev.target.id=='fullscreen') && ev.ctrlKey) {
ev.stopPropagation();
let mId=ev.target.parentNode.querySelector('[href*="mailId"]');
if (mId && /mailId=([^&]+)/.exec(mId)) openW(RegExp.$1);
}
}, true);
}
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]');
openW(mId.attributes['data-oao-mailid'].value);
}
}
},
{capture: true} );
}
function openW(mId, TO) {
if (!TO) {
// ensure that it opens a popup and not a tab
setTimeout(function(){openW(mId,1);}, 0);
return;
}
let u=location.origin+location.pathname.replace(/search\/[^;]+;/,'folder;')+'?folderId='+mId+'#';
let w=Math.min( Math.max(1024, t.scrollWidth) ,1400);
window.open(u, mId ,'width='+w+',height=600');
}
});
function addSt(s,t) {
let st=document.createElement('style');
try{
(document.head || document.documentElement).appendChild(st);
st.innerText=s;
}catch(e){
if (t) document.addEventListener('DOMContentLoaded',function(){addSt(s);});
else setTimeout(function(){addSt(s,t);},0);
}
}
if (window.name && ( (window.name.length>=20) && (window.name.length<=24) ) && 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;
}
addSt('#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}');
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);
}
})();