exmail.qq.com_contacts_plus

通讯录增强,在邮件列表展示头像(需要先进通讯录收集头像)

  1. // ==UserScript==
  2. // @name exmail.qq.com_contacts_plus
  3. // @description 通讯录增强,在邮件列表展示头像(需要先进通讯录收集头像)
  4. // @version 1.5
  5. // @namespace https://wanyaxing.com/blog/20190123201508.html
  6. // @author wyx@wanyaxing.com
  7. // @include https://exmail.qq.com/cgi-bin/mail_list*
  8. // @include https://exmail.qq.com/cgi-bin/laddr_list*
  9. // @include https://exmail.qq.com/cgi-bin/readmail*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // ==/UserScript==
  13.  
  14.  
  15. function setCheckout(check,fuc,time){
  16. if (check())
  17. {
  18. fuc();
  19. }
  20. else
  21. {
  22. setTimeout(function(){
  23. setCheckout(check,fuc,time);
  24. },time);
  25. }
  26. }
  27.  
  28. function bindImageEvent(imgNode)
  29. {
  30. imgNode.onmouseover = function(event){
  31. hintImageShow(this,event);
  32. }
  33. imgNode.onmouseout = function(event){
  34. hintImageHide(this,event);
  35. }
  36. imgNode.onclick = function(event){
  37. event.preventDefault();
  38. event.stopPropagation();
  39. return false;
  40. }
  41. }
  42.  
  43. function hintImageShow(imgNode,event)
  44. {
  45. console.log(imgNode,event);
  46. var hintNode = document.getElementById('hint_with_mouse');
  47. if (!hintNode)
  48. {
  49. hintNode = document.createElement('div');
  50. hintNode.setAttribute('id','hint_with_mouse');
  51. hintNode.style.cssText = 'position:absolute;z-index:999999;';
  52. document.body.append(hintNode);
  53. }
  54. hintNode.innerHTML='<img src="'+imgNode.getAttribute('src')+'"/>';
  55. hintNode.style.left = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft + 6 +'px';
  56. hintNode.style.top = event.clientY + document.body.scrollTop + document.documentElement.scrollTop + 9 +'px';
  57. hintNode.style.display="block";
  58. }
  59.  
  60. function hintImageHide(imgNode,event)
  61. {
  62. var hintNode = document.getElementById('hint_with_mouse');
  63. if (hintNode)
  64. {
  65. hintNode.style.display="none";
  66. }
  67. }
  68.  
  69. // 遍历存储头像
  70. if (document.querySelector('.contacts #list')) {
  71. var needCheckLis;
  72. function checkPhotos()
  73. {
  74. needCheckLis = [];
  75. document.querySelectorAll('#list li[data-id]').forEach(function(liNode){
  76. var email = liNode.querySelector('.email').innerText;
  77. email = email.replace(/;.*/,'');
  78. var photo = GM_getValue(email + '_photo');
  79. if (!photo || liNode.className=='item_current')
  80. {
  81. needCheckLis.push(liNode);
  82. } else {
  83. var imgNode = document.createElement('img');
  84. imgNode.src=photo;
  85. imgNode.style.cssText = ' height: 100%;position: absolute;left: 50px;';
  86. var nameNode = liNode.querySelector('.name');
  87. nameNode.style.cssText = 'position:relative;';
  88. nameNode.appendChild(imgNode);
  89. }
  90. });
  91. }
  92.  
  93. function getBase64Image(img) {
  94. var canvas = document.createElement("canvas");
  95. canvas.width = img.width;
  96. canvas.height = img.height;
  97. var ctx = canvas.getContext("2d");
  98. ctx.drawImage(img, 0, 0, img.width, img.height);
  99. var dataURL = canvas.toDataURL("image/png");
  100. return dataURL; // return dataURL.replace("data:image/png;base64,", "");
  101. }
  102.  
  103. function checkEmailIds()
  104. {
  105. if (needCheckLis.length>0) {
  106. var liNode = needCheckLis.shift();
  107. var email = liNode.querySelector('.email').innerText;
  108. liNode.click();
  109. setCheckout(function(){
  110. return document.querySelector('.detail_mail') && email.indexOf(document.querySelector('.detail_mail').innerText)>=0;
  111. },function(){
  112. var imgNode = document.querySelector('.avatar_img');
  113. if (imgNode && imgNode.getAttribute('src').indexOf('default')<0) {
  114. var dataURL = getBase64Image(imgNode);
  115. document.querySelectorAll('.detail_mail').forEach(function(child){
  116. var detail_mail = child.innerText;
  117. GM_setValue(detail_mail + '_photo',dataURL);
  118. });
  119. }
  120. var nameNode = document.querySelector('.info_name');
  121. if (nameNode) {
  122. document.querySelectorAll('.detail_mail').forEach(function(child){
  123. var detail_mail = child.innerText;
  124. GM_setValue(detail_mail + '_name',nameNode.innerText);
  125. });
  126. }
  127. // console.log(imgNode.getAttribute('src'),GM_getValue(email + '_photo'));
  128. checkEmailIds();
  129. },1000);
  130. }
  131. }
  132.  
  133. var aNode = document.createElement('a');
  134. aNode.innerHTML = '遍历刷新头像';
  135. aNode.className="button_gray ft_topbar_btn";
  136. aNode.onclick = function(){
  137. checkPhotos();
  138. checkEmailIds();
  139. }
  140. document.querySelector('#bar .tool').appendChild(aNode);
  141.  
  142. checkPhotos();
  143. }
  144.  
  145.  
  146. // 邮件列表简情处理
  147. if (document.getElementById('frm')) {
  148.  
  149. function checkEmailAvatar() {
  150. document.getElementById('frm').querySelectorAll('.toarea>table').forEach(function(child){
  151. var formNode = child.querySelector('.tl');
  152.  
  153. var email = formNode.getAttribute('title');
  154. if (formNode.innerText.indexOf('@')!==false){
  155. var name = GM_getValue(email + '_name');
  156. if (name) {
  157. formNode.querySelector('nobr').innerHTML = name;
  158. }
  159. }
  160. var photo = GM_getValue(email + '_photo');
  161. if (photo) {
  162. var imgNode = document.createElement('img');
  163. imgNode.src=photo;
  164. imgNode.style.cssText = 'height: 18px;right: 60px;position:absolute;z-index:99999;';
  165. formNode.style.cssText = 'position:relative;';
  166. bindImageEvent(imgNode);
  167. formNode.appendChild(imgNode);
  168. }
  169. });
  170. }
  171.  
  172. setTimeout(function(){
  173. checkEmailAvatar();
  174. },1);
  175. }
  176.  
  177.  
  178. //邮件详情显示头像
  179. if (document.getElementById("mainmail"))
  180. {
  181. document.querySelectorAll('span[e]').forEach(function(itemNode){
  182. var email = itemNode.getAttribute('e');
  183. var photo = GM_getValue(email + '_photo');
  184. if (photo) {
  185. var imgNode = document.createElement('img');
  186. imgNode.src=photo;
  187. imgNode.style.cssText = 'height: 15px;position: relative;top: 2px;';
  188. bindImageEvent(imgNode);
  189. itemNode.insertBefore(imgNode,itemNode.firstChild);
  190. }
  191. });
  192. document.querySelectorAll('#contentDiv a').forEach(function(itemNode){
  193. var href = itemNode.getAttribute('href');
  194. if (href && href.indexOf('mailto:')==0){
  195. var email = href.replace('mailto:','');
  196. var name = GM_getValue(email + '_name');
  197. if (name) {
  198. itemNode.innerHTML = '<span>'+name + '&lt;' + email + '&gt;'+'</span>';
  199. }
  200. var photo = GM_getValue(email + '_photo');
  201. if (photo) {
  202. var imgNode = document.createElement('img');
  203. imgNode.src=photo;
  204. imgNode.style.cssText = 'height: 15px;position: relative;top: 2px;';
  205. bindImageEvent(imgNode);
  206. if (itemNode.firstChild){
  207. itemNode.insertBefore(imgNode,itemNode.firstChild);
  208. } else {
  209. itemNode.append(imgNode);
  210. }
  211. }
  212. }
  213. });
  214.  
  215. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址