Created
September 4, 2011 18:33
-
-
Save morrow/1193282 to your computer and use it in GitHub Desktop.
Google Plus Link to Comments Directly (no longer working with new versions of googleplus)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function(){alert("Click the text of the comment you want a link to.");document.body.onclick=function(e){var clearance_height,element,id,offset_height,post,sibling_cursor,sibling_element,sibling_elements,sibling_ids,url,_i,_j,_len;element=e.toElement;_i=10;while(_i>0&&!id){if(element.parentNode&&element.parentNode.className==="qx rg"){id=element.parentNode.id;}element=element.parentNode;_i--;}sibling_ids=[];sibling_elements=element.parentNode.getElementsByClassName("qx rg");clearance_height=0;offset_height=0;if(window.innerHeight>=530){clearance_height+=document.getElementById("gb").offsetHeight||30;}if(window.innerHeight>=800){clearance_height+=document.getElementsByClassName("c-cb-V c-i-cb-V c-cb-V-Fi")[0].offsetHeight||60;}for(_j=0,_len=sibling_elements.length;_j<_len;_j++){sibling_element=sibling_elements[_j];sibling_ids.push(sibling_element.id);}sibling_cursor=sibling_ids.indexOf(element.id);while(offset_height<clearance_height&&sibling_cursor>0){sibling_cursor-=1;offset_height+=sibling_elements[sibling_ids[sibling_cursor]].offsetHeight;}if(sibling_ids&&sibling_ids.indexOf(sibling_cursor)){id=sibling_ids[sibling_cursor];}if(!id){return alert("No comment ID found,try clicking on the actual text of the comment.");}else{url=window.location.href;post=url.split("google.com/")[1];url=window.location.protocol+"//"+window.location.hostname+"#"+post+"#"+post+"#"+id;return alert(url);}};}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alert "Click the text of the comment you want a link to." | |
| document.body.onclick = (e)-> | |
| # Get element | |
| element = e.toElement | |
| # Set node depth limit | |
| _i = 10 | |
| # Search parent siblings of clicked element for anchorable div | |
| while _i > 0 and !id | |
| if element.parentNode and element.parentNode.className is "qx rg" | |
| id = element.parentNode.id | |
| element = element.parentNode | |
| _i-- | |
| # Find siblings to the selected comment in order to find the best anchor element to target | |
| # This accounts for the heights of the gbar and google plus navbar | |
| sibling_ids = [] | |
| sibling_elements = element.parentNode.getElementsByClassName("qx rg") | |
| clearance_height = 0 | |
| offset_height = 0 | |
| # Account for gbar (dynamically appearing based on browser window height) | |
| if window.innerHeight >= 530 then clearance_height += document.getElementById("gb").offsetHeight || 30 | |
| # Account for g+ navbar (dynamically appearing based on browser window height) | |
| if window.innerHeight >= 800 then clearance_height += document.getElementsByClassName("c-cb-V c-i-cb-V c-cb-V-Fi")[0].offsetHeight || 60 | |
| # Populate sibling_ids array | |
| for sibling_element in sibling_elements | |
| sibling_ids.push sibling_element.id | |
| # Set cursor to index of target element | |
| sibling_cursor = sibling_ids.indexOf(element.id) | |
| # Add up the total heights of each sibling comment prior to our target comment until we reach or exceed the clearance height | |
| while (offset_height < clearance_height and sibling_cursor > 0) | |
| # Subtract first as to not include the height of the target comment | |
| sibling_cursor -= 1 | |
| # Add height of the sibling element to the total offset height | |
| offset_height += sibling_elements[sibling_ids[sibling_cursor]].offsetHeight | |
| # If we ended up with a usable sibling id, use that, othewise link to original id | |
| if sibling_ids and sibling_ids.indexOf(sibling_cursor) | |
| id = sibling_ids[sibling_cursor] | |
| # If no id is found, prompt user to try again | |
| if not id | |
| alert "No comment ID found, try clicking on the actual text of the comment." | |
| # Alert final url | |
| else | |
| url = window.location.href | |
| post = url.split("google.com/")[1] | |
| url = window.location.protocol + "//" + window.location.hostname + "#" + post + "#" + post + "#" + id | |
| alert url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| alert("Click the text of the comment you want a link to."); | |
| document.body.onclick = function(e) { | |
| var clearance_height, element, id, offset_height, post, sibling_cursor, sibling_element, sibling_elements, sibling_ids, url, _i, _j, _len; | |
| element = e.toElement; | |
| _i = 10; | |
| while (_i > 0 && !id) { | |
| if (element.parentNode && element.parentNode.className === "qx rg") { | |
| id = element.parentNode.id; | |
| } | |
| element = element.parentNode; | |
| _i--; | |
| } | |
| sibling_ids = []; | |
| sibling_elements = element.parentNode.getElementsByClassName("qx rg"); | |
| clearance_height = 0; | |
| offset_height = 0; | |
| if (window.innerHeight >= 530) { | |
| clearance_height += document.getElementById("gb").offsetHeight || 30; | |
| } | |
| if (window.innerHeight >= 800) { | |
| clearance_height += document.getElementsByClassName("c-cb-V c-i-cb-V c-cb-V-Fi")[0].offsetHeight || 60; | |
| } | |
| for (_j = 0, _len = sibling_elements.length; _j < _len; _j++) { | |
| sibling_element = sibling_elements[_j]; | |
| sibling_ids.push(sibling_element.id); | |
| } | |
| sibling_cursor = sibling_ids.indexOf(element.id); | |
| while (offset_height < clearance_height && sibling_cursor > 0) { | |
| sibling_cursor -= 1; | |
| offset_height += sibling_elements[sibling_ids[sibling_cursor]].offsetHeight; | |
| } | |
| if (sibling_ids && sibling_ids.indexOf(sibling_cursor)) { | |
| id = sibling_ids[sibling_cursor]; | |
| } | |
| if (!id) { | |
| return alert("No comment ID found, try clicking on the actual text of the comment."); | |
| } else { | |
| url = window.location.href; | |
| post = url.split("google.com/")[1]; | |
| url = window.location.protocol + "//" + window.location.hostname + "#" + post + "#" + post + "#" + id; | |
| return alert(url); | |
| } | |
| }; | |
| }).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment