gitbook-plugin-adsense
Advanced tools
Comparing version 0.0.7 to 0.0.9
@@ -1,11 +0,11 @@ | ||
require(["gitbook"], function(gitbook) { | ||
var adInsertPoint = '.page-inner section' | ||
, ad | ||
; | ||
/* eslint-env browser */ | ||
gitbook.events.bind("start", function(e, cnf) { | ||
var config = cnf.adsense | ||
, adsByGoogleScript | ||
; | ||
require(['gitbook'], function (gitbook) { | ||
var adInsertPoint = '.page-inner section' | ||
, adPosition = 'bottom' | ||
, ad; | ||
gitbook.events.bind('start', function (e, cnf) { | ||
const config = cnf.adsense; | ||
// Use custom insert point if defined | ||
@@ -16,4 +16,9 @@ if (config.element) { | ||
// Use custom position if defined | ||
if (config.position) { | ||
adPosition = config.position; | ||
} | ||
// Inject script to head. | ||
adsByGoogleScript = document.createElement('script'); | ||
var adsByGoogleScript = document.createElement('script'); | ||
adsByGoogleScript.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; | ||
@@ -27,2 +32,3 @@ adsByGoogleScript.setAttribute('async', true); | ||
ad.className = 'adsbygoogle'; | ||
ad.setAttribute('data-ad-client', config.client); | ||
@@ -33,13 +39,25 @@ ad.setAttribute('data-ad-slot', config.slot); | ||
// Add the ad to the DOM | ||
document.querySelector(adInsertPoint).appendChild(ad); | ||
var element = document.querySelector(adInsertPoint); | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | ||
if (adPosition === 'top') { | ||
element.insertBefore(ad, element.firstChild); | ||
} else { | ||
element.appendChild(ad); | ||
} | ||
(adsbygoogle = window.adsbygoogle || []).push({}); // eslint-disable-line | ||
}); | ||
// I insert ad again when switching pages | ||
gitbook.events.bind("page.change", function() { | ||
gitbook.events.bind('page.change', function () { | ||
if (ad) { | ||
document.querySelector(adInsertPoint).appendChild(ad); | ||
var element = document.querySelector(adInsertPoint); | ||
if (adPosition === 'top') { | ||
element.insertBefore(ad, element.firstChild); | ||
} else { | ||
element.appendChild(ad); | ||
} | ||
} | ||
}); | ||
}); |
module.exports = { | ||
book: { | ||
assets: "./book", | ||
assets: './book', | ||
js: [ | ||
"plugin.js" | ||
'plugin.js' | ||
] | ||
} | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"main": "index.js", | ||
"version": "0.0.7", | ||
"version": "0.0.9", | ||
"engines": { | ||
@@ -42,3 +42,7 @@ "gitbook": ">=2.5.1" | ||
} | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.19.0", | ||
"eslint-config-tidal": "^1.1.3" | ||
} | ||
} |
@@ -28,3 +28,4 @@ Google Adsense for GitBook | ||
"format": "auto", | ||
"element": ".page-inner section" | ||
"element": ".page-inner section", | ||
"position": "top" | ||
} | ||
@@ -34,1 +35,2 @@ } | ||
``` | ||
Allowed positions are `top` and `bottom` (default) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
15405
8
56
35
2