Last active
August 29, 2015 13:57
-
-
Save rudiedirkx/9536267 to your computer and use it in GitHub Desktop.
Create a new popup to read the current selection
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() { | |
function parents(node) { | |
var el = node, | |
els = []; | |
while ( el && (el = el.parentNode) ) { | |
els.push(el); | |
} | |
return els; | |
} | |
var s = getSelection(), | |
from = s.baseNode, | |
to = s.extentNode; | |
var parents1 = parents(from), | |
parents2 = parents(to), | |
ancestor; | |
outside: | |
for ( var i=0, L=parents1.length; i<L; i++ ) { | |
for ( var j=0, M=parents2.length; j<M; j++ ) { | |
if ( parents1[i] == parents2[j] ) { | |
ancestor = parents1[1]; | |
break outside; | |
} | |
} | |
} | |
console.log('common ancestor', ancestor); | |
if ( ancestor ) { | |
console.log('====' + ancestor.textContent.trim() + '====') | |
with ( ancestor.style ) { | |
position = 'fixed'; | |
top = '5%'; | |
right = '5%'; | |
bottom = '5%'; | |
left = '5%'; | |
outline = 'solid 200px rgba(0, 0, 0, 0.5)'; | |
background = 'white'; | |
color = 'black'; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment