Skip to content

Commit 7096af5

Browse files
committed
Revert "adsense改注入"
This reverts commit f2b83f4.
1 parent 041fea6 commit 7096af5

4 files changed

Lines changed: 186 additions & 27 deletions

File tree

docs/javascripts/adsense.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,13 @@
77
var HOME_PATHS = new Set(['/', '/zh/', '/en/', '/es/', '/ar/']);
88
var HOME_TITLES = new Set(['Home', "Power's Wiki"]);
99
var ADSENSE_SCRIPT_SELECTOR = 'script[src*="pagead/js/adsbygoogle.js"]';
10-
var STYLE_ID = 'adsense-inline-style';
11-
var STYLE_CONTENT = `
12-
.adsense-container{margin:1rem 0;padding:.5rem;text-align:center;background:transparent;border:0;box-shadow:none;transition:opacity .3s ease;}
13-
.adsense-container.hidden,.adsense-container.error,.adsense-container[style*='display: none']{display:none!important;margin:0!important;padding:0!important;height:0!important;width:0!important;overflow:hidden!important;opacity:0!important;visibility:hidden!important;position:absolute!important;left:-9999px!important;top:-9999px!important;pointer-events:none!important;}
14-
.adsense-container.hidden *,.adsense-container[style*='display: none'] *{display:none!important;}
15-
.adsense-container ins.adsbygoogle{display:block!important;width:100%;border:0;min-height:auto;}
16-
[data-md-color-scheme='slate'] .adsense-container{background:transparent;border:0;box-shadow:none;}
17-
.adsense-container.loading{opacity:.7;}
18-
.adsense-container.loaded{opacity:1;}
19-
@media(max-width:768px){.adsense-container{margin:.75rem 0;padding:.25rem;}}
20-
`
21-
22-
function ensureStyles() {
23-
if (document.getElementById(STYLE_ID)) {
24-
return;
25-
}
26-
var style = document.createElement('style');
27-
style.id = STYLE_ID;
28-
style.textContent = STYLE_CONTENT;
29-
document.head.appendChild(style);
30-
}
31-
3210

3311
if (!AD_SLOT) {
3412
console.warn('[AdSense] Missing data-ad-slot id. Set window.ADSENSE_SLOT_ID before this script runs.');
3513
return;
3614
}
3715

