Update changs to create new for plugin
This commit is contained in:
@@ -1,24 +1,27 @@
|
|||||||
(function (window) {
|
(function (window) {
|
||||||
window.DocsifyAds = {
|
window.DocsifyAds = {
|
||||||
create(caPub) {
|
create(caPub, slot) {
|
||||||
return function (hook, vm) {
|
return function (hook, vm) {
|
||||||
hook.ready(function () {
|
hook.ready(function () {
|
||||||
window.DocsifyAds.injectStyle();
|
window.DocsifyAds.injectCarbonStyle();
|
||||||
});
|
});
|
||||||
|
|
||||||
hook.doneEach(function () {
|
hook.doneEach(function () {
|
||||||
window.DocsifyAds.injectScript(caPub);
|
window.DocsifyAds.injectScript(caPub, slot);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
injectScript(caPub) {
|
injectScript(caPub, slot) {
|
||||||
const adEl = document.querySelector("#adsense");
|
const adEl = document.querySelector("#adsense");
|
||||||
const scriptID = "_adsense_js";
|
const scriptID = "_adsense_js";
|
||||||
const sidebarEl = document.querySelector(".sidebar-nav");
|
const sidebarEl = document.querySelector(".sidebar-nav");
|
||||||
|
|
||||||
|
|
||||||
if (!adEl && sidebarEl) {
|
if (!adEl && sidebarEl) {
|
||||||
let scriptEl = document.querySelector(`#${scriptID}`);
|
let scriptEl = document.querySelector(`#${scriptID}`);
|
||||||
|
let scriptIns = document.querySelector(`#${scriptID}`);
|
||||||
|
let scriptAdPush = document.querySelector(`#${scriptID}`);
|
||||||
|
|
||||||
if (scriptEl) {
|
if (scriptEl) {
|
||||||
scriptEl = scriptEl.parentNode.removeChild(scriptEl);
|
scriptEl = scriptEl.parentNode.removeChild(scriptEl);
|
||||||
@@ -27,21 +30,33 @@
|
|||||||
scriptEl.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${caPub}`;
|
scriptEl.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${caPub}`;
|
||||||
scriptEl.async = "async";
|
scriptEl.async = "async";
|
||||||
scriptEl.id = scriptID;
|
scriptEl.id = scriptID;
|
||||||
|
scriptEl.crossOrigin = "anonymous";
|
||||||
|
|
||||||
|
scriptIns = document.createElement("ins");
|
||||||
|
scriptIns.className = `adsbygoogle`;
|
||||||
|
scriptIns.style = 'display:inline-block;width:300px;height:150px';
|
||||||
|
scriptIns.setAttribute("data-ad-client", `${caPub}`);
|
||||||
|
scriptIns.setAttribute("data-ad-slot", `${slot}`);
|
||||||
|
|
||||||
|
scriptAdPush = document.createElement("script");
|
||||||
|
scriptAdPush.text = "(adsbygoogle = window.adsbygoogle || []).push({});";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sidebarEl.insertBefore(scriptEl, sidebarEl.firstChild);
|
sidebarEl.insertBefore(scriptEl, sidebarEl.firstChild);
|
||||||
|
sidebarEl.insertBefore(scriptIns, sidebarEl.lastChild);
|
||||||
|
sidebarEl.insertBefore(scriptAdPush, sidebarEl.lastChild);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
injectStyle() {
|
injectCarbonStyle() {
|
||||||
const styleEl = document.createElement("style");
|
const styleEl = document.createElement("style");
|
||||||
|
|
||||||
styleEl.textContent = `
|
styleEl.textContent = `
|
||||||
#adsense * {
|
#carbonads * {
|
||||||
margin: initial;
|
margin: initial;
|
||||||
padding: initial;
|
padding: initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
document.head.insertBefore(styleEl, document.querySelector("head style, head link[rel*='stylesheet']"));
|
document.head.insertBefore(styleEl, document.querySelector("head style, head link[rel*='stylesheet']"));
|
||||||
|
|||||||
Reference in New Issue
Block a user