Google Improved

Makes Google bearable

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

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