GMX standalone window view

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

当前为 2021-07-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GMX standalone window view
  3. // @name:de GMX Standalone-Fensteransicht
  4. // @name:fr GMX email - fenêtre séparée
  5. // @namespace https://github.com/Procyon-b
  6. // @version 0.8
  7. // @description Set option to open email in standalone window (gmx / web.de)
  8. // @description:de Stellen Sie die Option so ein, dass E-Mails im eigenständigen Fenster geöffnet werden (gmx / web.de)
  9. // @description:fr Réactiver l'ouverture des emails dans une fenêtre popup (gmx / web.de)
  10. // @author Achernar
  11. // @match https://3c.gmx.net/mail/client/*
  12. // @match https://3c-bap.gmx.net/mail/client/*
  13. // @include https://3c-bs.gmx.tld/mail/client/*
  14. // @match https://3c.web.de/mail/client/*
  15. // @match https://3c-bap.web.de/mail/client/*
  16. // @run-at document-start
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. "use strict";
  23.  
  24. if ( /^\/mail\/client\/(home|folder|search)/.test(location.pathname) ) document.addEventListener('DOMContentLoaded', function(){
  25. const maxRetry=40;
  26. var e, r, retry=maxRetry;
  27.  
  28. function toggle(ev) {
  29. if (!e) return;
  30. var v=(typeof ev == 'object')? !phx.vars.enableStandaloneView : ev;
  31. e.checked=v;
  32. phx.vars.enableStandaloneView=v;
  33. try{
  34. GM_setValue('option', v);
  35. }catch(er){
  36. window.sessionStorage._popup_=v;
  37. }
  38. }
  39.  
  40. function addChk() {
  41. if (!(r=document.querySelector('.widget.menubar .button-container.left'))) {
  42. if (retry--) {
  43. setTimeout(addChk,10);
  44. }
  45. return;
  46. }
  47. retry=maxRetry;
  48. e=document.createElement('input');
  49. e.type='checkbox';
  50. e.id='standaloneView';
  51. e.title='Standalone view';
  52. e.style='margin-top: 6px;';
  53. r.appendChild(e);
  54. e.onclick=toggle;
  55. try{
  56. toggle(GM_getValue('option',true));
  57. }catch(er){
  58. let v=window.sessionStorage._popup_;
  59. if (v === undefined) v=true;
  60. else v=JSON.parse(v);
  61. toggle(v);
  62. }
  63. if (window !== top) document.addEventListener('click', function(ev){
  64. if ( (ev.target.id=='fullscreen') && ev.ctrlKey) {
  65. ev.stopPropagation();
  66. let mId=ev.target.parentNode.querySelector('[href*="mailId"]');
  67. if (mId && /mailId=([^&]+)/.exec(mId)) openW(RegExp.$1);
  68. }
  69. }, true);
  70. }
  71.  
  72. addChk();
  73.  
  74. const obs = new MutationObserver(function(mutL){
  75. for (let mut of mutL) {
  76. for (let el of mut.addedNodes) {
  77. if (el.classList && el.classList.contains('menubar')) {
  78. r=document.querySelector('.widget.menubar .button-container.left');
  79. addChk();
  80. return;
  81. }
  82. }
  83. }
  84. });
  85.  
  86. var t=document.querySelector('#panel-mail-table .panel-body form');
  87. if (t) {
  88. obs.observe(t, {subtree: false, childList: true, attributes: false} );
  89. t.addEventListener('click', function(ev){
  90. var tg=ev.target, li;
  91. if (tg.classList.contains('mail-open')
  92. || ( (tg.classList.contains('hoverMenu-icon') || tg.classList.contains('hover-menu-element') ) && ( (li=tg.closest('li')) && li.dataset.oaoHover=='open' )) ) {
  93. if (phx.vars.enableStandaloneView) {
  94. ev.stopPropagation();
  95. let mId=ev.target.closest('tr[data-oao-mailid]');
  96. openW(mId.attributes['data-oao-mailid'].value);
  97. }
  98. }
  99. },
  100. {capture: true} );
  101. }
  102.  
  103. function openW(mId, TO) {
  104. if (!TO) {
  105. // ensure that it opens a popup and not a tab
  106. setTimeout(function(){openW(mId,1);}, 0);
  107. return;
  108. }
  109. let u=location.origin+location.pathname.replace(/search\/[^;]+;/,'folder;')+'?folderId='+mId+'#';
  110. let w=Math.min( Math.max(1024, t.scrollWidth) ,1400);
  111. window.open(u, mId ,'width='+w+',height=600');
  112. }
  113.  
  114. });
  115.  
  116. function addSt(s,t) {
  117. let st=document.createElement('style');
  118. try{
  119. (document.head || document.documentElement).appendChild(st);
  120. st.innerText=s;
  121. }catch(e){
  122. if (t) document.addEventListener('DOMContentLoaded',function(){addSt(s);});
  123. else setTimeout(function(){addSt(s,t);},0);
  124. }
  125. }
  126.  
  127. if (window.name && (window.name.length==20) && window.name.startsWith('tmai') ) {
  128. let h='#action/mailDisplay/mailId/'+window.name+'/page/0';
  129.  
  130. window.onhashchange=function(){
  131. if (location.href.includes('#') && (location.hash != h) ) location.hash=h;
  132. }
  133.  
  134. if (location.href.includes('#')) {
  135. location.hash='#';
  136. location.hash=h;
  137. }
  138.  
  139. 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}');
  140.  
  141. function ready(){
  142. let c=-20;
  143. function setTitle() {
  144. let t=document.querySelector('.section-1 .mail-subject dd');
  145. if (t) {
  146. document.title=document.title.split('-')[0]+' - '+t.innerText;
  147. t=document.querySelector('#fullscreen');
  148. t && t.addEventListener('click', function(ev){
  149. window.close();
  150. }, {capture: true});
  151. }
  152. else c++ && setTimeout(setTitle, 100);
  153. }
  154. setTitle();
  155. document.body.addEventListener('click', function(ev){
  156. if (ev.target.id=='fullscreen') window.close();
  157. }, {capture: true});
  158.  
  159. document.body.addEventListener('keydown', function(ev){
  160. ev.stopPropagation();
  161. });
  162. }
  163.  
  164. if (document.readyState != 'loading') ready();
  165. else document.addEventListener('DOMContentLoaded', ready);
  166. }
  167.  
  168. })();