mirror of
https://github.com/thebaer/MMRA
synced 2024-11-13 10:11:01 +00:00
Improve/fix querySelector usage
This commit is contained in:
parent
ed675b91dd
commit
fd25d28997
20
content.js
20
content.js
@ -5,23 +5,23 @@
|
|||||||
var makeReadable = function() {
|
var makeReadable = function() {
|
||||||
// Un-position:fixed the top nav bar
|
// Un-position:fixed the top nav bar
|
||||||
var topNav = document.querySelector('.metabar.u-fixed');
|
var topNav = document.querySelector('.metabar.u-fixed');
|
||||||
if (topNav != null) {
|
if (topNav) {
|
||||||
topNav.classList.remove('u-fixed');
|
topNav.classList.remove('u-fixed');
|
||||||
}
|
}
|
||||||
// Remove the footer
|
// Remove the footer
|
||||||
var getUpdatesBar = document.querySelector('.js-stickyFooter');
|
var getUpdatesBar = document.querySelector('.js-stickyFooter');
|
||||||
if (getUpdatesBar != null) {
|
if (getUpdatesBar) {
|
||||||
getUpdatesBar.style.display = 'none';
|
getUpdatesBar.style.display = 'none';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var hideDickbar = function() {
|
var hideDickbar = function() {
|
||||||
var dickbar = document.querySelector('.js-postShareWidget');
|
var dickbar = document.querySelector('.js-postShareWidget');
|
||||||
if (dickbar != null) {
|
if (dickbar) {
|
||||||
dickbar.style.display = 'none';
|
dickbar.style.display = 'none';
|
||||||
}
|
}
|
||||||
var footerDickbar = document.querySelector('footer > .container:first-child');
|
var footerDickbar = document.querySelector('footer > .container:first-child');
|
||||||
if (footerDickbar != null) {
|
if (footerDickbar) {
|
||||||
footerDickbar.style.display = 'none';
|
footerDickbar.style.display = 'none';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -29,14 +29,14 @@ var hideDickbar = function() {
|
|||||||
var disableLazyLoading = function() {
|
var disableLazyLoading = function() {
|
||||||
// Get all <noscript> tags accompanying dynamically-loading <img>s
|
// Get all <noscript> tags accompanying dynamically-loading <img>s
|
||||||
var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
|
var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
|
||||||
if (hiddenMedia == null) {
|
if (hiddenMedia.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (var i=0; i<hiddenMedia.length; i++) {
|
for (var i=0; i<hiddenMedia.length; i++) {
|
||||||
// Create new <img> element from the one in <noscript> and add it in.
|
// 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
|
// 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.
|
// spend more time reverse-engineering Medium's lazy-loading code.
|
||||||
var img = document.createElement('img');
|
var img = new Image();
|
||||||
var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
|
var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
|
||||||
if (srcMatch != null) {
|
if (srcMatch != null) {
|
||||||
img.src = srcMatch[1];
|
img.src = srcMatch[1];
|
||||||
@ -48,7 +48,7 @@ var disableLazyLoading = function() {
|
|||||||
|
|
||||||
var shrinkHeaderImages = function() {
|
var shrinkHeaderImages = function() {
|
||||||
var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
|
var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
|
||||||
if (ridiculousHeaderImage != null) {
|
if (ridiculousHeaderImage) {
|
||||||
ridiculousHeaderImage.style.maxWidth = '700px';
|
ridiculousHeaderImage.style.maxWidth = '700px';
|
||||||
ridiculousHeaderImage.style.margin = '0 auto';
|
ridiculousHeaderImage.style.margin = '0 auto';
|
||||||
}
|
}
|
||||||
@ -64,9 +64,7 @@ var observer = new MutationObserver(function(mutations){
|
|||||||
var config = {attributes: true};
|
var config = {attributes: true};
|
||||||
|
|
||||||
// Only run this on Medium sites.
|
// Only run this on Medium sites.
|
||||||
// Ensure that by checking for <meta property="al:ios:app_name" content="Medium"> in the document <head />
|
if (document.querySelector('head meta[property="al:ios:app_name"][content="medium"]')) {
|
||||||
var metaCheck = document.head.querySelector('meta[property="al:ios:app_name"]');
|
|
||||||
if (metaCheck != null && metaCheck.content == "Medium") {
|
|
||||||
makeReadable();
|
makeReadable();
|
||||||
shrinkHeaderImages();
|
shrinkHeaderImages();
|
||||||
|
|
||||||
@ -79,5 +77,5 @@ if (metaCheck != null && metaCheck.content == "Medium") {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe(document.querySelector('body'), config);
|
observer.observe(document.body, config);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user