3816
document.addEventListener('DOMContentLoaded', function() {
39-
ensureStyles();
4017
if (isHomePage()) {
4118
return;
4219
}

docs/javascripts/test-adsense.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@
5656
}
5757

5858
function testStyles() {
59-
const inlineStyle = document.getElementById('adsense-inline-style');
59+
const styleSheets = Array.from(document.styleSheets);
60+
const adsenseStyle = styleSheets.find(sheet =>
61+
sheet.href && sheet.href.includes('adsense.css')
62+
);
6063

61-
if (inlineStyle) {
62-
debugLog('✅ AdSense样式已注入');
64+
if (adsenseStyle) {
65+
debugLog('✅ AdSense样式已加载');
6366
return true;
6467
}
6568

66-
console.warn('⚠️ AdSense样式未注入');
69+
console.warn('❌ AdSense样式未加载');
6770
return false;
6871
}
6972

docs/stylesheets/adsense.css

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/* AdSense广告样式 - 优化版本 */
2+
.adsense-container {
3+
margin: 1rem 0;
4+
padding: 0.5rem;
5+
text-align: center;
6+
background: transparent;
7+
border: none;
8+
box-shadow: none;
9+
transition: opacity 0.3s ease;
10+
}
11+
12+
.adsense-container.hidden {
13+
display: none !important;
14+
margin: 0 !important;
15+
padding: 0 !important;
16+
height: 0 !important;
17+
min-height: 0 !important;
18+
max-height: 0 !important;
19+
width: 0 !important;
20+
min-width: 0 !important;
21+
max-width: 0 !important;
22+
overflow: hidden !important;
23+
opacity: 0 !important;
24+
visibility: hidden !important;
25+
position: absolute !important;
26+
left: -9999px !important;
27+
top: -9999px !important;
28+
z-index: -9999 !important;
29+
pointer-events: none !important;
30+
user-select: none !important;
31+
transform: scale(0) !important;
32+
}
33+
34+
/* 强制隐藏iframe - 确保iframe不占用空间 */
35+
.adsense-container.hidden iframe {
36+
display: none !important;
37+
width: 0 !important;
38+
height: 0 !important;
39+
border: none !important;
40+
margin: 0 !important;
41+
padding: 0 !important;
42+
overflow: hidden !important;
43+
position: absolute !important;
44+
left: -9999px !important;
45+
top: -9999px !important;
46+
z-index: -9999 !important;
47+
pointer-events: none !important;
48+
visibility: hidden !important;
49+
opacity: 0 !important;
50+
transform: scale(0) !important;
51+
clip: rect(0, 0, 0, 0) !important;
52+
}
53+
54+
/* 强制隐藏iframe内部的body元素 */
55+
.adsense-container.hidden iframe[src*="googlesyndication"] {
56+
display: none !important;
57+
width: 0 !important;
58+
height: 0 !important;
59+
}
60+
61+
.adsense-ad {
62+
position: relative;
63+
text-align: center;
64+
min-height: auto;
65+
display: block;
66+
}
67+
68+
.adsense-label {
69+
display: none; /* 隐藏广告标签 */
70+
}
71+
72+
/* 确保广告在内容流中正确显示 */
73+
.adsense-container ins.adsbygoogle {
74+
display: block !important;
75+
width: 100%;
76+
height: auto;
77+
min-height: auto;
78+
border: none;
79+
overflow: visible;
80+
}
81+
82+
/* 响应式设计 - 保持简洁 */
83+
@media (max-width: 768px) {
84+
.adsense-container {
85+
margin: 0.75rem 0;
86+
padding: 0.25rem;
87+
}
88+
}
89+
90+
/* 暗色模式适配 - 保持透明 */
91+
[data-md-color-scheme="slate"] .adsense-container {
92+
background: transparent;
93+
border: none;
94+
box-shadow: none;
95+
}
96+
97+
/* 广告加载失败时完全隐藏 */
98+
.adsense-ad.error {
99+
display: none;
100+
}
101+
102+
/* 确保广告不会影响页面布局 */
103+
.adsense-container {
104+
overflow: visible;
105+
word-wrap: normal;
106+
}
107+
108+
/* 加载状态样式 */
109+
.adsense-container.loading {
110+
opacity: 0.7;
111+
}
112+
113+
/* 广告加载完成后的样式 */
114+
.adsense-container.loaded {
115+
opacity: 1;
116+
}
117+
118+
/* 强制隐藏状态 - 最高优先级 */
119+
.adsense-container[style*="display: none"] {
120+
display: none !important;
121+
margin: 0 !important;
122+
padding: 0 !important;
123+
height: 0 !important;
124+
min-height: 0 !important;
125+
max-height: 0 !important;
126+
width: 0 !important;
127+
min-width: 0 !important;
128+
max-width: 0 !important;
129+
overflow: hidden !important;
130+
opacity: 0 !important;
131+
visibility: hidden !important;
132+
position: absolute !important;
133+
left: -9999px !important;
134+
top: -9999px !important;
135+
z-index: -9999 !important;
136+
pointer-events: none !important;
137+
user-select: none !important;
138+
transform: scale(0) !important;
139+
}
140+
141+
/* 强制隐藏iframe - 最高优先级 */
142+
.adsense-container[style*="display: none"] iframe {
143+
display: none !important;
144+
width: 0 !important;
145+
height: 0 !important;
146+
border: none !important;
147+
margin: 0 !important;
148+
padding: 0 !important;
149+
overflow: hidden !important;
150+
position: absolute !important;
151+
left: -9999px !important;
152+
top: -9999px !important;
153+
z-index: -9999 !important;
154+
pointer-events: none !important;
155+
visibility: hidden !important;
156+
opacity: 0 !important;
157+
transform: scale(0) !important;
158+
clip: rect(0, 0, 0, 0) !important;
159+
}
160+
161+
/* 特殊处理:隐藏所有可能的AdSense相关元素 */
162+
.adsense-container.hidden *,
163+
.adsense-container[style*="display: none"] * {
164+
display: none !important;
165+
width: 0 !important;
166+
height: 0 !important;
167+
margin: 0 !important;
168+
padding: 0 !important;
169+
overflow: hidden !important;
170+
position: absolute !important;
171+
left: -9999px !important;
172+
top: -9999px !important;
173+
z-index: -9999 !important;
174+
pointer-events: none !important;
175+
visibility: hidden !important;
176+
opacity: 0 !important;
177+
transform: scale(0) !important;
178+
}

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,4 @@ extra_javascript:
286286

287287
extra_css:
288288
- stylesheets/extra.css
289+
- stylesheets/adsense.css

0 commit comments

Comments
 (0)