/
disqus-amp.html
98 lines (84 loc) · 2.78 KB
/
disqus-amp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Android Police Disqus for AMP</title>
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style>
html,
body {
margin: 0;
padding: 0;
}
body {
padding: 8px;
}
a {
color: #333
}
@media (prefers-color-scheme: dark) {
body {
background-color: #232323;
}
a {
color: #e0e0e0;
}
}
</style>
</head>
<body onresize="postHeight()">
<div id="disqus_thread"></div>
<script>
var post_message = {
sentinel: 'amp',
type: 'embed-size',
height: 340
};
function postHeight() {
var new_height = document.getElementById('disqus_thread').scrollHeight;
if (new_height > 340) {
post_message.height = new_height;
}
window.parent.postMessage(post_message, '*');
}
postHeight();
window.addEventListener('message', postHeight);
function getQueryVariable(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function generateCss(q) {
var css = document.createElement('style'),
sp2 = document.getElementById('disqus_thread'),
parentDiv = sp2.parentNode;
css.type = 'text/css';
if (css.styleSheet) css.styleSheet.cssText = q;
else css.appendChild(document.createTextNode(q));
parentDiv.insertBefore(css, sp2);
}
var disqus_config = function () {
this.page.url = getQueryVariable('url');
this.page.identifier = getQueryVariable('identifier');
this.callbacks.onReady.push(function (e) {
postHeight();
});
if (getQueryVariable('scroll_user') == 'scroll') {
this.disable_ads = true;
}
};
(function () {
var d = document,
s = d.createElement('script'),
q = '#disqus_thread {font-family:' + getQueryVariable('fontBodyFamily') + '}';
generateCss(q);
s.src = '//' + getQueryVariable('shortname') + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (evt) {
// reload page when user changes color scheme
location.reload();
});
</script>
</body>
</html>