2017-08-28 00:17:08 +00:00
|
|
|
//
|
|
|
|
// Make Medium Readable Again
|
|
|
|
//
|
|
|
|
|
|
|
|
var makeReadable = function() {
|
|
|
|
// Un-position:fixed the top nav bar
|
|
|
|
var topNav = document.querySelector('.metabar.u-fixed');
|
2017-12-16 09:39:40 +00:00
|
|
|
if (topNav) {
|
2017-08-28 00:17:08 +00:00
|
|
|
topNav.classList.remove('u-fixed');
|
|
|
|
}
|
2018-04-10 15:58:44 +00:00
|
|
|
|
2018-04-26 02:39:17 +00:00
|
|
|
// Remove the "Pardon the interruption" popup.
|
|
|
|
// We do this with JS because the .overlay.overlay--lighter element is used
|
|
|
|
// for interactions we consent to, like the sign up / log in dialogs, so we
|
|
|
|
// don't want to obliterate them too.
|
|
|
|
// FIXME: prevent this from breaking signup/login dialogs when the popup
|
|
|
|
// is removed (it works after changing pages).
|
|
|
|
var headings = document.evaluate("//h1[contains(., 'Pardon the interruption.')]", document, null, XPathResult.ANY_TYPE, null );
|
|
|
|
var thisHeading = headings.iterateNext();
|
|
|
|
if (thisHeading != null) {
|
|
|
|
var $overlay = thisHeading.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
$overlay.parentNode.removeChild($overlay);
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:22:06 +00:00
|
|
|
// Inject remaining styles
|
2018-04-10 15:58:44 +00:00
|
|
|
// This check makes sure the extension works on Chrome and Firefox.
|
|
|
|
if (typeof browser === 'undefined') {
|
|
|
|
browser = chrome;
|
|
|
|
}
|
2018-10-22 19:15:07 +00:00
|
|
|
var mediumCSS = browser.runtime.getURL("medium.css");
|
|
|
|
if (document.querySelector('head link[href="' + mediumCSS + '"]') == null) {
|
|
|
|
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" type="text/css" href="' + mediumCSS + '">');
|
|
|
|
}
|
2017-08-28 00:17:08 +00:00
|
|
|
};
|
|
|
|
|
2018-04-08 11:11:03 +00:00
|
|
|
var hideHighlightMenu = function() {
|
2018-10-22 18:30:47 +00:00
|
|
|
document.head.insertAdjacentHTML('beforeend', '<style type="text/css">.highlightMenu { display: none; }</style>');
|
2018-04-08 11:11:03 +00:00
|
|
|
};
|
|
|
|
|
2017-08-28 22:48:24 +00:00
|
|
|
var hideDickbar = function() {
|
2017-08-31 03:12:41 +00:00
|
|
|
var dickbar = document.querySelector('.js-postShareWidget');
|
2017-12-16 09:39:40 +00:00
|
|
|
if (dickbar) {
|
2017-08-31 03:12:41 +00:00
|
|
|
dickbar.style.display = 'none';
|
|
|
|
}
|
|
|
|
var footerDickbar = document.querySelector('footer > .container:first-child');
|
2017-12-16 09:39:40 +00:00
|
|
|
if (footerDickbar) {
|
2017-08-31 03:12:41 +00:00
|
|
|
footerDickbar.style.display = 'none';
|
|
|
|
}
|
2017-08-28 22:48:24 +00:00
|
|
|
};
|
|
|
|
|
2017-08-31 02:45:22 +00:00
|
|
|
var disableLazyLoading = function() {
|
2017-09-14 02:58:10 +00:00
|
|
|
// Get all <noscript> tags accompanying dynamically-loading <img>s
|
2017-09-14 03:00:50 +00:00
|
|
|
var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
|
2017-12-16 09:39:40 +00:00
|
|
|
if (hiddenMedia.length === 0) {
|
2017-08-31 02:45:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (var i=0; i<hiddenMedia.length; i++) {
|
2017-09-14 02:58:10 +00:00
|
|
|
// Create new <img> element from the one in <noscript> and add it in.
|
|
|
|
// This is certainly a roundabout way of doing things, but I didn't want to
|
|
|
|
// spend more time reverse-engineering Medium's lazy-loading code.
|
2017-12-16 09:39:40 +00:00
|
|
|
var img = new Image();
|
2017-09-14 02:58:10 +00:00
|
|
|
var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
|
|
|
|
if (srcMatch != null) {
|
|
|
|
img.src = srcMatch[1];
|
|
|
|
img.className = hiddenMedia[i].textContent.match(/class="([^"]+)"/)[1];
|
|
|
|
hiddenMedia[i].parentNode.appendChild(img);
|
|
|
|
}
|
2017-08-31 02:45:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-04 22:12:33 +00:00
|
|
|
var shrinkHeaderImages = function() {
|
2017-09-02 15:04:28 +00:00
|
|
|
var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
|
2017-12-16 09:39:40 +00:00
|
|
|
if (ridiculousHeaderImage) {
|
2017-09-02 15:04:28 +00:00
|
|
|
ridiculousHeaderImage.style.maxWidth = '700px';
|
|
|
|
ridiculousHeaderImage.style.margin = '0 auto';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:11:46 +00:00
|
|
|
var observer = new MutationObserver(function(mutations){
|
2017-09-05 01:43:06 +00:00
|
|
|
mutations.forEach(function(){
|
|
|
|
makeReadable();
|
|
|
|
shrinkHeaderImages();
|
|
|
|
});
|
2017-08-30 19:11:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var config = {attributes: true};
|
|
|
|
|
2018-03-31 13:34:31 +00:00
|
|
|
// This extension runs on all domains so it can Make Medium Readable Again even for publications on custom domains.
|
|
|
|
// Here we make sure the code only runs on Medium sites.
|
2018-03-31 13:29:15 +00:00
|
|
|
if (document.querySelector('head meta[property="al:ios:app_name"][content="medium" i]')) {
|
2017-08-28 00:17:08 +00:00
|
|
|
makeReadable();
|
2017-09-04 22:12:33 +00:00
|
|
|
shrinkHeaderImages();
|
2017-08-28 22:48:24 +00:00
|
|
|
|
|
|
|
chrome.storage.sync.get(null, function(items) {
|
|
|
|
if (items.hideDickbar) {
|
|
|
|
hideDickbar();
|
|
|
|
}
|
2017-08-31 02:45:22 +00:00
|
|
|
if (items.disableLazyImages) {
|
|
|
|
disableLazyLoading();
|
|
|
|
}
|
2018-04-08 11:11:03 +00:00
|
|
|
if (items.hideHighlightMenu) {
|
|
|
|
hideHighlightMenu();
|
|
|
|
}
|
2017-08-28 22:48:24 +00:00
|
|
|
});
|
2017-08-30 19:11:46 +00:00
|
|
|
|
2017-12-16 09:39:40 +00:00
|
|
|
observer.observe(document.body, config);
|
2017-08-28 00:17:08 +00:00
|
|
|
}
|