Skip to content

Commit 9b5c3a2

Browse files
committedJun 29, 2018
Add basic safari support
1 parent 8cab920 commit 9b5c3a2

File tree

7 files changed

+180
-0
lines changed

7 files changed

+180
-0
lines changed
 

‎MMRA.safariextension/Icon-32.png

1.19 KB
Loading

‎MMRA.safariextension/Icon-48.png

2.13 KB
Loading

‎MMRA.safariextension/Icon-64.png

2.02 KB
Loading

‎MMRA.safariextension/Info.plist

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Author</key>
6+
<string>Matt Baer</string>
7+
<key>Builder Version</key>
8+
<string>12605.2.8</string>
9+
<key>CFBundleDisplayName</key>
10+
<string>Make Medium Readable Again</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>com.abunchtell.mmra</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.5</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
<key>Content</key>
20+
<dict>
21+
<key>Scripts</key>
22+
<dict>
23+
<key>Start</key>
24+
<array>
25+
<string>content.js</string>
26+
</array>
27+
</dict>
28+
<key>Stylesheets</key>
29+
<array>
30+
<string>medium.css</string>
31+
</array>
32+
</dict>
33+
<key>Description</key>
34+
<string>Make Medium less annoying</string>
35+
<key>DeveloperIdentifier</key>
36+
<string>TPPAB4YBA6</string>
37+
<key>ExtensionInfoDictionaryVersion</key>
38+
<string>1.0</string>
39+
<key>Permissions</key>
40+
<dict>
41+
<key>Website Access</key>
42+
<dict>
43+
<key>Include Secure Pages</key>
44+
<true/>
45+
<key>Level</key>
46+
<string>All</string>
47+
</dict>
48+
</dict>
49+
<key>Website</key>
50+
<string>https://github.com/thebaer/MMRA</string>
51+
</dict>
52+
</plist>

‎MMRA.safariextension/Settings.plist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<array/>
5+
</plist>

‎MMRA.safariextension/content.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// Make Medium Readable Again
3+
//
4+
5+
var makeReadable = function() {
6+
// Un-position:fixed the top nav bar
7+
var topNav = document.querySelector('.metabar.u-fixed');
8+
if (topNav) {
9+
topNav.classList.remove('u-fixed');
10+
}
11+
12+
// Remove the "Pardon the interruption" popup.
13+
// We do this with JS because the .overlay.overlay--lighter element is used
14+
// for interactions we consent to, like the sign up / log in dialogs, so we
15+
// don't want to obliterate them too.
16+
// FIXME: prevent this from breaking signup/login dialogs when the popup
17+
// is removed (it works after changing pages).
18+
var headings = document.evaluate("//h1[contains(., 'Pardon the interruption.')]", document, null, XPathResult.ANY_TYPE, null );
19+
var thisHeading = headings.iterateNext();
20+
if (thisHeading != null) {
21+
var $overlay = thisHeading.parentNode.parentNode.parentNode.parentNode;
22+
$overlay.parentNode.removeChild($overlay);
23+
}
24+
25+
// Inject remaining styles
26+
// This check makes sure the extension works on Chrome and Firefox.
27+
if (typeof browser === 'undefined') {
28+
browser = chrome;
29+
}
30+
document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" type="text/css" href="' + browser.runtime.getURL("medium.css") + '">');
31+
};
32+
33+
var hideHighlightMenu = function() {
34+
var bar = document.querySelector('.highlightMenu');
35+
if (bar) {
36+
bar.style.display = 'none';
37+
}
38+
};
39+
40+
var hideDickbar = function() {
41+
var dickbar = document.querySelector('.js-postShareWidget');
42+
if (dickbar) {
43+
dickbar.style.display = 'none';
44+
}
45+
var footerDickbar = document.querySelector('footer > .container:first-child');
46+
if (footerDickbar) {
47+
footerDickbar.style.display = 'none';
48+
}
49+
};
50+
51+
var disableLazyLoading = function() {
52+
// Get all <noscript> tags accompanying dynamically-loading <img>s
53+
var hiddenMedia = document.querySelectorAll('noscript.js-progressiveMedia-inner');
54+
if (hiddenMedia.length === 0) {
55+
return;
56+
}
57+
for (var i=0; i<hiddenMedia.length; i++) {
58+
// Create new <img> element from the one in <noscript> and add it in.
59+
// This is certainly a roundabout way of doing things, but I didn't want to
60+
// spend more time reverse-engineering Medium's lazy-loading code.
61+
var img = new Image();
62+
var srcMatch = hiddenMedia[i].textContent.match(/src="(https:\/\/[^"]+)"/);
63+
if (srcMatch != null) {
64+
img.src = srcMatch[1];
65+
img.className = hiddenMedia[i].textContent.match(/class="([^"]+)"/)[1];
66+
hiddenMedia[i].parentNode.appendChild(img);
67+
}
68+
}
69+
};
70+
71+
var shrinkHeaderImages = function() {
72+
var ridiculousHeaderImage = document.querySelector('figure.graf--layoutFillWidth');
73+
if (ridiculousHeaderImage) {
74+
ridiculousHeaderImage.style.maxWidth = '700px';
75+
ridiculousHeaderImage.style.margin = '0 auto';
76+
}
77+
}
78+
79+
var observer = new MutationObserver(function(mutations){
80+
mutations.forEach(function(){
81+
makeReadable();
82+
shrinkHeaderImages();
83+
});
84+
});
85+
86+
var config = {attributes: true};
87+
88+
// This extension runs on all domains so it can Make Medium Readable Again even for publications on custom domains.
89+
// Here we make sure the code only runs on Medium sites.
90+
if (document.querySelector('head meta[property="al:ios:app_name"][content="medium" i]')) {
91+
makeReadable();
92+
shrinkHeaderImages();
93+
94+
chrome.storage.sync.get(null, function(items) {
95+
if (items.hideDickbar) {
96+
hideDickbar();
97+
}
98+
if (items.disableLazyImages) {
99+
disableLazyLoading();
100+
}
101+
if (items.hideHighlightMenu) {
102+
hideHighlightMenu();
103+
}
104+
});
105+
106+
observer.observe(document.body, config);
107+
}

‎MMRA.safariextension/medium.css

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* medium.css
3+
* Contains default styles to inject into Medium publications.
4+
*/
5+
.postMeterBar,
6+
.openInAppButton,
7+
.js-stickyFooter,
8+
.js-upgradeMembershipAction,
9+
.butterBar--privacy {
10+
display: none;
11+
}
12+
13+
/* Makes the page scrollable after hiding "Pardon the interruption" popup */
14+
html.u-overflowHidden {
15+
overflow-y: scroll !important;
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.