docsify-plugin-google-adsense 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +23 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
(function (window) {
|
|
2
2
|
window.DocsifyAds = {
|
|
3
|
-
create(caPub) {
|
|
3
|
+
create(caPub, slot) {
|
|
4
4
|
return function (hook, vm) {
|
|
5
5
|
hook.ready(function () {
|
|
6
|
-
window.DocsifyAds.
|
|
6
|
+
window.DocsifyAds.injectCarbonStyle();
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
hook.doneEach(function () {
|
|
10
|
-
window.DocsifyAds.injectScript(caPub);
|
|
10
|
+
window.DocsifyAds.injectScript(caPub, slot);
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
},
|
|
14
14
|
|
|
15
|
-
injectScript(caPub) {
|
|
15
|
+
injectScript(caPub, slot) {
|
|
16
16
|
const adEl = document.querySelector("#adsense");
|
|
17
17
|
const scriptID = "_adsense_js";
|
|
18
18
|
const sidebarEl = document.querySelector(".sidebar-nav");
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
if (!adEl && sidebarEl) {
|
|
21
22
|
let scriptEl = document.querySelector(`#${scriptID}`);
|
|
23
|
+
let scriptIns = document.querySelector(`#${scriptID}`);
|
|
24
|
+
let scriptAdPush = document.querySelector(`#${scriptID}`);
|
|
22
25
|
|
|
23
26
|
if (scriptEl) {
|
|
24
27
|
scriptEl = scriptEl.parentNode.removeChild(scriptEl);
|
|
@@ -27,24 +30,36 @@
|
|
|
27
30
|
scriptEl.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${caPub}`;
|
|
28
31
|
scriptEl.async = "async";
|
|
29
32
|
scriptEl.id = scriptID;
|
|
33
|
+
scriptEl.crossOrigin = "anonymous";
|
|
34
|
+
|
|
35
|
+
scriptIns = document.createElement("ins");
|
|
36
|
+
scriptIns.className = `adsbygoogle`;
|
|
37
|
+
scriptIns.style = 'display:inline-block;width:300px;height:150px';
|
|
38
|
+
scriptIns.setAttribute("data-ad-client", `${caPub}`);
|
|
39
|
+
scriptIns.setAttribute("data-ad-slot", `${slot}`);
|
|
40
|
+
|
|
41
|
+
scriptAdPush = document.createElement("script");
|
|
42
|
+
scriptAdPush.text = "(adsbygoogle = window.adsbygoogle || []).push({});";
|
|
43
|
+
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
sidebarEl.insertBefore(scriptEl, sidebarEl.firstChild);
|
|
47
|
+
sidebarEl.insertBefore(scriptIns, sidebarEl.lastChild);
|
|
48
|
+
sidebarEl.insertBefore(scriptAdPush, sidebarEl.lastChild);
|
|
33
49
|
}
|
|
34
50
|
},
|
|
35
51
|
|
|
36
|
-
|
|
52
|
+
injectCarbonStyle() {
|
|
37
53
|
const styleEl = document.createElement("style");
|
|
38
54
|
|
|
39
55
|
styleEl.textContent = `
|
|
40
|
-
#
|
|
56
|
+
#carbonads * {
|
|
41
57
|
margin: initial;
|
|
42
58
|
padding: initial;
|
|
43
59
|
}
|
|
44
|
-
|
|
45
60
|
`;
|
|
46
61
|
|
|
47
62
|
document.head.insertBefore(styleEl, document.querySelector("head style, head link[rel*='stylesheet']"));
|
|
48
63
|
},
|
|
49
64
|
};
|
|
50
|
-
})(window);
|
|
65
|
+
})(window);
|
package/package.json
CHANGED