Linkify Google Search Results

When you mouseover the green url below google search results, the url is linkified

  1. // ==UserScript==
  2. // @name Linkify Google Search Results
  3. // @namespace @namespace Andrew Basta
  4. // @description When you mouseover the green url below google search results, the url is linkified
  5. // @include http://www.google.co*/*
  6. // @version 0.0.1.20140621045118
  7. // ==/UserScript==
  8.  
  9. //User variables
  10. var indent = 1; //set to 0 for no indentation animation
  11. var marginPix = 8; //number of pixels to indent
  12. var marginCount = 10; //number of steps that are run to complete indentation
  13. var whiteSpaces = 2; //number of whitespaces that show up between the links
  14. var linkColor = "green"; //change to "default" if you're using a custom style and prefer to keep the native color,
  15. //or if you're not using a custom style but prefer blue links..or change to whatever you want.
  16. var boldRoot = 1; // set to 0 for no bold on the root domain of the url lists
  17. var splitOnLoad = 0; // set to 1 to split all the urls on pageload
  18.  
  19. //fadeInMargin Adapted from www.hesido.com
  20. function fadeInMargin (element){
  21. if (element.intFunction)
  22. window.clearInterval(element.intFunction);
  23. var count = 0;
  24. element.intFunction = window.setInterval(
  25. function() {
  26. element.currentWidth = easeInOut(0, marginPix, marginCount, count, 0.5);
  27. element.style.marginLeft = element.currentWidth+"px";
  28. count++;
  29. if (count > marginCount) {
  30. window.clearInterval(element.intFunction);
  31. }
  32. }
  33. , 5);
  34. }
  35.  
  36. //fadeOutMargin Adapted from www.hesido.com
  37. function fadeOutMargin (element){
  38. if (element.intFunction)
  39. window.clearInterval(element.intFunction);
  40. var count = 0;
  41. element.intFunction = window.setInterval(
  42. function() {
  43. element.currentWidth = easeInOut(marginPix, 0, marginCount, count, 0.5);
  44. element.style.marginLeft = element.currentWidth+"px";
  45. count++;
  46. if (count > marginCount) {
  47. window.clearInterval(element.intFunction);
  48. }
  49. }
  50. , 8);
  51. }
  52.  
  53. //Generic Animation Step Value Generator By www.hesido.com
  54. function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
  55. var delta = maxValue - minValue;
  56. var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta);
  57. return Math.ceil(stepp)
  58. }
  59.  
  60. function hover(event) {
  61. var linkText = [];
  62. var count = 0;
  63.  
  64. this.innerHTML = "";
  65. for (var i=0; i<linkListText[this.id].length; i++) {
  66. if (linkListText[this.id][i] != "...") {
  67. if (linkColor == "default") this.innerHTML = this.innerHTML.concat("<a href=http://", linkListURL[this.id][i], ">",linkListText[this.id][i],"/</a>");
  68. else if ((i==0) && (boldRoot==1)) this.innerHTML = this.innerHTML.concat("<em><a href=http://", linkListURL[this.id][i], " style=color:", linkColor, ">",linkListText[this.id][i],"/</a></em>");
  69. else this.innerHTML = this.innerHTML.concat("<a href=http://", linkListURL[this.id][i], " style=color:", linkColor, ">",linkListText[this.id][i],"/</a>");
  70. for (var j=0; j<whiteSpaces; j++) {
  71. this.innerHTML = this.innerHTML.concat("&nbsp");
  72. }
  73. }
  74. else break;
  75. }
  76. this.removeEventListener('mouseover', hover, false);
  77. this.addEventListener('mouseout', leave, false);
  78. if (indent) fadeInMargin(this);
  79. }
  80.  
  81. function splitAll() {
  82. var linkText = [];
  83. var count = 0;
  84. for (var i=0; i<linkList.length; i++) {
  85. linkList[i].innerHTML = "";
  86. for (var j=0; j<linkListText[linkList[i].id].length; j++) {
  87. if (linkListText[linkList[i].id][j] != "...") {
  88. if (linkColor == "default") linkList[i].innerHTML = linkList[i].innerHTML.concat("<a href=http://", linkListURL[linkList[i].id][j], ">",linkListText[linkList[i].id][j],"/</a>");
  89. else if ((j==0) && (boldRoot==1)) linkList[i].innerHTML = linkList[i].innerHTML.concat("<em><a href=http://", linkListURL[linkList[i].id][j], " style=color:", linkColor, ">",linkListText[linkList[i].id][j],"/</a></em>");
  90. else linkList[i].innerHTML = linkList[i].innerHTML.concat("<a href=http://", linkListURL[linkList[i].id][j], " style=color:", linkColor, ">",linkListText[linkList[i].id][j],"/</a>");
  91. for (var k=0; k<whiteSpaces; k++) {
  92. linkList[i].innerHTML = linkList[i].innerHTML.concat("&nbsp");
  93. }
  94. }
  95. else break;
  96. }
  97. }
  98. }
  99.  
  100.  
  101. //contains from mike hall, brainjar.com
  102. function contains(a, b) {
  103. // Return true if node a contains node b.
  104. while (b.parentNode)
  105. if ((b = b.parentNode) == a)
  106. return true;
  107. return false;
  108. }
  109.  
  110. //leave adapted from mike hall, brainjar.com
  111. //basically, this makes sure that the link you just moused out of was the last link moused into...
  112. function leave(event) {
  113. if (window.event) {
  114. current = this;
  115. related = window.event.toElement;
  116. }
  117. else {
  118. current = event.currentTarget;
  119. related = event.relatedTarget;
  120. }
  121.  
  122. if (current != related && !contains(current, related)) {
  123. this.textContent = linkListOrig[this.id];
  124. this.removeEventListener('mouseout', leave, false);
  125. this.addEventListener('mouseover', hover, false);
  126. if (indent) fadeOutMargin(this);
  127. }
  128. }
  129.  
  130. var currentLink;
  131. var linkList = document.getElementsByTagName('cite'); //gets all the green urls
  132. var linkListText = []; // holds the split text of the green url
  133. var linkListOrig = []; // holds a copy of the original green url
  134. var linkListURL = []; // holds the urls of all individual links
  135.  
  136. for (var i=0; i<linkList.length; i++) {
  137. //Indices of extraneous clutter, i.e. size of linked document and preceding http:// in green url. I don't like those.
  138. var trim0 = linkList[i].textContent.indexOf("://");
  139. var trim1 = linkList[i].textContent.indexOf(" - ");
  140. var trim2 = linkList[i].textContent.indexOf("/ - ");
  141. var trim3 = linkList[i].textContent.indexOf("/.../");
  142. var slashTest = linkList[i].textContent.indexOf("/");
  143.  
  144. linkList[i].id = i;
  145.  
  146. if(linkList[i].nextSibling != null && slashTest > -1) { //make sure the url has /'s in it..this is where i split it up
  147. //Trimming the extraneous clutter here...
  148. if(trim1>-1){
  149. linkListText[i] = linkList[i].textContent.substring((trim0==-1)?0:(trim0+3),((trim1==(trim2+1))?trim2:trim1));
  150. linkListOrig[i] = linkList[i].textContent.substring((trim0==-1)?0:(trim0+3),((trim1==(trim2+1))?(trim2+4):(trim1+3)));
  151. linkListURL[i] = linkList[i].textContent.substring((trim0==-1)?0:(trim0+3),((trim1==(trim2+1))?trim2:trim1));
  152. }
  153. else {
  154. linkListText[i] = linkList[i].textContent;
  155. linkListOrig[i] = linkList[i].textContent;
  156. linkListURL[i] = linkList[i].textContent;
  157. }
  158. if (trim3 > -1) {
  159. linkListText[i] = linkList[i].textContent.substring(0,trim3);
  160. linkListOrig[i] = linkList[i].textContent.substring(0,trim3);
  161. linkListURL[i] = linkList[i].textContent.substring(0,trim3);
  162. }
  163. linkList[i].textContent = linkListOrig[i]; //Copy the original green url for safekeeping
  164.  
  165. linkListText[i] = linkListText[i].split("/"); //Split up the url
  166. linkListURL[i] = linkListURL[i].split("/"); //Split up the url
  167.  
  168. //Concatenate the individual links to new urls...
  169. for (var j=0; j<linkListURL[i].length; j++)
  170. {
  171. if (j>0) {
  172. if (linkListURL[i][j] != null) linkListURL[i][j] = linkListURL[i][j-1].concat("/",linkListURL[i][j]);
  173. }
  174. }
  175.  
  176. if(!splitOnLoad) linkList[i].addEventListener('mouseover', hover, false);
  177. }
  178. //If there are /'s in the original url, make sure that it's a valid link, and not just green text that google threw in (like for adverts and such)
  179. else if (slashTest > -1 || (linkList[i].nextSibling != null && linkList[i].nextSibling.tagName == "BR")) {
  180. linkListText[i] = linkList[i].textContent;
  181. linkListOrig[i] = linkList[i].textContent;
  182. linkListURL[i] = linkList[i].textContent;
  183. linkList[i].textContent = linkListOrig[i];
  184.  
  185. linkListText[i] = linkListText[i].split("/");
  186. linkListURL[i] = linkListURL[i].split("/");
  187. for (var j=0; j<linkListURL[i].length; j++)
  188. {
  189. if (j>0) {
  190. if (linkListURL[i][j] != null) linkListURL[i][j] = linkListURL[i][j-1].concat("/",linkListURL[i][j]);
  191. }
  192. }
  193. if(!splitOnLoad) linkList[i].addEventListener('mouseover', hover, false);
  194. }
  195. else {
  196. linkListText[i] = linkList[i].textContent;
  197. linkListOrig[i] = linkList[i].textContent;
  198. linkListURL[i] = linkList[i].textContent;
  199. linkListText[i] = linkListText[i].split("/");
  200. linkListURL[i] = linkListURL[i].split("/");
  201. for (var j=0; j<linkListURL[i].length; j++)
  202. {
  203. if (j>0) {
  204. if (linkListURL[i][j] != null) linkListURL[i][j] = linkListURL[i][j-1].concat("/",linkListURL[i][j]);
  205. }
  206. }
  207. if(!splitOnLoad) linkList[i].addEventListener('mouseover', hover, false);
  208. }
  209. }
  210.  
  211. if(splitOnLoad) {
  212. splitAll();
  213. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址