Last active
September 2, 2015 13:41
-
-
Save oliverdoetsch/cf22b02980b1ba461e18 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
<script type="text/javascript"> | |
//<![CDATA[ | |
document.addEventListener('DOMContentLoaded', function() { | |
var sAttribut = /\/s\B\d{2,4}/; | |
var postWidth = document.getElementsByClassName('post-body')[0].offsetWidth; | |
var table = document.querySelectorAll('.post-body table'); | |
if (typeof(table) != 'undefined' && table !== null) { | |
var n = table.length; | |
while (n--) { | |
var oldNode = table[n]; | |
var newNode = document.createElement('div'); | |
newNode.setAttribute('class', 'separator'); | |
var newCap = document.createElement('div'); | |
newCap.style.textAlign = 'center'; | |
var p = table[n].querySelector('a').cloneNode(true); | |
newNode.appendChild(p); | |
oldNode.parentNode.replaceChild(newNode, oldNode); | |
if (table[n].querySelector('.tr-caption')) { | |
var text = table[n].querySelector('.tr-caption').innerText || table[n].querySelector('.tr-caption').textContent; | |
newCap.innerHTML = text; | |
newNode.appendChild(newCap); | |
} | |
} | |
} | |
var image = document.querySelectorAll('.post-body img'); | |
var i = image.length; | |
while (i--) { | |
var thisHeight = image[i].height; | |
var thisWidth = image[i].width; | |
var thisRatio = thisWidth / thisHeight; | |
var newHeight = Math.round(postWidth / thisRatio); | |
var newDimension = ''; | |
if (thisWidth >= thisHeight) { | |
newDimension = postWidth; | |
} else { | |
newDimension = newHeight; | |
} | |
var src = image[i].getAttribute('src'); | |
var newSrc = src.replace(sAttribut, '/' + 's' + newDimension); | |
image[i].removeAttribute('width'); | |
image[i].removeAttribute('height'); | |
image[i].parentNode.removeAttribute('style'); | |
image[i].style.marginLeft = "0"; | |
image[i].style.padding = "0"; | |
image[i].style.boxSizing = "border-box"; | |
image[i].style.boxShadow = "0 0 0 rgba(0, 0, 0, 0)"; | |
image[i].setAttribute('width', postWidth); | |
image[i].setAttribute('src', newSrc); | |
} | |
}); | |
//]]> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment