Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodebb-plugin-adsense

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodebb-plugin-adsense - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

47

library.js

@@ -5,20 +5,18 @@ 'use strict';

var meta = module.parent.require('./meta');
var winston = module.parent.require('winston');
var helpers = module.parent.require('./routes')
var settings = {};
var Adsense = module.exports;
var Adsense = {};
Adsense.loadSettings = function() {
Adsense.onConfigGet = function (config, callback) {
meta.settings.get('google-adsense', function(err, options) {
if (err) {
return winston.error(err);
return callback(err);
}
settings = options;
config.googleAdsense = options;
callback(null, config);
});
};
var admin = {};
admin.menu = function(custom_header, callback) {
Adsense.admin = {};
Adsense.admin.menu = function (custom_header, callback) {
custom_header.plugins.push({

@@ -29,7 +27,6 @@ "route": '/plugins/google-adsense',

});
callback(null, custom_header);
};
admin.onLoad = function(params, callback) {
Adsense.admin.onLoad = function (params, callback) {
function render(req, res) {

@@ -41,13 +38,8 @@ res.render('admin/plugins/google-adsense', {});

params.router.get('/api/admin/plugins/google-adsense', render);
params.router.get('/google-adsense.config', function(req, res) {
res.json(settings);
});
Adsense.loadSettings();
callback();
};
admin.activate = function(data) {
if (data.id === 'nodebb-plugin-adsense') {
Adsense.admin.activate = function (data) {
if (data.id === 'nodebb-plugin-google-adsense') {
var defaults = [

@@ -62,15 +54,6 @@ { field: 'client_id', value: '' },

meta.settings.setOnEmpty('google-adsense', defaults, next);
async.each(defaults, function(optObj, next) {
meta.settings.setOnEmpty('google-adsense', optObj.field, optObj.value, next);
});
}
};
admin.reloadSettings = function(data) {
if (data.plugin === 'google-adsense') {
settings = data.settings;
}
};
Adsense.admin = admin;
module.exports = Adsense;
};
{
"name": "nodebb-plugin-adsense",
"version": "1.0.0",
"version": "1.0.1",
"description": "Plugin to easily place ads on your forum in different areas",

@@ -24,2 +24,5 @@ "main": "library.js",

},
"dependencies": {
"async": "2.6.0"
},
"readmeFilename": "README.md",

@@ -26,0 +29,0 @@ "gitHead": "29458fd32c922debda109277839d23ae5c9f7e4b",

@@ -12,7 +12,7 @@ {

{ "hook": "action:plugin.activate", "method": "admin.activate" },
{ "hook": "action:settings.set", "method": "admin.reloadSettings"}
{ "hook": "filter:config.get", "method": "onConfigGet" }
],
"scripts": [
"public/main.js"
"public/main.js"
]
}

@@ -0,77 +1,69 @@

/* globals config, $ */
'use strict';
var loaded = false;
var relativePath=config.relative_path;
$(window).on('action:ajaxify.end', function (e, url) {
$.getScript("//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", function (data){
$.getJSON(relativePath + "/google-adsense.config", function (data){
//If ad in header is enabled
if(data.header_id && loaded == false){
$("<div class='text-center'>" + getInsCode(data.client_id, data.header_id, '', 'margin:15px auto;', 'auto') + "</div>").insertBefore("#content");
(adsbygoogle = window.adsbygoogle || []).push({});
}
function getInsCode(clientId, dataId, customClass, style, format){
var ad = '<div class="adsensewrapper" style="text-align:center;"><ins class="adsbygoogle ' + customClass + '" style="display:block; margin-bottom:15px;' + style + ' " data-ad-format="' + format + '" data-ad-client="ca-' + clientId + '" data-ad-slot="' + dataId + '"></ins></div>';
return ad;
}
//If ad in footer is enabled
if(data.footer_id && loaded == false){
$("<div class='text-center'>" + getInsCode(data.client_id, data.footer_id, '', 'margin:15px auto;', 'auto') + "</div>").insertAfter("#content");
(adsbygoogle = window.adsbygoogle || []).push({});
}
function placeSideAd(pull, margin) {
var height = $(".posts >li:first-child .content").height();
var width = 300;
var type = "vertical";
if (height < 250){
type = "rectangle";
width = 250;
}
if (url.url.substring(0, 6) == "topic/") {
if(data.after_first_post_id){
$(".posts >li:first-child").after("<li>" + getInsCode(data.client_id, data.after_first_post_id, '', 'margin: 15px auto', 'auto') + "</li>");
(adsbygoogle = window.adsbygoogle || []).push({});
}
if(data.first_post_id){
switch(data.first_post_position){
case 'bottom':
$(".posts >li:first-child .content").append(getInsCode(data.client_id, data.first_post_id, '', 'margin:15px auto;', 'auto'));
break;
$(".posts >li:first-child .content").prepend(getInsCode(config.googleAdsense.client_id, config.googleAdsense.first_post_id, 'pull-' + pull, 'width:' + width + 'px; margin-' + margin + ':30px;', type));
}
case 'top':
$(".posts >li:first-child .content").prepend(getInsCode(data.client_id, data.first_post_id, '', 'margin:15px auto;', 'auto'));
break;
$.getScript("//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", function () {
case 'left':
var height = $(".posts >li:first-child .content").height();
if(height < 250){
var type = "rectangle";
var width = 250;
}
else{
var width = 300;
var type ="vertical";
}
$(".posts >li:first-child .content").prepend(getInsCode(data.client_id, data.first_post_id, 'pull-left', 'width:' + width + 'px; margin-right:30px;', type));
break;
//If ad in header is enabled
if (config.googleAdsense.header_id && !loaded) {
$(getInsCode(config.googleAdsense.client_id, config.googleAdsense.header_id, '', 'margin:15px auto;', 'auto')).insertBefore("#content");
(adsbygoogle = window.adsbygoogle || []).push({});
}
case 'right':
var height = $(".posts >li:first-child .content").height();
if(height < 250){
var type = "rectangle";
var width = 250;
}
else{
var width = 300;
var type ="vertical";
}
$(".posts >li:first-child .content").prepend(getInsCode(data.client_id, data.first_post_id, 'pull-right', 'width:' + width + 'px; margin-left:30px;', type));
break;
//If ad in footer is enabled
if (config.googleAdsense.footer_id && !loaded) {
$(getInsCode(config.googleAdsense.client_id, config.googleAdsense.footer_id, '', 'margin:15px auto;', 'auto')).insertAfter("#content");
(adsbygoogle = window.adsbygoogle || []).push({});
}
default:
break;
}
(adsbygoogle = window.adsbygoogle || []).push({});
}
if (ajaxify.data.template.topic) {
if (config.googleAdsense.after_first_post_id) {
$(".posts >li:first-child").after("<li style='height:100px;'>" + getInsCode(config.googleAdsense.client_id, config.googleAdsense.after_first_post_id, '', 'margin: 15px auto', 'auto') + "</li>");
(adsbygoogle = window.adsbygoogle || []).push({});
}
loaded = true;
})
})
if (config.googleAdsense.first_post_id) {
switch (config.googleAdsense.first_post_position) {
case 'bottom':
$(".posts >li:first-child .content").append(getInsCode(config.googleAdsense.client_id, config.googleAdsense.first_post_id, '', 'margin:15px auto;', 'auto'));
break;
})
case 'top':
$(".posts >li:first-child .content").prepend(getInsCode(config.googleAdsense.client_id, config.googleAdsense.first_post_id, '', 'margin:15px auto;', 'auto'));
break;
case 'left':
placeSideAd('left', 'right');
break;
function getInsCode(clientId, dataId, customClass, style, format){
var ad = '<ins class="adsbygoogle ' + customClass + '" style="display:block; margin-bottom:15px;' + style + ' " data-ad-format="' + format + '" data-ad-client="ca-' + clientId + '" data-ad-slot="' + dataId + '"></ins>';
return ad;
}
case 'right':
placeSideAd('right', 'left');
break;
default:
break;
}
(adsbygoogle = window.adsbygoogle || []).push({});
}
}
loaded = true;
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc