Google Improved

Makes Google bearable

  1. // ==UserScript==
  2. // @name Google Improved
  3. // @namespace Alfur
  4. // @description Makes Google bearable
  5. // @include https://encrypted.google.com/?*
  6. // @include *://www.google.*/?*
  7. // @include *://google.*/?*
  8. // @include https://encrypted.google.com/#*
  9. // @include *://www.google.*/#*
  10. // @include *://google.*/#*
  11. // @include https://encrypted.google.com/
  12. // @include *://www.google.*/
  13. // @include *://google.*/
  14. // @include https://encrypted.google.com/webhp*
  15. // @include *://www.google.*/webhp*
  16. // @include *://google.*/webhp*
  17. // @include https://encrypted.google.com/imghp*
  18. // @include *://www.google.*/imghp*
  19. // @include *://google.*/imghp*
  20. // @include https://encrypted.google.com/search*
  21. // @include *://www.google.*/search*
  22. // @include *://google.*/search*
  23. // @version 1.0.10
  24. // @grant GM_getValue
  25. // @grant GM_setValue
  26. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  27. // @icon https://raw.githubusercontent.com/AlphaDelta/Google-Improved/master/icon.png
  28. // ==/UserScript==
  29.  
  30. var nuke = GM_getValue("nuke", true);
  31. var rownum = GM_getValue("rownum", true);
  32. var antigateway = GM_getValue("antigateway", true);
  33. var cleansearch = GM_getValue("cleansearch", true);
  34. var removenonsearch = GM_getValue("removenonsearch", true);
  35.  
  36. var x;
  37.  
  38. var del;
  39.  
  40. var doneappbar = false, donenavbar = false, donesearchbar = false, hit = 0, chrome = navigator.userAgent.toLowerCase().indexOf('chrome') !== -1;
  41. function DoMod() {
  42. hit++;
  43. if(cleansearch) {
  44. if(!doneappbar) {
  45. var appbar = $("#appbar");
  46. if(appbar.length > 0) {
  47. appbar.after("<br />");
  48. appbar.remove();
  49. doneappbar = true;
  50. }
  51. }
  52. if(!donenavbar) {
  53. var navbar = $("#hdtb-msb");
  54. if(navbar.length > 0) {
  55. var imagesi = false, webi = null;
  56. $(".hdtb-mitem", navbar).each(function() {
  57. var item = $(this);
  58. if(item.text() === "Web") webi = item;
  59. else if(item.text() === "Images") imagesi = true;
  60. else item.remove();
  61. });
  62. $("#hdtb-tls", navbar).remove();
  63. if(!imagesi && webi.length > 0) {
  64. $("#hdtb-more-mn .hdtb-mitem").each(function() {
  65. var item = $(this);
  66. if(item.text() === "Images") {
  67. webi.after(item[0].outerHTML);
  68. return false;
  69. }
  70. });
  71. }
  72. $("#hdtb-more", navbar).remove();
  73. //donenavbar = true;
  74. }
  75. }
  76. /*if(!donesearchbar) {
  77. var searchbar = $("#sfdiv");
  78. if(searchbar.length > 0) {
  79. $(".sfsbc").remove();
  80. searchbar.css("border-right-width", "1px").css("border-right-color", "inherit");
  81. donesearchbar = true;
  82. }
  83. }*/
  84. if(removenonsearch) {
  85. var inthenews = $(".mnr-c");
  86. if(inthenews.length > 0) {
  87. inthenews.each(function() {
  88. var parent = $(inthenews.parent()[0]);
  89. if(parent.is("div")) {
  90. if(parent.prev().is("hr")) parent.prev().remove();
  91. if(parent.next().is("hr")) parent.next().remove();
  92. parent.remove();
  93. } else inthenews.remove();
  94. });
  95. }
  96. }
  97. $("#footcnt").remove();
  98. $("#extrares").remove();
  99. }
  100. $('#rso .srg .g:not(.gi-parsed), #rso > .g:not(.gi-parsed)').each(function (index) {
  101. var t = $(this);
  102. t.addClass('gi-parsed');
  103. t.css('position', 'relative');
  104. if(rownum) t.prepend('<div style="color: #AAA; position: absolute; height: 100%; width: 20px; margin-left: -25px; margin-top: 2px; text-align: right;">' + (index + 1) + '</div>');
  105. if(antigateway) t.find(".rc > .r > a").first().removeAttr("onmousedown");
  106. });
  107. }
  108.  
  109. function DoLines() {
  110. clearTimeout(del);
  111. del = setTimeout(DoMod, 200);
  112. }
  113.  
  114. var settings = false;
  115. var viewport = null;
  116. function ToggleSettings() {
  117. settings = !settings;
  118. if(viewport === null) viewport = $("#viewport");
  119. if(settings) {
  120. $("body").prepend("\
  121. <div id=\"gi-settings\" style=\"position: fixed; margin: 5px; padding: 5px; background: #F2F2F2; border: 1px solid #888; font-size: 11px; color: #222; z-index: 1000;\">\
  122. <input id=\"gi-nuke\" type=\"checkbox\" " + (nuke ? "checked" : "") + "/><label for=\"gi-nuke\">Nuke <span style=\"color: #888;\">(Nuke the front page to a more minimal interface, no bullshit fogging up your screen)</span></label>\
  123. <br /><input id=\"gi-rownum\" type=\"checkbox\" " + (rownum ? "checked" : "") + "/><label for=\"gi-rownum\">Row numbers <span style=\"color: #888;\">(Adds row numbers to search results)</span></label>\
  124. <br /><input id=\"gi-antigateway\" type=\"checkbox\" " + (antigateway ? "checked" : "") + "/><label for=\"gi-antigateway\">Anti-gateway <span style=\"color: #888;\">(Prevents Google from jacking your link clicks and forcing them to go through their redirect gateway)</span></label>\
  125. <br /><input id=\"gi-cleansearch\" type=\"checkbox\" " + (cleansearch ? "checked" : "") + "/><label for=\"gi-cleansearch\">Clean search <span style=\"color: #888;\">(Removes clutter from the search page)</span></label>\
  126. <br /><input id=\"gi-removenonsearch\" type=\"checkbox\" style=\"margin-left: 25px;\" " + (removenonsearch ? "checked" : "") + (cleansearch ? "" : " disabled=\"disabled\"") + "/><label for=\"gi-removenonsearch\">Remove non-search items <span style=\"color: #888;\">(Removes non-search items such as 'In the news')</span></label>\
  127. <br /><div style=\"margin-top: 5px; font-style: italic; color: #555;\">Page must be refreshed in order for new settings to take effect</div>\
  128. </div>");
  129. $("#gi-nuke").change(function() { nuke = this.checked; GM_setValue("nuke", this.checked); });
  130. $("#gi-rownum").change(function() { rownum = this.checked; GM_setValue("rownum", this.checked); });
  131. $("#gi-antigateway").change(function() { antigateway = this.checked; GM_setValue("antigateway", this.checked); });
  132. $("#gi-cleansearch").change(function() {
  133. cleansearch = this.checked;
  134. GM_setValue("cleansearch", this.checked);
  135. if(!this.checked)
  136. $("#gi-removenonsearch").attr("disabled", "disabled");
  137. else
  138. $("#gi-removenonsearch").removeAttr("disabled");
  139. });
  140. $("#gi-removenonsearch").change(function() { removenonsearch = this.checked; GM_setValue("removenonsearch", this.checked); });
  141. viewport.mousedown(function() { ToggleSettings(); });
  142. } else {
  143. $("#gi-nuke").unbind();
  144. $("#gi-rownum").unbind();
  145. $("#gi-antigateway").unbind();
  146. $("#gi-cleansearch").unbind();
  147. $("#gi-removenonsearch").unbind();
  148. viewport.unbind();
  149. $("#gi-settings").remove();
  150. }
  151. }
  152.  
  153.  
  154. (function() {
  155. console.log("%c Google Improved - 1.0.10 ", 'background: #166BEC; color: #f1f1f1');
  156. x = document.getElementById("main");
  157. if(x.addEventListener){
  158. x.addEventListener('DOMSubtreeModified', DoLines, false);
  159. }
  160. if(nuke) {
  161. /* DEATH TO THE CLUTTER */
  162. $("#prm-pt").remove(); //Prompt
  163. $("#footer").remove(); //Footer (obviously)
  164. $("#gb").remove(); //Top bar
  165. $("input[name='btnK']").remove(); //Google Search button, farewell
  166. $("input[name='btnI']").remove(); //I'm Feeling Lucky button, I'll enjoy killing you the most
  167. //var search = $("#searchform.jhp");
  168. //search.css("top", "45%");
  169. $("head").append("<style type=\"text/css\">#searchform.jhp { top: 45% !important; }</style>");
  170. var logo = $("#hplogo");
  171. if(chrome && (window.location.toString().indexOf("//www.google.com/") !== -1 || window.location.toString().indexOf("//google.com/") !== -1)) logo.css("padding-top", "");
  172. logo.parent().css("padding-top", "").css("margin-top", "");
  173. logo.parent().parent()
  174. .css("height", "")
  175. .css("position", "absolute")
  176. .css("left", "50%")
  177. .css("margin-left", "-134px")
  178. .css("top", "45%")
  179. .css("margin-top", (
  180. window.location.toString().indexOf("https://encrypted.google.com") === 0 ||
  181. (!chrome && window.location.toString().indexOf("webhp?hl=en") !== -1) ? "-220px" : "-115px"));
  182. logo.children().first().text("Clean");
  183. }
  184. var ctrl = false, alt = false;
  185. $("body").on("keydown", function(evt) {
  186. if(evt.which == 17) ctrl = true;
  187. else if(evt.which == 18) alt = true;
  188. else if(ctrl && alt && evt.which == 73) ToggleSettings();
  189. else if(ctrl && alt && evt.which == 68) {
  190. console.log("%c Dumping debug data... ", 'background: #f1f1f1; color: #166BEC');
  191. console.log("DoLines() hit " + hit + " times");
  192. console.log("nuke=" + nuke + ";rownum=" + rownum + ";antigateway=" + antigateway + ";cleansearch=" + cleansearch + ";removenonsearch=" + removenonsearch);
  193. }
  194. });
  195. $("body").on("keyup", function(evt) {
  196. if(evt.which == 17) ctrl = false;
  197. else if(evt.which == 18) alt = false;
  198. });
  199. DoLines();
  200. })();