Safari Extension to change the logo of Google's home and search page.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
12 KiB

  1. var MGMLogoURLs;
  2. var MGMLogosText;
  3. var MGMCustomHome;
  4. var MGMCustomSearch;
  5. var MGMLoadedInfo = false;
  6. console.log("hello");
  7. function fourthJuly10(element) {
  8. var parent = element.parentNode;
  9. parent.removeChild(element);
  10. var style = document.createElement("style");
  11. style.innerHTML = "#doodle{width:530px;height:175px;background:url(http://www.google.com/logos/goldberg10-hp-bg.png) top left no-repeat;position:relative;cursor:pointer;}#doodle div{position:absolute;background-image:url(http://www.google.com/logos/goldberg10-hp-sprite.png);}";
  12. parent.insertBefore(style,null);
  13. var doodle = document.createElement("div");
  14. doodle.id = "doodle";
  15. doodle.setAttribute("onclick", "google.July4FW.goldberg(event)");
  16. parent.insertBefore(doodle,null);
  17. var script = document.createElement("script");
  18. script.innerHTML = "(function(){var d=true; try{if(!google.July4FW)google.July4FW={};var f,i,j,k,l,m,n=0,o=false,p=[],q,r=[[0],[87,114,34,40],[92,49,82,105],[92,49,82,107],[93,47,81,114],[100,136,40,26],[100,136,40,26],[144,68,37,61],[153,56,37,49],[158,42,42,50],[168,27,39,53],[179,14,47,54],[183,0,47,68],[194,0,105,109],[204,0,105,122],[217,0,93,123],[222,45,89,80],[220,50,91,70],[214,55,84,53],[251,80,45,29],[251,81,41,29],[252,81,37,29],[252,89,11,21],[252,89,11,21],[251,82,61,38],[251,82,61,42],[251,84,79,45],[272,86,37,32],[280,90,36, 34],[288,95,35,33],[294,100,38,31],[303,102,38,34],[313,107,37,34],[319,7,88,158],[312,7,95,157],[312,8,95,155],[312,8,142,159],[312,8,144,163],[314,12,155,161],[307,6,164,168],[304,0,167,174],[302,0,169,174],[302,19,163,156],[316,19,149,156],[323,19,142,156],[319,19,146,156],[400,19,65,107],[400,19,65,98],[400,19,65,98],[417,82,42,64],[419,83,42,63],[419,83,44,64],[420,85,46,59],[0],[0],[0],[463,79,15,28],[463,76,16,31],[464,74,15,30],[464,71,16,31],[465,68,15,31],[465,65,16,31],[466,63,15,30],[466, 60,16,31],[467,57,16,31],[468,56,15,29],[461,56,22,72],[461,55,22,73],[464,54,19,77],[467,54,16,77],[468,54,15,77],[0],[470,88,25,66],[0],[469,97,24,59],[466,102,26,54],[466,64,36,92],[476,19,34,113],[484,0,28,87],[492,0,20,41]],s=r.length,t,u,v=-1,w=-1,x;google.July4FW.init=function(){if(!x&&window.location.href.indexOf(\"#\")==-1){x=d;f=document.createElement(\"img\");i=document.createElement(\"img\");f.src=\"/logos/goldberg10-hp-stars.png\";i.src=\"/logos/goldberg10-hp-sprite.png\";if(j=document.getElementById(\"doodle\")){y(); window.setTimeout(function(){document.f&&document.f.q&&document.f.q.value==\"\"&&j&&j.childNodes.length<= 2&&google.July4FW.goldberg()},5E3);google.j&&google.j.en&&z()}else o=d}};var z=function(){if(!google.rein||!google.dstr)window.setTimeout(z,50);else if(!google.July4FW.jesr){google.July4FW.jesr=d;google.rein&&google.rein.push(google.July4FW.init);google.dstr&&google.dstr.push(function(){o=d;google.unlisten(document,\"click\",A)})}},A=function(){o||(o=d)},D=function(){google.listen(document,\"click\", A);if(k=document.getElementById(\"lga\")){q=google.style.getPageOffsetTop(k)+k.offsetHeight+10;B(2E3);C()}},B=function(b){if(!(o||b<= 0)){var e=google.style.getPageOffsetLeft(j)+50,a=j.offsetWidth-100,h=e+a/2,c=document.createElement(\"div\"),g=document.createElement(\"img\");g.src=f.src;c.appendChild(g);c.src=f.src;c.style.zIndex=12+s+p.length;c.style.position=\"absolute\";c.style.overflow=\"hidden\";c.style.top=\"25px\";c.top=25;c.height=c.width=g.height=10;g.width=30;g.style.position=\"absolute\";g.style.top= 0;g.starColor=n;g.style.left=0-c.width*n+\"px\";if(++n>2)n=0;c.left=e+Math.floor(Math.random()*(a+1));c.style.left=c.left-c.width/2+\"px\";c.vy=1;c.vx=3*(c.left-h)/j.offsetWidth;p.push(c);k.appendChild(c);window.setTimeout(function(){B(b-30)},30)}},C=function(){var b=p;p=[];for(var e=0;e< b.length;++e){var a=b[e],h=a.firstChild;a.top+=a.vy;a.vy+=0.6;a.left+=a.vx;if(a.height< 30){a.height+=1;a.width+=1}a.style.left=a.left-a.width/2+\"px\";a.style.top=a.top+\"px\";if(a.top+30>=q||a.left+30>=(typeof window.innerWidth== \"number\"?window.innerWidth:document.documentElement&&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth)||a.left< 0)a.parentNode.removeChild(a);else{if(a.top+30>q-50&&a.height>5){a.height-=5;a.width-=5}p.push(a)}a.style.height=a.height+\"px\";a.style.width=a.width+\"px\";h.height=a.height;h.width=3*a.width;h.style.left=0-a.width*h.starColor+\"px\"}if(p.length>0)window.setTimeout(C,20);else o=d},E=function(b,e,a,h,c,g){b.style.left=e+\"px\";b.style.top=a+\"px\"; b.style.width=h+\"px\";b.style.height=c+\"px\";b.style.zIndex=g},y=function(){for(;j.childNodes.length>0;)j.removeChild(j.firstChild);m=document.createElement(\"div\");E(m,\"0\",\"0\",\"85\",\"135\",10);m.style.backgroundPosition=\"-1620px -34px\";j.appendChild(m);l=document.createElement(\"div\");E(l,\"15\",\"50\",\"70\",\"70\",11);l.style.backgroundPosition=\"-3682px -104px\";l.opacity=100;j.appendChild(l);F(0)},F=function(b){if(b>
  19. parent.insertBefore(script,null);
  20. }
  21. function handleHomeBeforeLoad(event) {
  22. var element = event.target;
  23. if (!MGMLoadedInfo) {
  24. MGMLogoURLs = safari.self.tab.canLoad(event, {name: "getLogos", data: ""});
  25. MGMLogosText = safari.self.tab.canLoad(event, {name: "getLogosText", data: ""});
  26. MGMCustomHome = safari.self.tab.canLoad(event, {name: "getSetting", data: "homeLogo"});
  27. MGMCustomSearch = safari.self.tab.canLoad(event, {name: "getSetting", data: "searchLogo"});
  28. MGMLoadedInfo = true;
  29. }
  30. if (element.id=="logo") {
  31. if (element.getAttribute("MGMChanged"))
  32. return;
  33. element.removeAttribute("onload", 0);
  34. if (MGMCustomHome==null || MGMCustomHome=="") {
  35. var logoNum = Math.floor(Math.random()*MGMLogoURLs.length);
  36. var logo = MGMLogoURLs[logoNum];
  37. element.src = logo;
  38. var parent = element.parentNode;
  39. parent.removeChild(parent.children[1]);
  40. parent.removeChild(parent.children[1]);
  41. if (logoNum==757) {
  42. element.setAttribute("onclick","(function(){var f=document.getElementById('fall'),h=0,v=1,y='63px';window.newton&&clearTimeout(window.newton);if(f.style.bottom==y){window.newton=setInterval(function(){if(f){var r=parseInt(f.style.right)+h,b=parseInt(f.style.bottom)-v;f.style.right=r+'px';f.style.bottom=b+'px';if(b>-160){v+=2}else{if(v>9){h=v*0.1;v*=-0.3}else{h=v=0;}}}},25)}else{f.style.bottom=y;f.style.right='244px';}})()");
  43. var apple = document.createElement("img");
  44. apple.id = "fall";
  45. apple.src = "http://www.google.com/logos/newton10-apple.png";
  46. apple.style.position = "relative"
  47. apple.style.bottom = "63px"
  48. apple.style.right = "244px";
  49. parent.insertBefore(apple,null);
  50. } else if (logoNum==909) {
  51. fourthJuly10(element);
  52. }
  53. var title = document.createElement("div");
  54. title.innerHTML = MGMLogosText[logoNum];
  55. title.style.fontSize = "10px";
  56. parent.insertBefore(title,null);
  57. } else {
  58. element.src = MGMCustomHome;
  59. }
  60. element.removeAttribute("width", 0);
  61. element.removeAttribute("height", 0);
  62. element.setAttribute("MGMChanged", true);
  63. } else if (element.src=="https://www.google.com/images/logos/ssl_logo_lg.gif") {
  64. if (element.getAttribute("MGMChanged"))
  65. return;
  66. if (MGMCustomHome==null || MGMCustomHome=="") {
  67. var logoNum = Math.floor(Math.random()*MGMLogoURLs.length);
  68. var logo = MGMLogoURLs[logoNum];
  69. element.src = logo;
  70. var parent = element.parentNode;
  71. parent.removeChild(parent.children[1]);
  72. parent.removeChild(parent.children[1]);
  73. if (logoNum==757) {
  74. element.setAttribute("onclick","(function(){var f=document.getElementById('fall'),h=0,v=1,y='48px';window.newton&&clearTimeout(window.newton);if(f.style.bottom==y){window.newton=setInterval(function(){if(f){var r=parseInt(f.style.right)+h,b=parseInt(f.style.bottom)-v;f.style.right=r+'px';f.style.bottom=b+'px';if(b>-170){v+=2}else{if(v>9){h=v*0.1;v*=-0.3}else{h=v=0;}}}},25)}else{f.style.bottom=y;f.style.right='244px';}})()");
  75. var apple = document.createElement("img");
  76. apple.id = "fall";
  77. apple.src = "http://www.google.com/logos/newton10-apple.png";
  78. apple.style.position = "relative"
  79. apple.style.bottom = "48px"
  80. apple.style.right = "244px";
  81. console.log(element.parentNode);
  82. element.parentNode.insertBefore(apple,null);
  83. } else if (logoNum==909) {
  84. fourthJuly10(element);
  85. }
  86. var title = document.createElement("div");
  87. title.innerHTML = MGMLogosText[logoNum];
  88. title.style.fontSize = "10px";
  89. parent.insertBefore(title,null);
  90. } else {
  91. element.src = MGMCustomHome;
  92. }
  93. element.removeAttribute("width", 0);
  94. element.removeAttribute("height", 0);
  95. element.setAttribute("MGMChanged", true);
  96. }
  97. }
  98. function handleSearchBeforeLoad(event) {
  99. var element = event.target;
  100. if (!MGMLoadedInfo) {
  101. MGMLogoURLs = safari.self.tab.canLoad(event, {name: "getLogos", data: ""});
  102. MGMLogosText = safari.self.tab.canLoad(event, {name: "getLogosText", data: ""});
  103. MGMCustomHome = safari.self.tab.canLoad(event, {name: "getSetting", data: "homeLogo"});
  104. MGMCustomSearch = safari.self.tab.canLoad(event, {name: "getSetting", data: "searchLogo"});
  105. MGMLoadedInfo = true;
  106. }
  107. if (element.src.match("nav_logo") && element.width==167) {
  108. if (element.getAttribute("MGMChanged"))
  109. return;
  110. var parent = element.parentNode;
  111. if (MGMCustomSearch==null || MGMCustomSearch=="") {
  112. var logoNum = Math.floor(Math.random()*MGMLogoURLs.length);
  113. element.src = MGMLogoURLs[logoNum];
  114. } else {
  115. element.src = MGMCustomSearch;
  116. }
  117. parent.innerHTML = "";
  118. parent.insertBefore(element,null);
  119. element.style.top = "0px";
  120. element.width = "137";
  121. element.height = "49";
  122. element.setAttribute("MGMChanged", true);
  123. } else if (element.src.match("ssl_logo_beta")) {
  124. if (element.getAttribute("MGMChanged"))
  125. return;
  126. if (MGMCustomSearch==null || MGMCustomSearch=="") {
  127. var logoNum = Math.floor(Math.random()*MGMLogoURLs.length);
  128. element.src = MGMLogoURLs[logoNum];
  129. } else {
  130. element.src = MGMCustomSearch;
  131. }
  132. element.width = "137";
  133. element.height = "49";
  134. element.setAttribute("MGMChanged", true);
  135. }
  136. }
  137. function setupCom() {
  138. if (window.location.pathname=="/") {
  139. document.addEventListener("beforeload", handleHomeBeforeLoad, true);
  140. } else {
  141. var query = window.location.search;
  142. query = query.substr(1, query.length-1);
  143. query = query.split("&");
  144. for (i=0; i<query.length; i++) {
  145. var pram = query[i].split("=");
  146. if (pram[0]=="q") {
  147. document.addEventListener("beforeload", handleSearchBeforeLoad, true);
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. function setupDiv() {
  154. var lga = document.getElementById("lga");
  155. lga.innerHTML = "lga";
  156. var element = document.createElement("img");
  157. element.border = 0;
  158. if (MGMCustomHome==null || MGMCustomHome=="") {
  159. var logoNum = Math.floor(Math.random()*MGMLogoURLs.length);
  160. var logo = MGMLogoURLs[logoNum];
  161. element.src = logo;
  162. var parent = element.parentNode;
  163. parent.removeChild(parent.children[1]);
  164. parent.removeChild(parent.children[1]);
  165. if (logoNum==757) {
  166. element.setAttribute("onclick","(function(){var f=document.getElementById('fall'),h=0,v=1,y='63px';window.newton&&clearTimeout(window.newton);if(f.style.bottom==y){window.newton=setInterval(function(){if(f){var r=parseInt(f.style.right)+h,b=parseInt(f.style.bottom)-v;f.style.right=r+'px';f.style.bottom=b+'px';if(b>-160){v+=2}else{if(v>9){h=v*0.1;v*=-0.3}else{h=v=0;}}}},25)}else{f.style.bottom=y;f.style.right='244px';}})()");
  167. var apple = document.createElement("img");
  168. apple.id = "fall";
  169. apple.src = "http://www.google.com/logos/newton10-apple.png";
  170. apple.style.position = "relative"
  171. apple.style.bottom = "63px"
  172. apple.style.right = "244px";
  173. parent.insertBefore(apple,null);
  174. } else if (logoNum==909) {
  175. fourthJuly10(element);
  176. }
  177. var title = document.createElement("div");
  178. title.innerHTML = MGMLogosText[logoNum];
  179. title.style.fontSize = "10px";
  180. parent.insertBefore(title,null);
  181. } else {
  182. element.src = MGMCustomHome;
  183. }
  184. }
  185. var host = window.location.host;
  186. console.log(host);
  187. if (host.match(".com")){
  188. console.log("setup com");
  189. setupCom();
  190. } else if (host.match(".be")) {
  191. console.log("setup be");
  192. setupDiv();
  193. }