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.
 
 
 

95 regels
2.7 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. // Inject remaining styles
  11. // This check makes sure the extension works on Chrome and Firefox.
  12. if (typeof browser === 'undefined') {
  13. browser = chrome;
  14. }
  15. document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" type="text/css" href="' + browser.runtime.getURL("medium.css") + '">');
  16. };
  17. var hideHighlightMenu = function() {
  18. var bar = document.querySelector('.highlightMenu');
  19. if (bar) {
  20. bar.style.display = 'none';
  21. }
  22. };
  23. var hideDickbar = function() {
  24. var dickbar = document.querySelector('.js-postShareWidget');
  25. if (dickbar) {
  26. dickbar.style.display = 'none';
  27. }
  28. var footerDickbar = document.querySelector('footer > .container:first-child');
  29. if (footerDickbar) {
  30. footerDickbar.style.display = 'none';
  31. }
  32. };
  33. var disableLazyLoading = function() {
  34. // Get all <noscript> tags accompanying dynamically-loading <img>s
  35. var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
  36. if (hiddenMedia.length === 0) {
  37. return;
  38. }
  39. for (var i=0; i<hiddenMedia.length; i++) {
  40. // Create new <img> element from the one in <noscript> and add it in.
  41. // This is certainly a roundabout way of doing things, but I didn't want to
  42. // spend more time reverse-engineering Medium's lazy-loading code.
  43. var img = new Image();
  44. var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
  45. if (srcMatch != null) {
  46. img.src = srcMatch[1];
  47. img.className = hiddenMedia[i].textContent.match(/class="([^"]+)"/)[1];
  48. hiddenMedia[i].parentNode.appendChild(img);
  49. }
  50. }
  51. };
  52. var shrinkHeaderImages = function() {
  53. var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
  54. if (ridiculousHeaderImage) {
  55. ridiculousHeaderImage.style.maxWidth = '700px';
  56. ridiculousHeaderImage.style.margin = '0 auto';
  57. }
  58. }
  59. var observer = new MutationObserver(function(mutations){
  60. mutations.forEach(function(){
  61. makeReadable();
  62. shrinkHeaderImages();
  63. });
  64. });
  65. var config = {attributes: true};
  66. // This extension runs on all domains so it can Make Medium Readable Again even for publications on custom domains.
  67. // Here we make sure the code only runs on Medium sites.
  68. if (document.querySelector('head meta[property="al:ios:app_name"][content="medium" i]')) {
  69. makeReadable();
  70. shrinkHeaderImages();
  71. chrome.storage.sync.get(null, function(items) {
  72. if (items.hideDickbar) {
  73. hideDickbar();
  74. }
  75. if (items.disableLazyImages) {
  76. disableLazyLoading();
  77. }
  78. if (items.hideHighlightMenu) {
  79. hideHighlightMenu();
  80. }
  81. });
  82. observer.observe(document.body, config);
  83. }