//
// Make Medium Readable Again
//

var makeReadable = function() {
	// Un-position:fixed the top nav bar
	var topNav = document.querySelector('.metabar.u-fixed');
	if (topNav != null) {
		topNav.classList.remove('u-fixed');
	}
	// Remove the footer
	var getUpdatesBar = document.querySelector('.js-stickyFooter');
	if (getUpdatesBar != null) {
		getUpdatesBar.style.display = 'none';
	}
};

var hideDickbar = function() {
	document.querySelector('.js-postShareWidget').style.display = 'none';
	document.querySelector('footer > .container:first-child').style.display = 'none';
};

var disableLazyLoading = function() {
	var hiddenMedia = document.querySelectorAll('.js-progressiveMedia-inner');
	if (hiddenMedia == null) {
		return;
	}
	for (var i=0; i<hiddenMedia.length; i++) {
		var template = document.createElement('template');
		template.innerHTML = hiddenMedia[i].textContent;
		hiddenMedia[i].parentNode.appendChild(template.content.firstChild);
	}
};

// Only run this on Medium sites. 
// Ensure that by checking for <meta property="al:ios:app_name" content="Medium"> in the document <head />
var metaCheck = document.head.querySelector('meta[property="al:ios:app_name"]');
if (metaCheck != null && metaCheck.content == "Medium") {
	makeReadable();

	chrome.storage.sync.get(null, function(items) {
		if (items.hideDickbar) {
			hideDickbar();
		}
		if (items.disableLazyImages) {
			disableLazyLoading();
		}
	});
}

@@ -418,16 +418,30 @@
 on() %7B%0A%09
+var dickbar = 
 document
@@ -477,16 +477,51 @@
 Widget')
+;%0A%09if (dickbar != null) %7B%0A%09%09dickbar
 .style.d
@@ -538,16 +538,39 @@
 none';%0A%09
+%7D%0A%09var footerDickbar = 
 document
@@ -618,16 +618,63 @@
 -child')
+;%0A%09if (footerDickbar != null) %7B%0A%09%09footerDickbar
 .style.d
@@ -690,16 +690,19 @@
 'none';%0A
+%09%7D%0A
 %7D;%0A%0Avar 

Check for null dickbars before applying styles