Make Medium Readable Again https://makemediumreadable.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

83 line
2.4 KiB

  1. //
  2. // Make Medium Readable Again
  3. //
  4. var makeReadable = function() {
  5. // Un-position:fixed the top nav bar
  6. var topNav = document.querySelector('.metabar.u-fixed');
  7. if (topNav) {
  8. topNav.classList.remove('u-fixed');
  9. }
  10. // Remove the footer
  11. var getUpdatesBar = document.querySelector('.js-stickyFooter');
  12. if (getUpdatesBar) {
  13. getUpdatesBar.style.display = 'none';
  14. }
  15. };
  16. var hideDickbar = function() {
  17. var dickbar = document.querySelector('.js-postShareWidget');
  18. if (dickbar) {
  19. dickbar.style.display = 'none';
  20. }
  21. var footerDickbar = document.querySelector('footer > .container:first-child');
  22. if (footerDickbar) {
  23. footerDickbar.style.display = 'none';
  24. }
  25. };
  26. var disableLazyLoading = function() {
  27. // Get all <noscript> tags accompanying dynamically-loading <img>s
  28. var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
  29. if (hiddenMedia.length === 0) {
  30. return;
  31. }
  32. for (var i=0; i<hiddenMedia.length; i++) {
  33. // Create new <img> element from the one in <noscript> and add it in.
  34. // This is certainly a roundabout way of doing things, but I didn't want to
  35. // spend more time reverse-engineering Medium's lazy-loading code.
  36. var img = new Image();
  37. var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
  38. if (srcMatch != null) {
  39. img.src = srcMatch[1];
  40. img.className = hiddenMedia[i].textContent.match(/class="([^"]+)"/)[1];
  41. hiddenMedia[i].parentNode.appendChild(img);
  42. }
  43. }
  44. };
  45. var shrinkHeaderImages = function() {
  46. var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
  47. if (ridiculousHeaderImage) {
  48. ridiculousHeaderImage.style.maxWidth = '700px';
  49. ridiculousHeaderImage.style.margin = '0 auto';
  50. }
  51. }
  52. var observer = new MutationObserver(function(mutations){
  53. mutations.forEach(function(){
  54. makeReadable();
  55. shrinkHeaderImages();
  56. });
  57. });
  58. var config = {attributes: true};
  59. // This extension runs on all domains so it can Make Medium Readable Again even for publications on custom domains.
  60. // Here we make sure the code only runs on Medium sites.
  61. if (document.querySelector('head meta[property="al:ios:app_name"][content="medium" i]')) {
  62. makeReadable();
  63. shrinkHeaderImages();
  64. chrome.storage.sync.get(null, function(items) {
  65. if (items.hideDickbar) {
  66. hideDickbar();
  67. }
  68. if (items.disableLazyImages) {
  69. disableLazyLoading();
  70. }
  71. });
  72. observer.observe(document.body, config);
  73. }