-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
65 lines (55 loc) · 2.59 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// window.addEventListener ("load", expandGeneration(), false);
// document.onreadystatechange = function () {
// if (document.readyState == "complete") {
// expandGeneration()
// }
// }
function expandGeneration(){
var btns = document.getElementsByTagName('button')
var showCount = 0
for(var i = 0;i<btns.length;i++){
if(btns[i].getAttribute('aria-label')){
if(btns[i].getAttribute('aria-label').includes('Show') && !btns[i].getAttribute('aria-label').includes('spouse')){
btns[i].click()
showCount++
}
}
}
if(showCount==0){
alert('All Generations Expanded!')
}
}
function nGenerations(numberOfGenerations){
for(var i=0;i<numberOfGenerations;i++){
expandGeneration()
yield()
}
}
function findPotentialAncestor(){
if(document.getElementsByClassName("potential").length > 0){
var ancestorRectangle = document.getElementsByClassName("potential")[0].getBoundingClientRect();
var ancestorVerticalCenter = (ancestorRectangle.bottom - ancestorRectangle.top)/2
var ancestorHorizontalCenter = (ancestorRectangle.right - ancestorRectangle.left)/2
var treeWrapper = document.getElementsByClassName("treeWrapper")[0]
var containerWindow = document.getElementsByClassName("treeViewZoomPanContainer")[0].getBoundingClientRect()
var screenVerticalCenter = containerWindow.top + ((containerWindow.bottom - containerWindow.top)/2)
var screenHorizontalCenter = containerWindow.left + ((containerWindow.right - containerWindow.left)/2)
var desiredTop = screenVerticalCenter - ancestorVerticalCenter
var desiredLeft = screenHorizontalCenter - ancestorHorizontalCenter
var verticalMovementRequired = desiredTop - ancestorRectangle.top
var horizontalMovementRequired = desiredLeft - ancestorRectangle.left
treeWrapper.style.top = +treeWrapper.style.top.match(/\d*\.*\d*/)[0] + verticalMovementRequired + 'px'
treeWrapper.style.left = +treeWrapper.style.left.match(/\d*\.*\d*/)[0] + horizontalMovementRequired + 'px'
}
// console.log(rect.top, rect.right, rect.bottom, rect.left);
}
chrome.runtime.onMessage.addListener(gotMessage)
function gotMessage(request, sender, sendResponse){
if(document.location.href.match(/https:.*ancestry.com.family-tree.tree.*cfpid=\d*.*/)[0]==document.location.href){
expandGeneration()
findPotentialAncestor()
}
}
// save for later matching
// "https://*.ancestry.com/family-tree/tree/*cfpid=*"
// /^https:-store.mywebsite.com.(folder-\d+)/