|
67 | 67 | {% block libs %} |
68 | 68 | <script src="{{ base_url }}/assets/javascripts/modernizr.js"></script> |
69 | 69 | {% endblock %} |
| 70 | + {% block disqus_ads %} |
| 71 | + <!--rm disqus ad refer to https://www.javaer101.com/article/25891160.html--> |
| 72 | + <script src="{{ base_url }}/assets/javascripts/jquery-latest.min.js"></script> |
| 73 | + <script> |
| 74 | + (function($){ |
| 75 | + setInterval(() => { |
| 76 | + $.each($('iframe'), (arr,x) => { |
| 77 | + let src = $(x).attr('src'); |
| 78 | + if (src && src.match(/(ads-iframe)|(disqusads)/gi)) { |
| 79 | + $(x).remove(); |
| 80 | + } |
| 81 | + let title = $(x).attr('title'); |
| 82 | + if (!src && title == "Disqus") { |
| 83 | + $(x).remove(); |
| 84 | + } |
| 85 | + }); |
| 86 | + }, 300); |
| 87 | + })(jQuery); |
| 88 | + </script> |
| 89 | + {% endblock %} |
70 | 90 | {% block disqus_js %} |
71 | 91 | {% if config.extra.disqus and not page.is_homepage %} |
72 | | - <!--rm disqus ad refer to https://www.javaer101.com/article/25891160.html--> |
73 | | - <script src="{{ base_url }}/assets/javascripts/jquery-latest.min.js"></script> |
74 | | - <script> |
75 | | - (function($){ |
76 | | - setInterval(() => { |
77 | | - $.each($('iframe'), (arr,x) => { |
78 | | - let src = $(x).attr('src'); |
79 | | - if (src && src.match(/(ads-iframe)|(disqusads)/gi)) { |
80 | | - $(x).remove(); |
81 | | - } |
82 | | - let title = $(x).attr('title'); |
83 | | - if (!src && title == "Disqus") { |
84 | | - $(x).remove(); |
85 | | - } |
86 | | - }); |
87 | | - }, 300); |
88 | | - })(jQuery); |
89 | | - </script> |
90 | 92 | {% endif %} |
91 | 93 | {% endblock %} |
92 | 94 | {% block fonts %} |
@@ -217,16 +219,6 @@ <h2 id="__source">{{ lang.t("meta.source") }}</h2> |
217 | 219 | {% endblock %} |
218 | 220 | {% block disqus_free %} |
219 | 221 | {% if config.extra.disqus and not page.is_homepage %} |
220 | | - <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> |
221 | | -<ins class="adsbygoogle" |
222 | | - style="display:block; text-align:center;" |
223 | | - data-ad-layout="in-article" |
224 | | - data-ad-format="fluid" |
225 | | - data-ad-client="ca-pub-3680148472128768" |
226 | | - data-ad-slot="6465742678"></ins> |
227 | | -<script> |
228 | | - (adsbygoogle = window.adsbygoogle || []).push({}); |
229 | | -</script> |
230 | 222 | <h2 id="__comments">{{ lang.t("meta.comments") }}</h2> |
231 | 223 | {% include "partials/integrations/disqus.html" %} |
232 | 224 | {% endif %} |
@@ -280,5 +272,43 @@ <h2 id="__comments">{{ lang.t("meta.comments") }}</h2> |
280 | 272 | {% include "partials/integrations/analytics.html" %} |
281 | 273 | {% endif %} |
282 | 274 | {% endblock %} |
| 275 | + <!--adjust disqus recommendation width (possibly occupied by ads)--> |
| 276 | + <script> |
| 277 | +// 确保在 DOM 完全加载后执行 |
| 278 | +document.addEventListener('DOMContentLoaded', function() { |
| 279 | + // 定义修复宽度的函数 |
| 280 | + function fixDisqusWidth() { |
| 281 | + const iframe = document.querySelector('#disqus_recommendations iframe'); |
| 282 | + if (iframe) { |
| 283 | + iframe.style.cssText += 'width: 100% !important; max-width: 100% !important;'; |
| 284 | + } |
| 285 | + } |
| 286 | + |
| 287 | + // 初次尝试修复 |
| 288 | + fixDisqusWidth(); |
| 289 | + |
| 290 | + // 监听 Disqus 容器的动态加载 |
| 291 | + const observer = new MutationObserver(function(mutations) { |
| 292 | + fixDisqusWidth(); |
| 293 | + }); |
| 294 | + |
| 295 | + // 获取 Disqus 容器 |
| 296 | + const targetNode = document.getElementById('disqus_recommendations'); |
| 297 | + if (targetNode) { |
| 298 | + // 如果容器已存在,直接监听 |
| 299 | + observer.observe(targetNode, { childList: true, subtree: true }); |
| 300 | + } else { |
| 301 | + // 如果容器未加载,监听整个文档直到其出现 |
| 302 | + const docObserver = new MutationObserver(function(mutations) { |
| 303 | + const lateTarget = document.getElementById('disqus_recommendations'); |
| 304 | + if (lateTarget) { |
| 305 | + observer.observe(lateTarget, { childList: true, subtree: true }); |
| 306 | + docObserver.disconnect(); |
| 307 | + } |
| 308 | + }); |
| 309 | + docObserver.observe(document.body, { childList: true, subtree: true }); |
| 310 | + } |
| 311 | +}); |
| 312 | + </script> |
283 | 313 | </body> |
284 | 314 | </html> |
0 commit comments