Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 1.74 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.   alert("Click the text of the comment you want a link to.");
  3.   document.body.onclick = function(e) {
  4.     var clearance_height, element, id, offset_height, post, sibling_cursor, sibling_element, sibling_elements, sibling_ids, url, _i, _j, _len;
  5.     element = e.toElement;
  6.     _i = 10;
  7.     while (_i > 0 && !id) {
  8.       if (element.parentNode && element.parentNode.className === "qx rg") {
  9.         id = element.parentNode.id;
  10.       }
  11.       element = element.parentNode;
  12.       _i--;
  13.     }
  14.     sibling_ids = [];
  15.     sibling_elements = element.parentNode.getElementsByClassName("qx rg");
  16.     clearance_height = 0;
  17.     offset_height = 0;
  18.     if (window.innerHeight >= 530) {
  19.       clearance_height += document.getElementById("gb").offsetHeight || 30;
  20.     }
  21.     if (window.innerHeight >= 800) {
  22.       clearance_height += document.getElementsByClassName("c-cb-V c-i-cb-V c-cb-V-Fi")[0].offsetHeight || 60;
  23.     }
  24.     for (_j = 0, _len = sibling_elements.length; _j < _len; _j++) {
  25.       sibling_element = sibling_elements[_j];
  26.       sibling_ids.push(sibling_element.id);
  27.     }
  28.     sibling_cursor = sibling_ids.indexOf(element.id);
  29.     while (offset_height < clearance_height && sibling_cursor > 0) {
  30.       sibling_cursor -= 1;
  31.       offset_height += sibling_elements[sibling_ids[sibling_cursor]].offsetHeight;
  32.     }
  33.     if (sibling_ids && sibling_ids.indexOf(sibling_cursor)) {
  34.       id = sibling_ids[sibling_cursor];
  35.     }
  36.     if (!id) {
  37.       return alert("No comment ID found, try clicking on the actual text of the comment.");
  38.     } else {
  39.       url = window.location.href;
  40.       post = url.split("google.com/")[1];
  41.       url = window.location.protocol + "//" + window.location.hostname + "#" + post + "#" + post + "#" + id;
  42.       return alert(url);
  43.     }
  44.   };
  45. }).call(this);