Google translate auto slide

Google translate auto slide on mouseover

  1. // ==UserScript==
  2. // @name Google translate auto slide
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description Google translate auto slide on mouseover
  6. // @author aseg
  7. // @match https://*
  8. // @match http://*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function()
  14. {
  15. 'use strict';
  16.  
  17. let
  18. ftcolor = "#4175b4",
  19. stripX = 510,
  20. stripY = 40,
  21. zcont = null,
  22. lklang = null,
  23. glink,
  24. btn1,
  25. btn1a,
  26. btn2,
  27. observer = new MutationObserver(mutations =>
  28. {
  29. for(let mutation of mutations)
  30. {
  31. // examine new nodes
  32. for(let node of mutation.addedNodes)
  33. {
  34. if(!(node instanceof HTMLElement))
  35. {
  36. continue;
  37. }
  38. if(document.getElementById(":0.container"))
  39. {
  40. zcont = document.getElementById(":0.container");
  41. glink = document.getElementById(":0.container").contentDocument.body.firstChild.firstChild.firstChild.firstChild.firstChild;
  42. lklang = document.getElementById(":0.container").contentDocument.body.firstChild.firstChild.firstChild.children[3].firstChild.firstChild.children[2].firstChild.firstChild;
  43. btn1 = document.getElementById(":0.container").contentDocument.body.firstChild.firstChild.firstChild.children[3].firstChild.firstChild.children[2].children[2].firstChild;
  44. btn1a = document.getElementById(":0.container").contentDocument.body.firstChild.firstChild.firstChild.children[3].firstChild.firstChild.firstChild.children[2].firstChild;
  45. btn2 = document.getElementById(":0.container").contentDocument.body.firstChild.firstChild.firstChild.children[5].firstChild;
  46. }
  47. }
  48. }
  49.  
  50. if(zcont)
  51. {
  52. zcont.contentDocument.body.style.backgroundImage = "none";
  53. zcont.contentDocument.body.style.backgroundColor = "#aaa";
  54. zcont.style.width = "36px";
  55. zcont.style.marginLeft = "-10px";
  56. zcont.style.borderRadius = "0px 8px 8px 0px";
  57.  
  58. glink.style.width = "30px";
  59. glink.firstChild.style.position = "absolute";
  60. glink.firstChild.style.top = "8px";
  61. glink.firstChild.style.clip = "rect(0px,17px,20px,0px)";
  62.  
  63. lklang.style.color = ftcolor;
  64. lklang.children[0].style.fontWeight = "bold";
  65. if(lklang.children[0].firstChild)
  66. {
  67. lklang.children[0].firstChild.style.color = ftcolor;
  68. }
  69.  
  70. if(btn1)
  71. {
  72. btn1.style.border = "none";
  73. btn1.firstChild.style.backgroundImage = "none";
  74. btn1.firstChild.style.border = "none";
  75. btn1.firstChild.firstChild.style.backgroundColor = "#ddd";
  76. btn1.firstChild.firstChild.style.borderRadius = "4px";
  77. btn1.firstChild.firstChild.style.color = ftcolor;
  78. }
  79.  
  80. if(btn1a)
  81. {
  82. btn1a.style.border = "none";
  83. btn1a.firstChild.style.backgroundImage = "none";
  84. btn1a.firstChild.style.border = "none";
  85. btn1a.firstChild.firstChild.style.backgroundColor = "#ddd";
  86. btn1a.firstChild.firstChild.style.borderRadius = "4px";
  87. btn1a.firstChild.firstChild.style.color = ftcolor;
  88. }
  89.  
  90. if(btn2)
  91. {
  92. btn2.style.border = "none";
  93. btn2.firstChild.style.background = "none";
  94. btn2.firstChild.style.border = "none";
  95. btn2.firstChild.firstChild.style.backgroundColor = "#ddd";
  96. btn2.firstChild.firstChild.style.borderRadius = "4px";
  97. btn2.firstChild.firstChild.style.color = ftcolor;
  98. }
  99.  
  100. zcont.onmouseover = function()
  101. {
  102. zcont.style.width = stripX + "px";
  103. zcont.style.marginLeft = "0px";
  104.  
  105. glink.style.width = "auto";
  106. glink.firstChild.style.position = "initial";
  107.  
  108. document.onmousemove = function(evt)
  109. {
  110. let evtDoc, doc, body, posX = 0, posY = 0;
  111.  
  112. evt = evt || window.evt;
  113.  
  114. if (evt.pageX == null && evt.clientX != null)
  115. {
  116. evtDoc = (evt.target && evt.target.ownerDocument) || document;
  117. doc = evtDoc.documentElement;
  118. body = evtDoc.body;
  119.  
  120. evt.pageX = evt.clientX +
  121. (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
  122. (doc && doc.clientLeft || body && body.clientLeft || 0);
  123.  
  124. evt.pageY = evt.clientY +
  125. (doc && doc.scrollTop || body && body.scrollTop || 0) -
  126. (doc && doc.clientTop || body && body.clientTop || 0 );
  127.  
  128. posX = evt.pageX;
  129. posY = evt.pageY;
  130. }
  131. else
  132. {
  133. posX = evt.pageX > evt.clientX ? evt.clientX : evt.pageX;
  134. posY = evt.pageY > evt.clientY ? evt.clientY : evt.pageY;
  135. }
  136.  
  137. if((posX > (stripX + 25)) || (posY > (stripY + 25)))
  138. {
  139. zcont.style.width = "36px";
  140. zcont.style.marginLeft = "-10px";
  141.  
  142. glink.style.width = "30px";
  143. glink.firstChild.style.position = "absolute";
  144.  
  145. document.onmousemove = function(){};
  146. }
  147. }
  148. }
  149. }
  150. });
  151.  
  152. observer.observe(document.body, {childList: true});
  153. })();