Created
April 5, 2018 04:58
-
-
Save zawataki/2fe740cfc26f0963cc72974d4982af80 to your computer and use it in GitHub Desktop.
This file contains 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
// Find difference element in Confluence history difference page | |
// and Scroll to the element. | |
function scroll_to_next_diff() { | |
let addedElements = document.getElementsByClassName('diff-html-added'); | |
let removedElements = document.getElementsByClassName('diff-html-removed'); | |
let targetElements = Array.from(addedElements) | |
.concat(Array.from(removedElements)); | |
targetElements.sort(function (a, b) { | |
let aRect = a.getBoundingClientRect(); | |
let aAbsolutelyTop = aRect.top + window.pageYOffset; | |
let aAbsolutelyLeft = aRect.left + window.pageXOffset; | |
let bRect = b.getBoundingClientRect(); | |
let bAbsolutelyTop = bRect.top + window.pageYOffset; | |
let bAbsolutelyLeft = bRect.left + window.pageXOffset; | |
let topDiff = aAbsolutelyTop - bAbsolutelyTop; | |
if (topDiff === 0) { | |
return aAbsolutelyLeft - bAbsolutelyLeft; | |
} | |
return topDiff; | |
}); | |
for (const element of targetElements) { | |
let style = element.style; | |
style.border = ''; | |
} | |
let numberOfElements = targetElements.length; | |
let index = sessionStorage.getItem('currentIndex'); | |
if (index === null) { | |
index = 0; | |
} else { | |
index++; | |
if (index >= numberOfElements) { | |
index = 0; | |
} | |
} | |
targetElements[index].scrollIntoView(); | |
let targetStyle = targetElements[index].style; | |
targetStyle.border = 'solid 2px #5989cf'; | |
sessionStorage.currentIndex = index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment