Skip to content

Commit 60f5939

Browse files
authored
[Doc] Optimize doc ad show (DataLinkDC#4358)
1 parent c8fecc0 commit 60f5939

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

docs/sidebars.js

+26-12
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,33 @@
3030

3131
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
3232
const sidebars = {
33-
// By default, Docusaurus generates a sidebar from the docs folder structure
34-
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
33+
// By default, Docusaurus generates a sidebar from the docs folder structure
34+
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}, {
35+
type: 'html',
36+
value: `<div>
37+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3727048951544938"
38+
crossorigin="anonymous" data-checked-head="true"></script>
39+
<ins class="adsbygoogle"
40+
style="display:block;height: 600px"
41+
data-ad-client="ca-pub-3727048951544938"
42+
data-ad-slot="2720872962"
43+
data-full-width-responsive="true" ></ins>
44+
<script>
45+
(adsbygoogle = window.adsbygoogle || []).push({});
46+
</script>
47+
</div>`, // The HTML to be rendered
48+
},],
3549

36-
// But you can create a sidebar manually
37-
/*
38-
tutorialSidebar: [
39-
{
40-
type: 'category',
41-
label: 'Tutorial',
42-
items: ['hello'],
43-
},
44-
],
45-
*/
50+
// But you can create a sidebar manually
51+
/*
52+
tutorialSidebar: [
53+
{
54+
type: 'category',
55+
label: 'Tutorial',
56+
items: ['hello'],
57+
},
58+
],
59+
*/
4660
};
4761

4862
module.exports = sidebars;

docs/src/pages/index.less

+3
Original file line numberDiff line numberDiff line change
@@ -16267,3 +16267,6 @@ section {
1626716267
width: 100%; }
1626816268

1626916269
/*# sourceMappingURL=quick-website.css.map */
16270+
.col--3{
16271+
z-index: 1;
16272+
}

docs/src/plugin/wwads-plugin.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,26 @@ module.exports = function myPlugin(context, options) {
33
name: 'wwads-plugin',
44
injectHtmlTags() {
55
return {
6-
preBodyTags: [`<div class="wwads-cn wwads-vertical wwads-sticky" data-id="312" style="max-width:180px;position:fixed;bottom:0;right:0"></div>`],
6+
// preBodyTags: [`<div class="wwads-cn wwads-vertical wwads-sticky" data-id="312" style="max-width:180px;position:fixed;bottom:0;right:0"></div>`],
7+
preBodyTags: [``],
78
postBodyTags: [`
89
<script>
9-
// function called if wwads is blocked
10-
function ABDetected() {
11-
document.getElementsByClassName("wwads-cn")[0].insertAdjacentHTML("beforeend", "<style>.wwads-horizontal,.wwads-vertical{background-color:#f4f8fa;padding:5px;min-height:120px;margin-top:20px;box-sizing:border-box;border-radius:3px;font-family:sans-serif;display:flex;min-width:150px;position:relative;overflow:hidden;}.wwads-horizontal{flex-wrap:wrap;justify-content:center}.wwads-vertical{flex-direction:column;align-items:center;padding-bottom:32px}.wwads-horizontal a,.wwads-vertical a{text-decoration:none}.wwads-horizontal .wwads-img,.wwads-vertical .wwads-img{margin:5px}.wwads-horizontal .wwads-content,.wwads-vertical .wwads-content{margin:5px}.wwads-horizontal .wwads-content{flex:130px}.wwads-vertical .wwads-content{margin-top:10px}.wwads-horizontal .wwads-text,.wwads-content .wwads-text{font-size:14px;line-height:1.4;color:#0e1011;-webkit-font-smoothing:antialiased}.wwads-horizontal .wwads-poweredby,.wwads-vertical .wwads-poweredby{display:block;font-size:11px;color:#a6b7bf;margin-top:1em}.wwads-vertical .wwads-poweredby{position:absolute;left:10px;bottom:10px}.wwads-horizontal .wwads-poweredby span,.wwads-vertical .wwads-poweredby span{transition:all 0.2s ease-in-out;margin-left:-1em}.wwads-horizontal .wwads-poweredby span:first-child,.wwads-vertical .wwads-poweredby span:first-child{opacity:0}.wwads-horizontal:hover .wwads-poweredby span,.wwads-vertical:hover .wwads-poweredby span{opacity:1;margin-left:0}.wwads-horizontal .wwads-hide,.wwads-vertical .wwads-hide{position:absolute;right:-23px;bottom:-23px;width:46px;height:46px;border-radius:23px;transition:all 0.3s ease-in-out;cursor:pointer;}.wwads-horizontal .wwads-hide:hover,.wwads-vertical .wwads-hide:hover{background:rgb(0 0 0 /0.05)}.wwads-horizontal .wwads-hide svg,.wwads-vertical .wwads-hide svg{position:absolute;left:10px;top:10px;fill:#a6b7bf}.wwads-horizontal .wwads-hide:hover svg,.wwads-vertical .wwads-hide:hover svg{fill:#3E4546}</style><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-img' target='_blank' rel='nofollow'><img src='https://creatives-1301677708.file.myqcloud.com/images/placeholder/wwads-friendly-ads.png' width='130'></a><div class='wwads-content'><a href='https://wwads.cn/page/whitelist-wwads' class='wwads-text' target='_blank' rel='nofollow'>为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!</a><a href='https://wwads.cn/page/end-user-privacy' class='wwads-poweredby' title='万维广告 ~ 让广告更优雅,且有用' target='_blank'><span>万维</span><span>广告</span></a></div><a class='wwads-hide' onclick='parentNode.remove()' title='隐藏广告'><svg xmlns='http://www.w3.org/2000/svg' width='6' height='7'><path d='M.879.672L3 2.793 5.121.672a.5.5 0 11.707.707L3.708 3.5l2.12 2.121a.5.5 0 11-.707.707l-2.12-2.12-2.122 2.12a.5.5 0 11-.707-.707l2.121-2.12L.172 1.378A.5.5 0 01.879.672z'></path></svg></a>");
12-
};
1310
14-
//check document ready
15-
function docReady(t) {
16-
"complete" === document.readyState ||
17-
"interactive" === document.readyState
18-
? setTimeout(t, 1)
19-
: document.addEventListener("DOMContentLoaded", t);
11+
function handleUrlChange(){
12+
const targetDiv = document.querySelector('div.col.col--3');
13+
const wwadsDiv = document.querySelector('div.col.col--3').querySelector("div.wwads-cn");
14+
if (targetDiv&&!wwadsDiv) {
15+
targetDiv.insertAdjacentHTML('beforeend', '<div class="wwads-cn wwads-horizontal" data-id="312" style="min-height: 0px; border: 1px #eee solid; margin-bottom: 12px; z-index: 1; position: fixed"></div>');
16+
}
2017
}
21-
22-
//check if wwads' fire function was blocked after document is ready with 3s timeout (waiting the ad loading)
23-
docReady(function () {
24-
setTimeout(function () {
25-
if( window._AdBlockInit === undefined ){
26-
ABDetected();
27-
}
28-
}, 3000);
18+
const observer = new MutationObserver(() => {
19+
try {
20+
handleUrlChange()
21+
}catch (e) {
22+
23+
}
2924
});
25+
observer.observe(document, { subtree: true, childList: true });
3026
</script>
3127
`],
3228

docs/static/img/ads.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google.com, pub-3727048951544938, DIRECT, f08c47fec0942fa0

0 commit comments

Comments
 (0)