Skip to content

Commit 99dc98d

Browse files
committed
event
1 parent 9213a3e commit 99dc98d

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

Writerside/cfg/head-script.html

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,47 @@
1818
<meta name="keywords" content="Simple Robot, simbot, Simple Robot 4, simbot4, Java, Java11, Kotlin, Kotlin Multiplatform, KMP, Kotlin JVM, Simple Robot v4, bot, forte, ForteScarlet, 法欧特斯卡雷特, 法欧特">
1919

2020
<script>
21+
function _addIns(then) {
22+
const elements = document.getElementsByTagName('article');
23+
if (elements && elements.length > 0) {
24+
const article = elements[0];
25+
const insDiv = document.createElement('div');
26+
insDiv.setAttribute('class', 'ins_div');
27+
const ins = document.createElement('ins');
28+
ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
29+
/*ins.setAttribute('style', 'display:block');*/
30+
ins.style.display = 'block';
31+
ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
32+
ins.setAttribute('data-ad-slot', 'auto');
33+
ins.setAttribute('data-full-width-responsive', 'true');
34+
insDiv.appendChild(ins);
35+
article.appendChild(insDiv);
36+
then();
37+
}
38+
}
39+
function _pushAd(log) {
40+
(adsbygoogle = window.adsbygoogle || []).push({});
41+
console.log('adsbygoogle pushed: ', log || '(NULL)');
42+
}
43+
2144
/*横向广告*/
45+
if (/Mobi|Android|iPhone/i.test(navigator.userAgent)) {
46+
// 当前设备是移动设备
47+
// https://www.ruanyifeng.com/blog/2021/09/detecting-mobile-browser.html
48+
window.onload=(event)=>{
49+
_addIns(() => {
50+
_pushAd('after ins append.');
51+
});
52+
};
53+
} else {
2254
document.addEventListener("DOMContentLoaded", (event) => {
2355
try {
24-
const elements = document.getElementsByTagName('article');
25-
if (elements && elements.length > 0) {
26-
const article = elements[0];
27-
const insDiv = document.createElement('div');
28-
insDiv.setAttribute('class', 'ins_div');
29-
const ins = document.createElement('ins');
30-
ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
31-
/*ins.setAttribute('style', 'display:block');*/
32-
ins.style.display = 'block';
33-
ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
34-
ins.setAttribute('data-ad-slot', 'auto');
35-
ins.setAttribute('data-full-width-responsive', 'true');
36-
insDiv.appendChild(ins);
37-
article.appendChild(insDiv);
38-
// in loaded
39-
try {
40-
window.addEventListener('load',(event) => {
41-
(adsbygoogle = window.adsbygoogle || []).push({});
42-
console.log('adsbygoogle pushed after loaded.');
56+
_addIns(() => {
57+
window.addEventListener('load',(event) => {
58+
_pushAd('on event `load`');
4359
});
44-
} catch(e) {
45-
(adsbygoogle = window.adsbygoogle || []).push({});
46-
console.log('adsbygoogle pushed in DOMContentLoaded.');
47-
}
48-
}
60+
});
4961
} catch(e) {console.log(e);}
5062
});
51-
//window.onload=function () {
52-
//try {
53-
//const elements = document.getElementsByTagName('article');
54-
//if (elements && elements.length > 0) {
55-
// const article = elements[0];
56-
// const insDiv = document.createElement('div');
57-
// insDiv.setAttribute('class', 'ins_div');
58-
// const ins = document.createElement('ins');
59-
// ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
60-
// /*ins.setAttribute('style', 'display:block');*/
61-
// ins.style.display = 'block';
62-
// ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
63-
// ins.setAttribute('data-ad-slot', 'auto');
64-
// ins.setAttribute('data-full-width-responsive', 'true');
65-
// insDiv.appendChild(ins);
66-
// article.appendChild(insDiv);
67-
// (adsbygoogle = window.adsbygoogle || []).push({});
68-
// console.log('adsbygoogle pushed.');
69-
//}
70-
//} catch(e) {console.log(e);}
71-
//};
63+
}
7264
</script>

0 commit comments

Comments
 (0)