Google Improved

Makes Google bearable

当前为 2015-07-23 提交的版本,查看 最新版本

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