if( window.mMLoaded !== true ){
function mMReady(fn){var d=document;(d.readyState=='loading')?d.addEventListener('DOMContentLoaded',fn):fn();}
mMReady(mMMainFunc);
}else{
console.log('Loaded: '+window.mMLoaded);
}
function mMwatchClicks(){
var activeE = document.activeElement;
if(activeE && activeE.tagName == 'IFRAME'){
// check if any of the adsbymahimeta divs enclose this iframe
var myElementToCheckIfClicksAreInsideOf = document.querySelectorAll('.adsbymahimeta');
for (var i = 0; i < myElementToCheckIfClicksAreInsideOf.length; i++) {
tempEle = myElementToCheckIfClicksAreInsideOf[i];
if( tempEle.contains(activeE) && tempEle.getAttribute("default-ad") == null ){
window.clickedEle = activeE; // store current
console.log('ad clicked - new code');
logClick();
clearInterval(window.iframewatcher);
// check if cookie is set
if( getCookie('adClicked') !== null ){
ad_clicks = getCookie('adClicked');
ad_clicks = parseInt(ad_clicks);
ad_clicks += 1;
// save new value
createCookie("adClicked",ad_clicks,15);
// if ad clicks are more than set no, report to server
if( ad_clicks >= window.clicks_limit ){
reportClicks(ad_clicks);
// reset count
createCookie("adClicked",0,15);
// block ad serving
createCookie("blockServing",1,30);
}
}else{
createCookie("adClicked",1,15);
}
// blur this element now
window.focus();
document.activeElement.blur();
// restart interval
setTimeout(function(){
window.iframewatcher = setInterval(mMwatchClicks, 500);
},2000);
}
}
}
}
function mMwaitforchange(){
var activeE = document.activeElement;
//console.log(activeE);
//console.log(window.clickedEle);
if( activeE.isEqualNode(window.clickedEle) ){
console.log('same');
}
}
function mMMainFunc(){
// if ad serving is disabled, simply return
if( getCookie('blockServing') !== null && getCookie('blockServing') !== '' && getCookie('blockServing') == '1' ){
return '';
}
mMloadScript('https://mahimeta.com/networks/tag_config.js?ver=1.1', function() {
if( typeof inview_elements == 'undefined' )
inview_elements = []; // store in view ad units here
if( typeof mm_isPageVisible == 'undefined' )
mm_isPageVisible = true;
if( typeof mm_blocked_keywords_array == 'undefined' )
mm_blocked_keywords_array = [];
mMrequest_blocked = false;
console.log("LIMIT Direct: "+impressions_limit);
window.clicks_limit = clicks_limit;
window.impressions_limit = impressions_limit;
window.max_time = max_time;
window.thin_content_count = thin_content_count;
// find keyword violations in text
var text = document.body.innerText;
text = text.toLowerCase();
mMPageCategories = [];
// only do following if violations havent been reported already
if( mm_blocked_keywords_array.length == 0 ){
// find keyword violations
for (index = 0; index < mMkeyword.length; ++index) {
// must have space at end and start to avoid matching words like karengay
mkey = mMkeyword[index];
// remove all invalid charatcers
cleankey = mkey.replace(/[^0-9.,A-Za-z_\-\@]/g, "");
if( cleankey != '' ){
var pattern = new RegExp("(<=\\s|\\b)"+ cleankey +"(?=[]\\b|\\s|$)");
if( pattern.test(text) ){
// keyword found
console.log('violation detected');
console.log('Keyword: '+cleankey);
mm_keyword_violation = true;
mm_blocked_keyword = cleankey;
//break;
if( !mm_blocked_keywords_array.includes(cleankey) ){
mm_blocked_keywords_array.push(cleankey);
}
}
}
}
console.log("Violations: "+mm_blocked_keywords_array);
}
if( typeof mMcategories !== 'undefined' ){
// find keyword violations
for (var key in mMcategories) {
// must have space at end and start to avoid matching words like karengay
mkey = key;
mcategory = mMcategories[mkey];
// remove all invalid charatcers
cleankey = mkey.replace(/[^0-9.,A-Za-z_\-\@]/g, "");
if( cleankey != '' ){
var pattern = new RegExp("(<=\\s|\\b)"+ cleankey +"(?=[]\\b|\\s|$)");
if( pattern.test(text) ){
// only add if not already added
if( !mMPageCategories.includes(mcategory) )
mMPageCategories.push(mcategory);
}
}
}
}
// check if lazy load has been enabled
Array.prototype.forEach.call(mMLazyload, function(dom, index) {
curr_domain = window.location.hostname;
if( curr_domain.indexOf(dom) !== -1 ){
// lazyload is enabled
mMLazyloadEnabled = true;
console.log("Lazy load is enabled");
// add attribute to all units
var adsByMahiMeta = document.querySelectorAll('.adsbymahimeta');
Array.prototype.forEach.call(adsByMahiMeta, function(elements, index) {
if( elements.getAttribute("data-size") == 'Sticky_Video' ){
}else{
elements.setAttribute("data-lazyload","true");
}
});
}
}); // loaded
var adsByMahiMeta = document.querySelectorAll('.adsbymahimeta');
Array.prototype.forEach.call(adsByMahiMeta, function(elements, index) {
// only request ad if not fulfilled already
if( elements.getAttribute("data-loaded") == null && elements.getAttribute("data-domain") == null ){
// do not request if lazy load is enabled - unless ad comes into viewport
//if( mMLazyloadEnabled ){
// elements.setAttribute("data-lazyload","true");
//}else{
// add attribute - loaded
elements.setAttribute("data-loaded","true");
elements.setAttribute("data-reloaded","0");
// get placement type
if( elements.getAttribute("data-placement") != null ){
if( elements.getAttribute("data-placement") != 'in-image' && elements.getAttribute("data-placement") != 'video-overlay' && elements.getAttribute("data-placement") != 'popup' && elements.getAttribute("data-placement") != 'crown' ){
// check if ad is in article
if( elements.getAttribute("data-placement") == 'in-article' ){
// get delay time
if( elements.getAttribute("data-delay") != null && elements.getAttribute("data-delay") != '' ){
delay = parseInt(elements.getAttribute("data-delay")) * 1000;
}else{
delay = 2000;
}
// in article ads must fill full area
elements.style.display = "block"; // fill complete area
elements.style.background = "#f2f2f2"; // set grey background
elements.style.marginTop = "40px";
elements.style.marginBottom = "40px";
elements.style.textAlign = "center";
// get the width of element, to get width of parent
var positionInfo = elements.getBoundingClientRect();
var width = elements.offsetWidth; // width of parent container
// decide size of ad based on width
if( width > 728 ){
ad_size = '728x90';
}else if( width > 336 ){
ad_size = '336x280';
}else{
ad_size = '300x250';
}
window.addEventListener('scroll', function(){
if( inView(elements) ){
// load ad
// add attribute to disable loading again
if( elements.getAttribute("data-viewed") == null ){
// wait for ad to come inside view area
setTimeout(function(){
placement = 'inline';
loadXMLDocDynamic(ad_size,placement,elements);// Calling server for tag
}, delay);
// add attr
elements.setAttribute("data-viewed","true");
}
}else{
}
});
// for intersitial ads
}else if( elements.getAttribute("data-placement") == 'Interstitial' || elements.getAttribute("data-placement") == 'interstitial' ){
if( window.matchMedia("(max-width: 1000px)").matches ){
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// create full screen wrapper to trigger interstitial on click
var wrapper = document.createElement('a');
wrapper.setAttribute('style','position:fixed;top:0;left:0;bottom:0;right:0;display:inline-block;background:transparent;width:100%;height:100%;z-index:99999;text-align:center;font-family:helvetica;;');
wrapper.setAttribute("id","wrap-"+rand);
wrapper.setAttribute("href",'javascript:showInterstitial("'+rand+'","inline","336x280");');
document.getElementsByTagName('body')[0].appendChild(wrapper);
}
if( window.matchMedia("(min-width: 1000px)").matches ){
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// create full screen wrapper to trigger interstitial on click
var wrapper = document.createElement('a');
wrapper.setAttribute('style','position:fixed;top:0;left:0;bottom:0;right:0;display:inline-block;background:transparent;width:100%;height:100%;z-index:99999;text-align:center;font-family:helvetica;;');
wrapper.setAttribute("id","wrap-"+rand);
wrapper.setAttribute("href",'javascript:showInterstitial("'+rand+'","inline","970x300");');
document.getElementsByTagName('body')[0].appendChild(wrapper);
}
}else if( elements.getAttribute("data-lazyload") == 'true' ){
console.log("Entered LazyLoad");
// load if already in viewport
if( inView(elements) ){
if( elements.getAttribute("data-lazyload-filled") == null ){
elements.setAttribute("data-lazyload-filled","true");
// load ad
console.log("Element is in view");
placement = elements.dataset.placement;
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
}
}
window.addEventListener('scroll', function(){
if( inView(elements) ){
if( elements.getAttribute("data-lazyload-filled") == null ){
elements.setAttribute("data-lazyload-filled","true");
// load ad
console.log("Element is in view");
placement = elements.dataset.placement;
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
}
}else{
}
});
}else{
placement = elements.dataset.placement;
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
// if ad is in view, store in array
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}
// need to check when element comes into view after scroll
window.addEventListener('scroll', function(){
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
});
}
}else if( elements.getAttribute("data-placement") == 'video-overlay' ){
// check if user wants it to autoplay
if( elements.getAttribute("data-autoplay") != null ){
autoplay = elements.dataset.autoplay;
}else{
autoplay = "false";
}
if( document.readyState == 'complete' ){
videoOverlayAd(elements,autoplay); // insert video wrapper on embeds
}else{
window.addEventListener('load', function() {
videoOverlayAd(elements,autoplay); // insert video wrapper on embeds
});
}
}else if( elements.getAttribute("data-placement") == 'popup' ){
// insert popup ad
console.log('insert ad');
placement = 'popup';
loadXMLDocDynamic(elements.dataset.size,placement,elements);
}else if( elements.getAttribute("data-placement") == 'crown' ){
elements.setAttribute("data-loaded","true");
elements.setAttribute("data-reloaded","10");
console.log('crown ad');
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
if( screenWidth <= 768 ){
// convert the element into parallax holder
// add new element inside
elements.setAttribute("id","parallax");
elements.setAttribute("class","parallax-holder");
elements.setAttribute("style","margin-top: 30px; margin-bottom: 30px; text-align: center; position: relative; height: 430px; overflow: hidden; background: #f2f2f2; display: block;");
// add new elements inside
elements.innerHTML = `
Advertisement
mahimeta.com
`;
new_element = elements.getElementsByClassName("adsbymahimeta")[0];
placement = 'inline';
loadXMLDocDynamic("300x600",placement,new_element);
// control scroll of element for parallax
window.addEventListener('scroll', function(){
// position of parallax element
var parallaxEle = elements;
var parallaxEleTop = elements.offsetTop;
curr_pos = document.documentElement.scrollTop;
// when scroll has reached parallax element
// start pulling banner above to create parallax effect
diff = parallaxEleTop - curr_pos;
if( diff <= 150 && diff >= -150 ){
parallaxEle.getElementsByClassName("adsbymahimeta")[0].style.top = - diff + "px";
}
});
}
}else{
// check how many images user wants to show ad on
if( elements.getAttribute("data-max") != null ){
max_images = elements.dataset.max;
}else{
max_images = 3;
}
// check min image dimension user wants to show ad on
if( elements.getAttribute("data-dimensions") != null ){
min_dimensions = elements.dataset.dimensions;
}else{
min_dimensions = 336; // default
}
window.addEventListener('load', function() {
inlineImgAd(elements,max_images,min_dimensions); // insert in-image ad
})
}
}else{
if( elements.getAttribute("data-lazyload") == 'true' ){
console.log("Entered LazyLoad");
// load if already in viewport
if( inView(elements) ){
if( elements.getAttribute("data-lazyload-filled") == null ){
elements.setAttribute("data-lazyload-filled","true");
// load ad
console.log("Element is in view");
placement = elements.dataset.placement;
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
}
}
window.addEventListener('scroll', function(){
if( inView(elements) ){
if( elements.getAttribute("data-lazyload-filled") == null ){
elements.setAttribute("data-lazyload-filled","true");
// load ad
console.log("Element is in view");
placement = 'inline';
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
}
}else{
}
});
}else{
placement = 'inline';
loadXMLDocDynamic(elements.dataset.size,placement,elements);// Calling server for tag
// if ad is in view, store in array
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}
// need to check when element comes into view after scroll
window.addEventListener('scroll', function(){
if( isElementInViewport(elements) ){
// check if element exists already
if( inview_elements.indexOf(elements.id) === -1 ){
// add element
inview_elements.push(elements.id);
}
}else{
// remove this element
removeA(inview_elements,elements.id);
}
});
}
}
//} // lazy load check ends here
/*
setTimeout(function(){
if( mMrequest_blocked == true && elements.offsetHeight == 0 ){
// seems like ad blocker is turned on
// check if user has enabled ad blocker
curr_domain = window.location.hostname;
var adblocker_enable = mMBlockers.indexOf(curr_domain);
if( adblocker_enable !== -1 ){
// ad blocker is enabled and user has enabled check
// show message
// check if already added
var blc_wrap = document.getElementById('blc-wrap');
if( typeof(blc_wrap) != 'undefined' && blc_wrap != null ){
}else{
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:fixed;top:0;left:0;bottom:0;right:0;display:inline-block;background:#f2f2f2;width:100%;height:100%;z-index:99999;text-align:center;font-family:helvetica;padding-top:80px;');
wrapper.setAttribute("id","blc-wrap");
wrapper.innerHTML = `It seems you are using an ad blocker.
I have turned off ad blocker
Access site without disabling
`;
document.getElementsByTagName('body')[0].appendChild(wrapper);
}
}
}
console.log("Request Blocked: "+mMrequest_blocked);
}, 4000);
*/
}
});
// load widgets
//var widgetsByMahiMeta = document.querySelectorAll('.widgetsbymahimeta');
elements = document.getElementsByClassName('widgetsbymahimeta')[0];
//Array.prototype.forEach.call(widgetsByMahiMeta, function(elements, index) {
if( elements !== null && typeof elements !== 'undefined' ){
// only request ad if not fulfilled already
if( elements.getAttribute("data-loaded") == null ){
// mark loaded
elements.setAttribute("data-loaded","true");
// get type
widget_type = elements.getAttribute("data-type");
// get color
if( typeof elements.getAttribute("data-color") !== 'undefined' && elements.getAttribute("data-color") !== null ){
widget_color = elements.getAttribute("data-color");
}else{
widget_color = 'black';
}
// decide ad size based on device
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
if( screenWidth >= 1024 ){
bannerWidth = 320;
bannerHeight = 100;
marginBottom = 120;
center_css = ' ';
}else if( ( screenWidth >= 768 && screenWidth < 1024 ) ){
bannerWidth = 320;
bannerHeight = 100;
marginBottom = 120;
center_css = ' ';
}else{
bannerWidth = 320;
bannerHeight = 100;
marginBottom = 120;
center_css = ' ';
}
// get banner size
if( typeof elements.getAttribute("data-desktop") !== 'undefined' && elements.getAttribute("data-desktop") !== null && elements.getAttribute("data-desktop") == '970x90' ){
if( screenWidth >= 1024 ){
bannerWidth = 970;
bannerHeight = 90;
center_css = ' bottom: 0; left: 50%; right: auto; transform: translateX(-50%);';
}
}
if( widget_color == 'black' ){
widget_color = '#555555';
}else if( widget_color == 'blue' ){
widget_color = '#2196f3';
}else if( widget_color == 'green' ){
widget_color = '#76a73f';
}else if( widget_color == 'red' ){
widget_color = '#f44336';
}
elements.setAttribute("style",`position: fixed; right: 10px; bottom: ${marginBottom}px; background: ${widget_color}; border-radius: 4px; text-decoration: none; z-index: 999999;`);
widget_id = elements.getAttribute("id");
var temp = widget_id.split("_");
if( widget_id.length < 3 ){
// generate random
widget_id = Math.floor(Math.random() * 10000);
}else{
widget_id = temp[2];
}
if( widget_type == 'covid' ){
title = 'COVID-19 CASES';
}else if( widget_type == 'weather' ){
title = 'WEATHER TODAY';
}else if( widget_type == 'currency' ){
title = 'FOREX';
}else if( widget_type == 'stocks' ){
title = 'STOCKS - USD';
}else if( widget_type == 'news' ){
title = 'NEWS TODAY';
}else if( widget_type == 'horoscope' ){
title = 'HOROSCOPE';
}else if( widget_type == 'cricket' ){
title = 'CRICKET SCORES';
}
// prepare design
elements.innerHTML = `
x
Powered by Mahimeta
${title}
`;
new_element = elements.getElementsByClassName("adsbymahimeta")[0];
setTimeout(() => {
placement = 'inline';
loadXMLDocDynamic(bannerWidth+"x"+bannerHeight,placement,new_element,false);
}, 3000);
inview_elements.push(new_element.id);
// fill data
if( widget_type == 'covid' ){
loadCovidData(""+widget_id);
}else if( widget_type == 'weather' ){
loadWeatherData(""+widget_id);
}else if( widget_type == 'currency' ){
loadCurrencyData(""+widget_id);
}else if( widget_type == 'news' ){
loadNewsData(""+widget_id);
}else if( widget_type == 'stocks' ){
loadStocksData(""+widget_id);
}else if( widget_type == 'horoscope' ){
loadHoroscopeData(""+widget_id);
}else if( widget_type == 'cricket' ){
loadCricketData(""+widget_id);
}
}
}
//});
// check if refresh ads has been enabled for domain
curr_domain = window.location.hostname;
var refresh_exception = mMRefreshExceptions.indexOf(curr_domain);
// also look in referrer
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
var referer_exception = mMRefreshExceptions.indexOf(referrer);
if( typeof mm_interval == 'undefined' && refresh_exception === -1 && referer_exception === -1 ){
console.log('Refresh Enabled');
mm_interval = setInterval(function(){
// tab must be active, otherwise dont refresh ad
if( mm_isPageVisible ){
// reload all ads which are in view
inview_elements.forEach(function(element) {
// load ad again
mm_reload = document.getElementById(element);
reload_count = parseInt(mm_reload.getAttribute("data-reloaded"));
// only reload if already loaded before and height and width are not zero
if( mm_reload.getAttribute("data-loaded") == "true" && mm_reload.getAttribute("data-ad-inserted") == "true" && reload_count < 3 ){
console.log("Reloading: "+element);
reload_count++;
mm_reload.setAttribute("data-reloaded",reload_count);
if( mm_reload.getAttribute("data-placement") !== null ){
placement = mm_reload.dataset.placement;
}else{
placement = 'inline';
}
loadXMLDocDynamic(mm_reload.dataset.size,placement,mm_reload);// Calling server for tag
}
});
}
console.log("Is page visible: "+mm_isPageVisible);
}, 50000);
}
// check if intersitial ads have been enabled for domain
Array.prototype.forEach.call(mMInterstitial, function(dom, index) {
if( curr_domain.indexOf(dom) !== -1 ){
// interstitial is enabled
// get ad to fill
if( window.matchMedia("(max-width: 1000px)").matches ){
// show only once per session
if( getCookie("mMInterShown") == null ){
// only add if not added already
var interAds = document.getElementsByClassName("wrap-inter");
console.log('Inters: '+interAds.length);
if( interAds.length == 0 ){
// generate cookie now
createCookie("mMInterShown",1,5);
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// add interstitial ad unit
// this checks if geo targeted ads are available
var adElement = document.createElement('ins');
adElement.setAttribute("id","mMTag_Interstitial_"+rand);
adElement.setAttribute("class","adsbymahimeta wrap-inter");
adElement.setAttribute("data-size","Interstitial");
adElement.setAttribute("style","display:inline-block;");
adElement.setAttribute("data-loaded","true");
adElement.setAttribute("data-reloaded","5");
document.getElementsByTagName('body')[0].appendChild(adElement);
// insert ad
loadXMLDocDynamic("Interstitial","inline",adElement);
}
}
}
}
}); // loaded
// check if popup has been enabled
Array.prototype.forEach.call(mMPopups, function(dom, index) {
if( curr_domain.indexOf(dom) !== -1 ){
// popup is enabled
// get ad to fill
// generate random no for id
rand = Math.floor(Math.random() * 10000);
var adElement = document.createElement('ins');
adElement.setAttribute("id","mMTag_Responsive_"+rand);
adElement.setAttribute("class","adsbymahimeta");
adElement.setAttribute("data-size","Pop-Up");
adElement.setAttribute("data-placement","popup");
adElement.setAttribute("style","display:inline-block;");
document.getElementsByTagName('body')[0].appendChild(adElement);
// fill ad
loadXMLDocDynamic("Pop-Up","popup",adElement);
}
}); // loaded
// add other hack for click detection inside iframe
var myConfObj = {
iframeMouseOver : false
}
var elements = document.getElementsByClassName("adsbymahimeta");
for (var i = 0; i < elements.length; i++) {
// only bind if not already bound
if( elements[i].getAttribute("data-binded-click") == null ){
elements[i].addEventListener('mouseover',function(){
myConfObj.iframeMouseOver = true;
});
elements[i].addEventListener('mouseout',function(){
myConfObj.iframeMouseOver = false;
});
// mark binded
elements[i].setAttribute('data-binded-click','true');
}
}
if( window.ImpressionCounted == false || window.ImpressionCounted == '' || typeof window.ImpressionCounted == 'undefined' ){
// detect user's ip
detect_ipChange();
window.iframewatcher = setInterval(mMwatchClicks, 500);
// enable click detection on ads
// save in session cookie
document.body.addEventListener('click', function (event) {
var myElementToCheckIfClicksAreInsideOf = document.querySelectorAll('.adsbymahimeta');
for (var i = 0; i < myElementToCheckIfClicksAreInsideOf.length; i++) {
tempEle = myElementToCheckIfClicksAreInsideOf[i];
if( tempEle.contains(event.target) && tempEle.getAttribute("default-ad") == null ){
console.log(tempEle.getAttribute("default-ad"));
console.log('ad clicked');
logClick();
// check if cookie is set
if( getCookie('adClicked') !== null ){
ad_clicks = getCookie('adClicked');
ad_clicks = parseInt(ad_clicks);
ad_clicks += 1;
// save new value
createCookie("adClicked",ad_clicks,15);
console.log('Click Limit: '+window.clicks_limit);
// if ad clicks are more than set number, report to server
if( ad_clicks >= window.clicks_limit ){
reportClicks(ad_clicks);
// reset count
createCookie("adClicked",0,15);
// block ad serving
createCookie("blockServing",1,30);
}
}else{
createCookie("adClicked",1,15);
}
}
}
});
// check if cookie is set
if( getCookie('pageImpression') !== null ){
page_impression = getCookie('pageImpression');
page_impression = parseInt(page_impression);
page_impression += 1;
// save new value
createCookie("pageImpression",page_impression,15);
console.log( "LIMIT WINDOW: " + window.impressions_limit );
// if page impressions are more than set no, report to server
if( page_impression >= window.impressions_limit ){
console.log("Impressions: Reporting...");
reportImpressions(page_impression);
// reset count
createCookie("pageImpression",0,15);
// block ad serving
createCookie("blockServing",1,30);
}
}else{
createCookie("pageImpression",1,15);
// as long as cookie exists, this is one user browsing site
// ping user count
reportUserLanding(true,false);
}
//creat array of refs to all ads, And keep removing it once it's overlap test is done.
mahimeta_all_ads_ref = Array.prototype.slice.call( document.getElementsByClassName("adsbymahimeta") );
document.addEventListener('scroll', function(e) {
mahimeta_check_overlaps();
});
//setInterval(function(){ reportUserLanding(false,true); }, 20000);
}
window.ImpressionCounted = true;
}); // loaded
}
function mahimeta_check_overlaps(){
var arr = [];
var refs = mahimeta_all_ads_ref;
// for each ref check overlapping
for (var i = 0; i < refs.length; i++) {
let el = refs[i];
var rect = el.getBoundingClientRect();
var viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
var is_ad_visible = !(rect.bottom < 0 || rect.top - viewHeight >= 0);
if(is_ad_visible){ //only check if any ad is visible on screen
ad_overlap_detect(el);
mahimeta_all_ads_ref = mahimeta_all_ads_ref.filter(item => item !== el);
}
}
}
function ad_overlap_detect(ad_element){
var count_overlaps = 0;
var margin = 5; //allow margin of 5px in width and height
//get refs to all ads
var refs = document.getElementsByClassName("adsbymahimeta");
let ad_elem = ad_element;
//check if ad is inserted for this ad
if( Boolean(ad_elem.getAttribute('data-ad-inserted')) ){
let data_placement = ad_elem.getAttribute('data-placement');
if(data_placement == 'floating'){ //for floating ads banner is shown in children element
ad_elem = ad_elem.children[0];
}
// 1. get points of each ad div
let rect = ad_elem.getBoundingClientRect();
// let rect = mahimeta_ad_getCoords(ad_elem);
// console.log(rect);
let x = Math.floor(rect.x + margin);
let y = Math.ceil(rect.y + margin);
if(x > 0 && y > 0){
let x_end = (x+ (rect.width - margin));
let y_end = (y+ (rect.height - margin));
// console.log(x,y);
let found = false;
let scale_x = 10;
main_loop:
for (let offset_x = x; offset_x < x_end; offset_x+=scale_x) {
let scale_y = 10;
for (let offset_y = y; offset_y < y_end; offset_y+=scale_y) {
// 2. get elements which lie within these points
ad_div = document.elementFromPoint(offset_x,offset_y);
// //this can be iframe of ad, select it's ancestor of class adsbymahimeta
if(ad_div){
topElt = ad_div.closest('.adsbymahimeta');
if(! topElt){ // this is not adbymahimeta div OR it a tag overlapping all page for floating ad
if(ad_div.tagName == 'A' && ad_div.getAttribute("href").includes('javascript:showInterstitial')){
}
else{
if(topElt === ad_elem ){ //it is same element of ad's div
}else{
// the overlapping element must not be parent of the ad
if( !ad_div.contains(ad_elem) ){
count_overlaps++;
console.log("Detected On:");
console.log(ad_elem);
console.log("Overlapping Element:");
console.log(ad_div);
found = true;
break main_loop; //overlap found in this ad
}
}
}
}
}
}
}
}
};
if( count_overlaps > 0 ){
// if cookie is already set, then dont send report
if( getCookie('mMOverlapReported') !== null ){
// already reported, ignore
}else{
report_overlap();
createCookie("mMOverlapReported",1,12);
}
console.log(`Total Overlaps detected ${count_overlaps}`);
}
}
function detect_ipChange(){
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
// check if IP exists
ip_address = temp.ip_address;
if( getCookie('mMIP') !== null ){
curr_ip = getCookie('mMIP');
if( curr_ip !== ip_address ){
// report change
console.log("IP change detected");
reportIpChange();
}
// save new value
createCookie("mMIP",ip_address,15);
}else{
createCookie("mMIP",ip_address,15); // seconds
}
console.log(temp.ip_address);
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve2.mahimeta.com/ip/", true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
xmlhttp.ontimeout = function () {
console.log('timeout... on detecting ip.');
}
xmlhttp.send(JSON.stringify({}));
}
function mMRemovePop(id){
console.log('Remove Popup: '+id);
document.getElementById("Popup_"+id).remove();
}
function isMobileDevice() {
return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
}
var mm_hidden, mm_visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
mm_hidden = "hidden";
mm_visibilityChange = "visibilitychange";
}else if( typeof document.msHidden !== "undefined" ){
mm_hidden = "msHidden";
mm_visibilityChange = "msvisibilitychange";
}else if( typeof document.webkitHidden !== "undefined" ){
mm_hidden = "webkitHidden";
mm_visibilityChange = "webkitvisibilitychange";
}
document.addEventListener(mm_visibilityChange, handleVisibilityChange, false);
function handleVisibilityChange() {
if( document[mm_hidden] ){
mm_isPageVisible = false;
}else{
mm_isPageVisible = true;
}
}
function removeA(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
}
// to check if element is completely in view port
function isElementInViewport(el){
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}
function inView(element) {
var elementHeight = element.clientHeight;
var windowHeight = window.innerHeight;
var scrollY = window.scrollY || window.pageYOffset;
var scrollPosition = scrollY + windowHeight;
var elementPosition = element.getBoundingClientRect().top + scrollY + elementHeight;
if (scrollPosition > elementPosition) {
return true;
}
return false;
}
function isScrolledIntoView(el) {
var rect = el.getBoundingClientRect();
var elemTop = rect.top;
var elemBottom = rect.bottom;
// Only completely visible elements return true:
var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
// Partially visible elements return true:
//isVisible = elemTop < window.innerHeight && elemBottom >= 0;
return isVisible;
}
function mMCheckAgain(){
// reload
location.reload();
}
function showInterstitial(id,type,size){
if( document.getElementById('wrap-'+rand) ){
wrapper = document.getElementById('wrap-'+rand);
// remove this a tag now
wrapper.remove();
// add new wrapper div
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:fixed;top:0;left:0;bottom:0;right:0;display:inline-block;background:#f2f2f2;width:100%;height:100%;z-index:99999;text-align:center;font-family:helvetica;;');
wrapper.setAttribute("id","wrap-"+rand);
document.getElementsByTagName('body')[0].appendChild(wrapper);
if( type == 'Outstream' ){
// show outstream player
// insert our ad unit now
var adElement = document.createElement('ins');
adElement.setAttribute("id","mMTag_OutStream_"+rand);
adElement.setAttribute("class","adsbymahimeta");
adElement.setAttribute("data-size","Out_Stream");
adElement.setAttribute("data-placement","interBanner");
adElement.setAttribute("data-autoplay","true");
adElement.setAttribute("style","display:inline-block;width:100%;height:100%;box-sizing:border-box;padding:20px 0;");
wrapper.appendChild(adElement);
// insert ad
loadXMLDocDynamic("Out_Stream","interBanner",adElement);
}else{
// show advertisement
advertisement_tag = document.createElement('span');
advertisement_tag.setAttribute("style","position: absolute; top: 20px; left: 50%; transform: translateX(-50%); background: #e6e5e5; padding: 5px 10px; border-radius: 4px; font-family: helvetica; font-size: 11px; font-style: italic;");
advertisement_tag.innerHTML = "ADVERTISEMENT";
wrapper.appendChild(advertisement_tag);
temp = size.split("x");
ml = parseInt(temp[0]) / 2;
mt = parseInt(temp[1]) / 2;
// show banner ad instead
var adElement = document.createElement('ins');
adElement.setAttribute("id","mMTag_"+size+"_"+rand);
adElement.setAttribute("class","adsbymahimeta");
adElement.setAttribute("data-size",size);
adElement.setAttribute("data-placement","inline");
adElement.setAttribute("style","ddisplay:inline-block;width:"+temp[0]+"px;height:"+temp[1]+"px;position:absolute;top:50%;left:50%;margin-top:-"+mt+"px;margin-left:-"+ml+"px;");
wrapper.appendChild(adElement);
// insert ad
loadXMLDocDynamic(size,"inline",adElement);
}
// insert close button
var closeElement = document.createElement('a');
closeElement.setAttribute('style','position:absolute;bottom:80px;right:20px;background:#000;color:#fff;text-align:center;border-radius:4px;width:auto;height:30px;line-height:30px;padding:0 10px;font-weight:bold;text-decoration: none;');
closeElement.setAttribute("id","close-wrap-"+rand);
closeElement.setAttribute("data-count",'4');
closeElement.innerHTML = 'Skip Ad | 4';
wrapper.appendChild(closeElement);
// add css
var styles = `
#wrap-${id} .mahimeta-wrapper div{
background: #f2f2f2 !important;
}
#wrap-${id} .mahimeta-close{
display: none !important;
}
#mMFloat_${id}, #mMFloat_${id} > div{
height: calc( 100% - 40px ) !important;
}
#mMFloat_${id} .adsbymahimeta{
position: absolute !important;
top: 50% !important;
left: 50% !important;
margin-top: -140px !important;
margin-left: -168px !important;
}
`;
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
wrapper.appendChild(styleSheet);
// start timer for close
interInt = setInterval(function(){
// get count
close_ele = document.getElementById('close-wrap-'+rand);
curr_count = parseInt(close_ele.dataset.count);
if( curr_count > 0 ){
curr_count--;
// update text
close_ele.innerHTML = 'Skip Ad | '+curr_count;
close_ele.setAttribute('data-count',curr_count);
}else{
// allow closing now
close_ele.innerHTML = 'Skip Ad | x';
close_ele.setAttribute('href',"javascript:mahimetaCloseFloater('mMFloat_"+rand+"')");
clearInterval(interInt);
}
},1000);
}
}
function mMContinuewithout(){
// hide message and let user continue
document.getElementById("blc-wrap").remove();
// count inventory lost
inventory_lost = 0;
var adsByMahiMeta = document.querySelectorAll('.adsbymahimeta');
Array.prototype.forEach.call(adsByMahiMeta, function(elements, index) {
if( elements.offsetHeight == 0 ){
inventory_lost++;
}
});
// store request in db
domain = document.domain;
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&inventory_lost="+inventory_lost;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
element.innerHTML = xmlhttp.responseText;
}else if(xmlhttp.status == 400) {
console.log('400');
}else {
console.log('other code:'.xmlhttp.status);
}
}
};
xmlhttp.open("POST", "//mahimeta.com/networks/continue_access.php?"+params, true);
xmlhttp.timeout = 5000;
xmlhttp.ontimeout = function () {
}
xmlhttp.send();
}
function mMloadScript(url,callback) {
var script = document.createElement( "script" )
script.type = "text/javascript";
if(script.readyState) { // only required for IE <9
script.onreadystatechange = function() {
if ( script.readyState === "loaded" || script.readyState === "complete" ) {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName( "head" )[0].appendChild( script );
}
function onElementHeightChange(elm, callback){
var lastHeight = elm.clientHeight, newHeight;
(function run(){
newHeight = elm.clientHeight;
if( lastHeight != newHeight )
callback();
lastHeight = newHeight;
if( elm.onElementHeightChangeTimer )
clearTimeout(elm.onElementHeightChangeTimer);
elm.onElementHeightChangeTimer = setTimeout(run, 700);
})();
}
onElementHeightChange(document.body, function(){
// get all overlayed elements
var overlayed = document.querySelectorAll('[data-overlay]');
Array.prototype.forEach.call(overlayed, function(el, index) {
// get elements position again and update wrapper position
// get offsets
m_top = mMgetOffset(el).top;
m_left = mMgetOffset(el).left;
wrapper_id = el.getAttribute("data-mmoverlay");
console.log(wrapper_id);
if( document.getElementById(wrapper_id) != null ){ // incase ad has player already and wrapper removed
console.log(wrapper_id+" exists");
// update location
document.getElementById(wrapper_id).style.top = m_top+"px";
document.getElementById(wrapper_id).style.left = m_left+"px";
}
});
});
function mMgetOffset( el ) {
/*
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
// customize for one site
if( document.domain.includes('idiziizle') ){
return { top: _y , left: _x };
}else{
return { top: _y + window.scrollY, left: _x };
}
*/
var doc = document,
win = window,
body = doc.body,
// pageXOffset and pageYOffset work everywhere except IE <9.
offsetX = win.pageXOffset !== undefined ? win.pageXOffset :
(doc.documentElement || body.parentNode || body).scrollLeft,
offsetY = win.pageYOffset !== undefined ? win.pageYOffset :
(doc.documentElement || body.parentNode || body).scrollTop,
rect = el.getBoundingClientRect();
if (el !== body) {
var parent = el.parentNode;
// The element's rect will be affected by the scroll positions of
// *all* of its scrollable parents, not just the window, so we have
// to walk up the tree and collect every scroll offset. Good times.
while (parent !== body && parent !== null) {
offsetX += parent.scrollLeft;
offsetY += parent.scrollTop;
parent = parent.parentNode;
}
}
return {
bottom: rect.bottom + offsetY,
height: rect.height,
left : rect.left + offsetX,
right : rect.right + offsetX,
top : rect.top + offsetY,
width : rect.width
};
}
function inlineImgAd(element,max_images,min_dimensions){
// get images on page
var inlineImages = document.querySelectorAll('img');
window.inlineImgCount = 0;
Array.prototype.forEach.call(inlineImages, function(el, index) {
parentA = false;
// check its parent
ep = el.parentNode;
if ( ep.tagName && ep.tagName.toLowerCase() == 'a' ) {
// use parent as element
parentA = true;
}
// if parent is figure then traverse higher
if ( ep.tagName && ep.tagName.toLowerCase() == 'figure' ) {
ep = ep.parentNode;
if ( ep.tagName && ep.tagName.toLowerCase() == 'a' ) {
// use parent as element
parentA = true;
}
}
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
// get width and height of element
width = el.offsetWidth;
height = el.offsetHeight;
if( width >= min_dimensions && height >= 150 ){ // must be atleast this size
window.inlineImgCount++;
if( window.inlineImgCount > max_images ){
return false;
}
// choose ad size based on screen width and image size
ad_size = "320x100"; // default
ad_width = 320;
ad_height = 100;
if( screenWidth > 768 ){ // desktop or tablet
if( width >= 728 && height >= 400 ){
ad_size = "728x90";
ad_width = 728;
ad_height = 90;
}else if( width >= 336 && height >= 400 ){
ad_size = "300x250";
ad_width = 300;
ad_height = 250;
}
}else{ // mobile
if( width >= 336 && height >= 400 ){
ad_size = "300x250";
ad_width = 300;
ad_height = 250;
}
}
// create wrapper container
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:relative;display:inline-block;');
// insert wrapper before el in the DOM tree
if( parentA ){
ep.parentNode.insertBefore(wrapper, ep);
// move el into wrapper
wrapper.appendChild(ep);
}else{
el.parentNode.insertBefore(wrapper, el);
// move el into wrapper
wrapper.appendChild(el);
}
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// insert our ad unit now
var adElement = document.createElement('ins');
adElement.setAttribute("id","inlineImageAd_"+ad_size+"_"+rand);
adElement.setAttribute("style","position:absolute;width:"+ad_width+"px;height:"+ad_height+"px;bottom:0;left:50%;margin-left:-"+ad_width/2+"px;");
wrapper.appendChild(adElement);
// insert close button
var closeElement = document.createElement('span');
from_bottom = ad_height + 10;
from_left = ( ad_width / 2 ) - 25;
closeElement.setAttribute("style","position:absolute;bottom:"+from_bottom+"px;left:50%;margin-left:"+from_left+"px;background:#000;color:#fff;width:24px;height:24px;line-height:22px;text-align:center;border-radius:50%;font-family:Arial;cursor:pointer;");
closeElement.setAttribute("id","close-mmImageAd-"+rand);
//closeElement.onclick = mahimetaCloseFloater("inlineImageAd-"+rand);
closeElement.setAttribute("onclick","mahimetaCloseInline('"+rand+"','"+ad_size+"')");
closeElement.innerHTML = 'x';
wrapper.appendChild(closeElement);
// call ad loading script now
loadXMLDocDynamic(ad_size,"inline",adElement);
}
});
}
function videoOverlayAd(element,autoplay){
// find video tags
var vidTags = document.querySelectorAll('video');
Array.prototype.forEach.call(vidTags, function(el, index) {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
// get width and height of element
width = el.offsetWidth;
height = el.offsetHeight;
// get offsets
m_top = mMgetOffset(el).top;
m_left = mMgetOffset(el).left;
if( width >= 200 && height >= 200 ){ // must be atleast this size
window.vidEmbeds++;
if( window.vidEmbeds > 5 ){
return false;
}
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// create wrapper container
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:absolute;top:'+m_top+'px;left:'+m_left+'px;display:inline-block;background:transparent;width:'+width+'px;height:'+height+'px');
wrapper.setAttribute("id","wrapper-vidOverlay-"+rand);
wrapper.setAttribute("data-autoplay",autoplay);
document.getElementsByTagName('body')[0].appendChild(wrapper);
//el.parentNode.insertBefore(wrapper, el);
// move el into wrapper
//wrapper.appendChild(el);
// insert our ad unit now
var adElement = document.createElement('iframe');
adElement.setAttribute("id","vidOverlay-"+rand);
adElement.setAttribute("data-autoplay",autoplay);
adElement.setAttribute("frameborder","0");
adElement.setAttribute("onclick","mMTriggerPlay('"+rand+"')");
adElement.setAttribute("allow","accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture");
adElement.setAttribute("src","https://mahimeta.com/videoads/?placement=outstream&domain="+document.domain+"&frame_id=vidOverlay-"+rand);
adElement.setAttribute("style","position:absolute;width:100%;height:100%;bottom:0;left:0;top:0;right:0;border:0;z-index:999;background:#000;opacity:0.5;");
wrapper.appendChild(adElement);
// insert message
var closeElement = document.createElement('span');
closeElement.setAttribute("style","opacity:0;position:absolute;top:10px;right:10px;color:#fff;font-size:12px;line-height:22px;text-align:left;font-family:Arial;z-index:1000;cursor:pointer;background:#000;padding:2px 5px;border-radius:4px;");
closeElement.setAttribute("id","close-vidOverlay-"+rand);
//closeElement.onclick = mahimetaCloseFloater("inlineImageAd-"+rand);
closeElement.setAttribute("onclick","mahimetaCloseOverlay('"+rand+"')");
//closeElement.innerHTML = 'x Mahimeta Video Ad';
closeElement.innerHTML = 'Mahimeta Video Ad';
wrapper.appendChild(closeElement);
// attach attribute with element
el.setAttribute("data-overlay","true");
el.setAttribute("data-mmoverlay","wrapper-vidOverlay-"+rand);
}
});
// find embed tags for shockwave
var embedTags = document.querySelectorAll('embed');
Array.prototype.forEach.call(embedTags, function(el, index) {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
// get width and height of element
width = el.offsetWidth;
height = el.offsetHeight;
// get offsets
m_top = mMgetOffset(el).top;
m_left = mMgetOffset(el).left;
if( width >= 200 && height >= 200 ){ // must be atleast this size
window.vidEmbeds++;
if( window.vidEmbeds > 5 ){
return false;
}
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// create wrapper container
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:absolute;top:'+m_top+'px;left:'+m_left+'px;display:inline-block;background:transparent;width:'+width+'px;height:'+height+'px');
wrapper.setAttribute("id","wrapper-vidOverlay-"+rand);
wrapper.setAttribute("data-autoplay",autoplay);
document.getElementsByTagName('body')[0].appendChild(wrapper);
//el.parentNode.insertBefore(wrapper, el);
// move el into wrapper
//wrapper.appendChild(el);
// insert our ad unit now
var adElement = document.createElement('iframe');
adElement.setAttribute("id","vidOverlay-"+rand);
adElement.setAttribute("data-autoplay",autoplay);
adElement.setAttribute("frameborder","0");
adElement.setAttribute("onclick","mMTriggerPlay('"+rand+"')");
adElement.setAttribute("allow","accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture");
adElement.setAttribute("src","https://mahimeta.com/videoads/?placement=outstream&domain="+document.domain+"&frame_id=vidOverlay-"+rand);
adElement.setAttribute("style","position:absolute;width:100%;height:100%;bottom:0;left:0;top:0;right:0;border:0;z-index:999;background:#000;opacity:0.5;");
wrapper.appendChild(adElement);
// insert message
var closeElement = document.createElement('span');
closeElement.setAttribute("style","opacity:0;position:absolute;top:10px;right:10px;color:#fff;font-size:12px;line-height:22px;text-align:left;font-family:Arial;z-index:1000;cursor:pointer;background:#000;padding:2px 5px;border-radius:4px;");
closeElement.setAttribute("id","close-vidOverlay-"+rand);
//closeElement.onclick = mahimetaCloseFloater("inlineImageAd-"+rand);
closeElement.setAttribute("onclick","mahimetaCloseOverlay('"+rand+"')");
//closeElement.innerHTML = 'x Mahimeta Video Ad';
closeElement.innerHTML = 'Mahimeta Video Ad';
wrapper.appendChild(closeElement);
// attach attribute with element
el.setAttribute("data-overlay","true");
el.setAttribute("data-mmoverlay","wrapper-vidOverlay-"+rand);
}
});
// get embeds on page
var vidEmbeds = document.querySelectorAll('iframe');
window.vidEmbeds = 0;
Array.prototype.forEach.call(vidEmbeds, function(el, index) {
//console.log(el);
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
// get width and height of element
width = el.offsetWidth;
height = el.offsetHeight;
// get offsets
m_top = mMgetOffset(el).top;
m_left = mMgetOffset(el).left;
console.log("Top: "+m_top+" Left: "+m_left+" Width: "+width+" Height: "+height);
if( width >= 200 && height >= 200 ){ // must be atleast this size
// show only for youtube and dailymotion
frame_src = el.src;
player_found = false;
for (index = 0; index < mMplayers.length; ++index) {
// get curr element
mplayer = mMplayers[index];
if( frame_src.includes(mplayer) ){
player_found = true;
console.log('found');
}
}
console.log(mMplayers);
if( player_found ){
window.vidEmbeds++;
if( window.vidEmbeds > 5 ){
return false;
}
// generate random no for id
rand = Math.floor(Math.random() * 10000);
// create wrapper container
var wrapper = document.createElement('div');
wrapper.setAttribute('style','position:absolute;top:'+m_top+'px;left:'+m_left+'px;display:inline-block;background:transparent;width:'+width+'px;height:'+height+'px');
wrapper.setAttribute("id","wrapper-vidOverlay-"+rand);
wrapper.setAttribute("data-autoplay",autoplay);
//el.parentNode.insertBefore(wrapper, el);
document.getElementsByTagName('body')[0].appendChild(wrapper);
// move el into wrapper
//wrapper.appendChild(el);
// insert our ad unit now
var adElement = document.createElement('iframe');
adElement.setAttribute("id","vidOverlay-"+rand);
adElement.setAttribute("data-autoplay",autoplay);
adElement.setAttribute("frameborder","0");
adElement.setAttribute("onclick","mMTriggerPlay('"+rand+"')");
adElement.setAttribute("allow","accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture");
adElement.setAttribute("src","https://mahimeta.com/videoads/?placement=outstream&domain="+document.domain+"&frame_id=vidOverlay-"+rand);
adElement.setAttribute("style","position:absolute;width:100%;height:100%;bottom:0;left:0;top:0;right:0;border:0;z-index:999;background:#000;opacity:0.5;");
wrapper.appendChild(adElement);
// insert message
var closeElement = document.createElement('span');
closeElement.setAttribute("style","opacity:0;position:absolute;top:10px;right:10px;color:#fff;font-size:12px;line-height:22px;text-align:left;font-family:Arial;z-index:1000;cursor:pointer;background:#000;padding:2px 5px;border-radius:4px;");
closeElement.setAttribute("id","close-vidOverlay-"+rand);
//closeElement.onclick = mahimetaCloseFloater("inlineImageAd-"+rand);
closeElement.setAttribute("onclick","mahimetaCloseOverlay('"+rand+"')");
//closeElement.innerHTML = 'x Mahimeta Video Ad';
closeElement.innerHTML = 'Mahimeta Video Ad';
wrapper.appendChild(closeElement);
// attach attribute with element
el.setAttribute("data-overlay","true");
el.setAttribute("data-mmoverlay","wrapper-vidOverlay-"+rand);
}
}
});
}
var eventMethodMahimeta = window.addEventListener
? "addEventListener"
: "attachEvent";
var eventer = window[eventMethodMahimeta];
var messageEvent = eventMethodMahimeta === "attachEvent"
? "onmessage"
: "message";
eventer(messageEvent, function (e) {
if( e.data == undefined ){
e.data = e.message;
}
if( Array.isArray(e.data) ){
console.log(e.data);
if( e.data[0] === "mM_default_served" ){
// get frame id
frame_id = e.data[2];
// check if this frame is child of adsbymahimeta ad unit
var myElementToCheckIfClicksAreInsideOf = document.querySelectorAll('.adsbymahimeta');
for (var i = 0; i < myElementToCheckIfClicksAreInsideOf.length; i++) {
tempEle = myElementToCheckIfClicksAreInsideOf[i];
if( tempEle.contains(document.getElementById(frame_id)) ){
tempEle.setAttribute("default-ad","true");
}
}
}
if (e.data[0] === "mM_player_ready"){
// check if autoplay is enabled
if( document.getElementById(e.data[1]) ){
autoplay = document.getElementById(e.data[1]).getAttribute("data-autoplay");
console.log(autoplay);
if( autoplay == 'true' ){
document.getElementById(e.data[1]).contentWindow.postMessage("autoplay_ad", "*");
document.getElementById(e.data[1]).contentWindow.postMessage("show_play_button", "*");
}
}
if( document.getElementById('mMTag_OutStream_'+e.data[1]) ){
autoplay = document.getElementById('mMTag_OutStream_'+e.data[1]).getAttribute("data-autoplay");
if( autoplay == 'true' ){
document.getElementById('mMFrame_'+e.data[1]).contentWindow.postMessage("autoplay_ad", "*");
document.getElementById('mMFrame_'+e.data[1]).contentWindow.postMessage("show_play_button", "*");
}
}
}
if (e.data[0] === "mM_force_ad_start"){
if( document.getElementById(e.data[1]) )
document.getElementById(e.data[1]).contentWindow.postMessage("autoplay_ad", "*");
if( document.getElementById('mMFrame_'+e.data[1]) )
document.getElementById('mMFrame_'+e.data[1]).contentWindow.postMessage("autoplay_ad", "*");
}
if (e.data[0] === "mM_ad_started"){
console.log('Ad Started');
// show play button now
//document.getElementById(e.data[1]).contentWindow.postMessage("autoplay_ad", "*");
if( document.getElementById(e.data[1]) )
document.getElementById(e.data[1]).style.opacity = "1";
if( document.getElementById("close-"+e.data[1]) )
document.getElementById("close-"+e.data[1]).style.opacity = "1";
}
if (e.data[0] === "mM_close_overlay"){
// hide ad
if( document.getElementById(e.data[1]) )
document.getElementById(e.data[1]).outerHTML = "";
if( document.getElementById('wrap-'+e.data[1]) )
document.getElementById('wrap-'+e.data[1]).outerHTML = "";
if( document.getElementById("close-"+e.data[1]) )
document.getElementById("close-"+e.data[1]).outerHTML = "";
if( document.getElementById("wrapper-"+e.data[1]) )
document.getElementById("wrapper-"+e.data[1]).outerHTML = "";
console.log('Close');
}
if (e.data[0] === "mM_show_banner"){
// hide iframe and ad text
if( document.getElementById(e.data[1]) )
document.getElementById(e.data[1]).outerHTML = "";
//document.getElementById("close-"+e.data[1]).outerHTML = "";
if( document.getElementById("close-"+e.data[1]) ){
document.getElementById("close-"+e.data[1]).style.opacity = "0";
document.getElementById("close-"+e.data[1]).innerHTML = 'Close Ad | 10';
}
// get id
var res = e.data[1].split("-");
adunit_id = res[1];
if( document.getElementById("wrapper-"+e.data[1]) ){
wrapper = document.getElementById("wrapper-"+e.data[1]);
// insert new ad unit
var bannerElement = document.createElement('div');
bannerElement.setAttribute("style","opacity:0.5;position:absolute;width:100%;height:100%;bottom:0;left:0;top:0;right:0;border:0;z-index:999;background:#000;text-align:center;");
bannerElement.setAttribute("id","banner-"+e.data[1]);
bannerElement.innerHTML = '';
bannerElement.setAttribute("onclick","mahimetaShowBanner('"+adunit_id+"')");
wrapper.appendChild(bannerElement);
// check if autoplay is enabled
autoplay = document.getElementById("wrapper-"+e.data[1]).getAttribute("data-autoplay");
if( autoplay == 'true' ){
// load banner and show
mahimetaShowBanner(''+adunit_id+'');
}
}
}
}
});
function createCookie(name,value,minutes) {
if (minutes) {
var date = new Date();
date.setTime(date.getTime()+(minutes*60*1000));
var expires = "; expires="+date.toGMTString();
}else{
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function mahimetaCloseInline(id,size){
// remove floating unit
document.getElementById("close-mmImageAd-"+id).outerHTML = "";
document.getElementById("inlineImageAd_"+size+"_"+id).outerHTML = "";
}
function mMTriggerPlay(id){
console.log('Trigger');
}
function mahimetaCloseOverlay(id){
// remove overlay unit
if( document.getElementById("close-vidOverlay-"+id) )
document.getElementById("close-vidOverlay-"+id).outerHTML = "";
if( document.getElementById("vidOverlay-"+id) )
document.getElementById("vidOverlay-"+id).outerHTML = "";
if( document.getElementById("banner-vidOverlay-"+id) )
document.getElementById("banner-vidOverlay-"+id).outerHTML = "";
if( document.getElementById("wrapper-vidOverlay-"+id) )
document.getElementById("wrapper-vidOverlay-"+id).outerHTML = "";
// clear timer
clearInterval(mMTimers[id]);
}
var mMTimers = [];
function mahimetaShowBanner(adunit_id){
// show wrapper
document.getElementById("banner-vidOverlay-"+adunit_id).style.opacity = "1";
document.getElementById("close-vidOverlay-"+adunit_id).style.opacity = "1";
// load ad
var MEle = document.getElementById("mMTag_336x280_"+adunit_id+"_1");
loadXMLDocDynamic("336x280","inline",MEle);
// start timer
mMTimers[adunit_id] = setInterval(function(){
curr = document.getElementById("count-vidOverlay-"+adunit_id).innerHTML;
count = parseInt(curr);
count--;
if( count == 0 ){
clearInterval(mMTimers[adunit_id]);
}
document.getElementById("count-vidOverlay-"+adunit_id).innerHTML = ""+count+"";
},1000);
setTimeout(function(){
if( document.getElementById("close-vidOverlay-"+adunit_id) )
document.getElementById("close-vidOverlay-"+adunit_id).outerHTML = "";
if( document.getElementById("wrapper-vidOverlay-"+adunit_id) )
document.getElementById("wrapper-vidOverlay-"+adunit_id).outerHTML = "";
if( document.getElementById("banner-vidOverlay-"+adunit_id) )
document.getElementById("banner-vidOverlay-"+adunit_id).outerHTML = "";
}, 10000);
}
function mahimetaCloseFloater(id){
// if it has wrapper, close it too
temp = id.split('_');
if( temp.length > 1 ){
if( document.getElementById('wrap-'+temp[1]) !== null ){
document.getElementById('wrap-'+temp[1]).remove();
}
if( document.getElementById('mMTag_OutStream_'+temp[1]) !== null ){
document.getElementById('mMTag_OutStream_'+temp[1]).remove();
}
}
// remove floating unit
if( document.getElementById(""+id) !== null ){
document.getElementById(""+id).outerHTML = "";
}
}
function mahimetaCloseInterstitial(id){
// remove floating unit, only if close button has appeared already
if( document.getElementById("mMCounter").innerHTML == "x" ){
document.getElementById(""+id).outerHTML = ""; // remove ad
document.getElementById("mMOverlay").outerHTML = ""; // remove overlay
}
}
function reportUserLanding(landed,ping) {
if( landed == true || mm_isPageVisible ){
if( landed == false && ping == true && mm_isPageVisible ){
if( getCookie('mMtimeSpent') !== null ){
mMtimeSpent = getCookie('mMtimeSpent');
mMtimeSpent = parseInt(mMtimeSpent);
mMtimeSpent += 20; // seconds
// save new value
createCookie("mMtimeSpent",mMtimeSpent,15);
}else{
createCookie("mMtimeSpent",20,15); // seconds
}
console.log('Max Time: '+window.max_time);
}
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&screenWidth="+screenWidth+"&screenHeight="+screenHeight+"&landed="+landed+"&ping="+ping;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("POST", "//adserve2.mahimeta.com/networks/time/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
}
function reportClicks(click_count) {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var mm_autoblock = false;
for (index = 0; index < mMexceptions.length; ++index) {
if( user_fullpath.indexOf(mMexceptions[index]) !== -1 ){
// domain is set on autoblock
mm_autoblock = true;
}
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&screenWidth="+screenWidth+"&screenHeight="+screenHeight+"&clicks="+click_count+ref+device_size;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
console.log('user reported');
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("POST", "//adserve2.mahimeta.com/networks/report/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function logClick() {
console.log('click logged');
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&screenWidth="+screenWidth+"&screenHeight="+screenHeight+"&click=log";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
//console.log('click logged');
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("POST", "//adserve2.mahimeta.com/networks/report/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function reportImpressions(page_impressions) {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&screenWidth="+screenWidth+"&screenHeight="+screenHeight+"&impressions="+page_impressions;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
console.log('user reported');
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("POST", "//adserve2.mahimeta.com/networks/impressions/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function reportIpChange() {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var mm_autoblock = false;
for (index = 0; index < mMexceptions.length; ++index) {
if( user_fullpath.indexOf(mMexceptions[index]) !== -1 ){
// domain is set on autoblock
mm_autoblock = true;
}
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+ref;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
console.log('ip change reported');
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve2.mahimeta.com/networks/ip_change/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function report_overlap() {
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
if( document.domain == 'tpc.googlesyndication.com' ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var mm_autoblock = false;
for (index = 0; index < mMexceptions.length; ++index) {
if( user_fullpath.indexOf(mMexceptions[index]) !== -1 ){
// domain is set on autoblock
mm_autoblock = true;
}
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+ref;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
console.log('overlap reported');
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve2.mahimeta.com/networks/overlap_detected/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function loadXMLDocDynamic(size,placement,ele,show_default = true) {
var element = ele;
var id = element.id;
// get screen size for responsive ads
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
screenWidth = x;
screenHeight = y;
// get referrer
if( window.mMReferrer == undefined ){
var ref_url = document.createElement('a');
ref_url.href = document.referrer;
referrer = ref_url.hostname;
window.mMReferrer = referrer;
console.log('Referrer: '+referrer);
ref = '&referrer='+referrer;
}else{
ref = '';
}
// get desktop, tablet, mobile sizes for responsive ad
if( ele.dataset.size == 'Responsive' ){
if( ele.getAttribute("data-desktop") != null && ele.getAttribute("data-tablet") != null && ele.getAttribute("data-mobile") != null ){
device_size = '&desktop='+ele.getAttribute("data-desktop")+'&tablet='+ele.getAttribute("data-tablet")+'&mobile='+ele.getAttribute("data-mobile");
}else{
// use default sizes
device_size = '&desktop=970x90&tablet=728x90&mobile=300x250';
}
}else{
device_size = '';
if( ele.dataset.size == 'Sticky_Video' ){
if( ele.getAttribute("data-desktop") != null ){
if( ele.getAttribute("data-desktop") == "hide" ){
device_size += '&desktop=hide';
}
}
if( ele.getAttribute("data-tablet") != null ){
if( ele.getAttribute("data-tablet") == "hide" ){
device_size += '&tablet=hide';
}
}
if( ele.getAttribute("data-mobile") != null ){
if( ele.getAttribute("data-mobile") == "hide" ){
device_size += '&mobile=hide';
}
}
}
}
// domain sent
//console.log("SENT: "+document.domain);
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// check if site is on autoblock
user_domain = domain;
user_path = window.location.pathname;
user_query = window.location.search;
user_fullpath = user_domain + user_path + user_query;
var mm_autoblock = false;
for (index = 0; index < mMexceptions.length; ++index) {
if( user_fullpath.indexOf(mMexceptions[index]) !== -1 ){
// domain is set on autoblock
mm_autoblock = true;
}
}
time_exceeded = '&time_exceeded=false';
if( getCookie('mMtimeSpent') !== null ){
mMtimeSpent = getCookie('mMtimeSpent');
mMtimeSpent = parseInt(mMtimeSpent);
if( mMtimeSpent > window.max_time ){
time_exceeded = '&time_exceeded=true';
}
}
if( typeof window.thin_content_count !== undefined ){
if( window.thin_content_count !== '' ){
thin_content = '&thin_content_count='+window.thin_content_count;
}
}
// send page categories with request
page_categories = mMPageCategories.join();
page_categories = '&page_categories='+page_categories;
// get user's timeszone
var Toffset = new Date().getTimezoneOffset();
timeoffset = Toffset / 60;
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc);
var mMhours = nd.getHours();
var mMminutes = nd.getMinutes();
var mMTime = ('0' + mMhours).slice(-2)+':'+('0' + mMminutes).slice(-2);
if( mm_blocked_keywords_array.length > 0 ){
mm_blocked_keyword = mm_blocked_keywords_array.join(",");
}
var adserver = '';
if( ele.getAttribute("data-adserver") !== null ){
if( ele.getAttribute("data-adserver") !== '' ){
adserver='&adserver='+ele.getAttribute("data-adserver");
}
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&size="+size+"&placement="+placement+"&adId="+id+"&screenWidth="+screenWidth+"&screenHeight="+screenHeight+"&keywordViolation="+mm_keyword_violation+"&blockedKeywords="+mm_blocked_keyword+"&autoBlock="+mm_autoblock+"&timezone="+timeoffset+"&currTime="+mMTime+ref+device_size+time_exceeded+page_categories+thin_content+adserver;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
if( show_default == false ){
const regex = /"default-ad","true"/gm;
ad_code = xmlhttp.responseText;
default_found = false;
if( ad_code.match(regex) !== null ){
if( ad_code.match(regex).length > 0 ){
element.outerHTML = '';
default_found = true;
}
}
if( default_found == false ){
element.innerHTML = xmlhttp.responseText;
element.setAttribute("data-ad-inserted","true");
var arr = element.querySelectorAll('script');
var scriptSources = [];
for (var n = 0; n < arr.length; n++) {
if( arr[n].src != '' ){
scriptSources.push(arr[n].src);
}
}
for (var n = 0; n < arr.length; n++) {
if (arr[n].src == '') {
var newScript = document.createElement("script");
var inlineScript = document.createTextNode(arr[n].innerHTML);
newScript.appendChild(inlineScript);
element.appendChild(newScript);
}
}
if(scriptSources.length) {
eboundLoadScripts(scriptSources, function () {
console.log('loaded');
});
}
}
}else{
element.innerHTML = xmlhttp.responseText;
element.setAttribute("data-ad-inserted","true");
var arr = element.querySelectorAll('script');
var scriptSources = [];
for (var n = 0; n < arr.length; n++) {
if( arr[n].src != '' ){
scriptSources.push(arr[n].src);
}
}
for (var n = 0; n < arr.length; n++) {
if (arr[n].src == '') {
var newScript = document.createElement("script");
var inlineScript = document.createTextNode(arr[n].innerHTML);
newScript.appendChild(inlineScript);
element.appendChild(newScript);
}
}
if(scriptSources.length) {
eboundLoadScripts(scriptSources, function () {
console.log('loaded');
});
}
}
}else if(xmlhttp.status == 400) {
console.log('400');
}else {
console.log('other code:'+xmlhttp.status);
mMrequest_blocked = true;
}
}
};
xmlhttp.open("POST", "//adserve.mahimeta.com/networks/?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
xmlhttp.ontimeout = function () {
console.log('timeout... retrying...');
setTimeout(function(){ loadXMLDocDynamic(size,placement,ele); }, 3000);
}
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function prepareAnalytics() {
var text = document.body.innerText;
var reportItems = {};
//5- Get Operating System Platform
var os = navigator.platform;
reportItems['platform'] = os;
//5- Get User agent
var ua = navigator.userAgent;
reportItems['userAgent'] = ua;
//6- Get Referrer url
var referrer = document.referrer;
reportItems['referrer'] = referrer;
//7- Get Iframe
reportItems['iframe'] = 0;
if(inIframe()){
reportItems['iframe'] = 1;
}
//7- Get Domain name
reportItems['domain'] = document.domain;
//8- Path Name
reportItems['pathname'] = window.location.pathname;
reportItems['query'] = window.location.search;
//8- Get Current Page
reportItems['currentPage'] = window.location.href;
// Send full page for keyword detection
reportItems['text'] = text;
return reportItems;
}
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
function eboundLoadScripts(array,callback){
var loader = function(src,handler){
var script = document.createElement("script");
script.src = src;
script.async = true;
script.onload = script.onreadystatechange = function(){
script.onreadystatechange = script.onload = null;
handler();
}
var head = document.getElementsByTagName("head")[0];
(head || document.body).appendChild( script );
};
(function run(){
if(array.length!=0){
loader(array.shift(), run);
}else{
callback && callback();
}
})();
}
function loadCovidData(widget_id){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_Covid_"+widget_id);
data_holder = element.getElementsByClassName("covid-data")[0];
console.log(temp);
country = temp.country;
country_cases = temp.cases.toLocaleString();
country_deaths = temp.deaths.toLocaleString();
country_vaccinated = temp.vaccinated.toLocaleString();
country_new_cases = temp.new_cases.toLocaleString();
country_new_deaths = temp.new_deaths.toLocaleString();
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
data_holder.innerHTML = `
${url_canvas_start}
${country} CASES
${country_cases}
+${country_new_cases}
${country} DEATHS
${country_deaths}
+${country_new_deaths}
${country} VACCINATED
${country_vaccinated}
${url_canvas_end}
`;
setInterval( rotate_data, 6000, widget_id);
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/covid?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function rotate_data(widget_id,type = 'Covid'){
if( document.getElementById("mMTag_"+type+"_"+widget_id) ){
// get widget
widget_id = document.getElementById("mMTag_"+type+"_"+widget_id);
type = type.toLowerCase();
console.log(type);
// get data holder inside widget
widget_data = widget_id.getElementsByClassName(type+"-data")[0];
// check which block is active
active = widget_data.getElementsByClassName("covid-visible")[0];
// get id of active element
active_id = active.id;
// check its number
temp = active_id.split("-");
active_block_number = parseInt(temp[1]);
show_next = 0;
if( active_block_number == 1 ){
show_next = 2;
}else if( active_block_number == 2 ){
show_next = 3;
}else{
show_next = 1; // back to start
}
// hide current first
active.classList.remove("covid-visible");
active.style.display = "none";
next = widget_id.getElementsByClassName("covid-"+show_next)[0];
next.classList.add("covid-visible");
next.style.display = "block";
}
}
function loadWeatherData(widget_id){
// prepare data
element = document.getElementById("mMTag_Weather_"+widget_id);
data_holder = element.getElementsByClassName("weather-data")[0];
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
data_holder.innerHTML = 'Loading...
';
/*
*/
if( getCookie('userCity') !== null ){
city = getCookie('userCity');
data_holder.innerHTML = `
${url_canvas_start}
${url_canvas_end}
`;
// show data now
geoCallback(city);
}else{
// try api first
mMgetUserCityAPI(widget_id);
}
//var script = document.createElement('script');
//script.src = 'https://ipinfo.io?callback=geoCallback';
//document.getElementsByTagName('head')[0].appendChild(script);
}
function geoCallback(city){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
// send request for weather and show
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href)+"&city="+city;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
console.log(temp);
visibility = parseInt( parseInt(temp.visibility) / 1000 );
temperature = parseInt(temp.temperature);
f_temperature = parseInt(temp.f_temperature);
feels_like = parseInt(temp.feels_like);
f_feels_like = parseInt(temp.f_feels_like);
document.getElementsByClassName("weather-city")[0].innerHTML = temp.city;
document.getElementsByClassName("weather-description")[0].innerHTML = temp.weather;
document.getElementsByClassName("weather-temperature")[0].innerHTML = temperature+'o'+' / '+f_temperature+'o';
document.getElementsByClassName("weather-feels")[0].innerHTML = "Feels Like: "+feels_like+'o / '+f_feels_like+'o';
document.getElementsByClassName("weather-humidity")[0].innerHTML = "Humidity: "+temp.humidity+"%";
document.getElementsByClassName("weather-visibility")[0].innerHTML = "Visibility: "+visibility+"km";
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/weather?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function mMgetUserCity(latitude,longitude){
// send request for weather and show
var xmlhttp;
var params = latitude+','+longitude;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
if( temp.status == 'success' ){
// save city
createCookie("userCity",temp.data.name,1000);
geoCallback(temp.data.name);
}
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//mahimeta.com/get_city.php?coord="+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function mMgetUserCityAPI(widget_id){
element = document.getElementById("mMTag_Weather_"+widget_id);
data_holder = element.getElementsByClassName("weather-data")[0];
// send request for weather and show
var xmlhttp;
var params = '';
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
if( temp.status == 'success' ){
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
data_holder.innerHTML = `
${url_canvas_start}
${url_canvas_end}
`;
// save city
createCookie("userCity",temp.city,1000);
geoCallback(temp.city);
}else{
data_holder.innerHTML = 'Waiting for location permission...
';
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
// fall back to browser permission
// get permission and create cookie
navigator.geolocation.getCurrentPosition((position)=>{
console.log(position.coords.latitude);
console.log(position.coords.longitude);
data_holder.innerHTML = `
${url_canvas_start}
${url_canvas_end}
`;
// get city now
mMgetUserCity(position.coords.latitude,position.coords.longitude);
}, (error)=>{
console.log(error);
// remove widget
element.outerHTML = '';
});
}
}else {
data_holder.innerHTML = 'Waiting for location permission...
';
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
// fall back to browser permission
// get permission and create cookie
navigator.geolocation.getCurrentPosition((position)=>{
console.log(position.coords.latitude);
console.log(position.coords.longitude);
data_holder.innerHTML = `
${url_canvas_start}
${url_canvas_end}
`;
// get city now
mMgetUserCity(position.coords.latitude,position.coords.longitude);
}, (error)=>{
console.log(error);
// remove widget
element.outerHTML = '';
});
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/city/", true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function loadNewsData(widget_id){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_News_"+widget_id);
data_holder = element.getElementsByClassName("news-data")[0];
title_holder = element.getElementsByClassName("widget-title")[0];
title_holder.style.textTransform = 'uppercase';
title_holder.innerHTML = temp.country_name + " News";
//country = temp.country;
//country_cases = temp.cases.toLocaleString();
//country_deaths = temp.deaths.toLocaleString();
//country_vaccinated = temp.vaccinated.toLocaleString();
start = 1;
html = `
`;
start_class = 'news-visible';
Array.prototype.forEach.call(temp.data, function(news, index) {
html += `
`;
start++;
start_class = 'news-hidden';
});
data_holder.innerHTML = html;
setInterval( rotate_news, 6000, widget_id);
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/news?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function rotate_news(widget_id,type = "News"){
if( document.getElementById("mMTag_"+type+"_"+widget_id) ){
// get widget
widget_id = document.getElementById("mMTag_"+type+"_"+widget_id);
type = type.toLocaleLowerCase();
// get data holder inside widget
widget_data = widget_id.getElementsByClassName(type+"-data")[0];
// check which block is active
active = widget_data.getElementsByClassName("news-visible")[0];
// get id of active element
active_id = active.id;
// check its number
temp = active_id.split("-");
active_block_number = parseInt(temp[1]);
show_next = 0;
// count news
item_count = widget_data.getElementsByClassName("news-block").length;
show_next = ++active_block_number;
if( show_next > item_count ){
show_next = 1;
}
// hide current first
active.classList.remove("news-visible");
active.classList.add("news-hidden");
next = widget_id.getElementsByClassName("news-"+show_next)[0];
next.classList.add("news-visible");
next.classList.remove("news-hidden");
}
}
function loadCurrencyData(widget_id){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_Currency_"+widget_id);
data_holder = element.getElementsByClassName("currency-data")[0];
console.log(temp);
country = temp.country;
to_usd = temp.data[0].to_usd;
to_eur = temp.data[0].to_eur;
to_gbp = temp.data[0].to_gbp;
currency = temp.currency;
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
data_holder.innerHTML = `
${url_canvas_start}
$1 = ${currency} ${to_usd}
€1 = ${currency} ${to_eur}
£1 = ${currency} ${to_gbp}
${url_canvas_end}
`;
setInterval( rotate_data, 6000, widget_id, "Currency");
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/currency?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function loadStocksData(widget_id){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_Stocks_"+widget_id);
data_holder = element.getElementsByClassName("stocks-data")[0];
console.log(temp);
start = 1;
html = `
`;
start_class = 'news-visible';
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
Array.prototype.forEach.call(temp.data, function(stocks, index) {
let dollarUSLocale = Intl.NumberFormat('en-US');
current_price = dollarUSLocale.format(stocks.current_price)
if( stocks.change_value > 0 ){
change_color = 'green';
change_value = "+"+stocks.change_value;
}else{
change_color = 'red';
change_value = stocks.change_value;
}
html += `
${url_canvas_start}
${stocks.name}
${current_price}
${change_value}
${url_canvas_end}
`;
start++;
start_class = 'news-hidden';
});
data_holder.innerHTML = html;
setInterval( rotate_news, 6000, widget_id, "Stocks");
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/stocks?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function loadHoroscopeData(widget_id){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_Horoscope_"+widget_id);
data_holder = element.getElementsByClassName("horoscope-data")[0];
console.log(temp);
start = 1;
html = `
`;
data = temp.data;
for (var key of Object.keys(data)) {
star = key.toUpperCase();
html += `
x
${star}
${data[key].description}
`;
};
data_holder.innerHTML = html;
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/horoscope?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}
function mMshowHoroscope(star){
// hide the selector
//document.getElementsByClassName("select-horoscope")[0].style.display = "none";
Array.prototype.forEach.call(document.getElementsByClassName("select-horoscope"), function(item, index) {
item.style.display = "none";
});
document.getElementsByClassName("horoscope-"+star)[0].style.display = "block";
}
function mMshowSelector(star){
// hide the selector
//document.getElementsByClassName("select-horoscope")[0].style.display = "none";
Array.prototype.forEach.call(document.getElementsByClassName("select-horoscope"), function(item, index) {
item.style.display = "inline-block";
});
document.getElementsByClassName("horoscope-"+star)[0].style.display = "none";
}
function closeWidget(element){
document.getElementById(element).outerHTML = '';
}
function loadCricketData(widget_id,first_load = true){
if( document.domain.indexOf('googlesyndication.com') !== -1 ){
domain = window.mMReferrer;
}else{
domain = document.domain;
}
var xmlhttp;
var params = "domain="+encodeURIComponent(domain)+"&pathname="+encodeURIComponent(window.location.pathname)+"&query="+encodeURIComponent(window.location.search)+"¤tPage="+encodeURIComponent(window.location.href);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
temp = JSON.parse(xmlhttp.responseText);
element = document.getElementById("mMTag_Cricket_"+widget_id);
data_holder = element.getElementsByClassName("cricket-data")[0];
console.log(temp);
if( temp.success == 'true' ){
url_canvas_start = '';
url_canvas_end = '';
if( typeof element.getAttribute("data-url") !== 'undefined' && element.getAttribute("data-url") !== '' && element.getAttribute("data-url") !== null ){
url_canvas_start = '';
url_canvas_end = '';
}
if( temp.data.state == 'Complete' ){
title_holder = element.getElementsByClassName("widget-title")[0];
title_holder.innerHTML = temp.data.series_name;
data_holder.innerHTML = `
${url_canvas_start}
${temp.data.team1_short} vs ${temp.data.teeam2_short}
${temp.data.bat_team} | ${temp.data.bat_team_score}/${temp.data.bat_team_wickets} |
${temp.data.second_team} | ${temp.data.second_team_score}/${temp.data.second_team_wickets} |
${temp.data.custom_status}
${url_canvas_end}
`;
}else if( temp.data.state == 'Toss' ){
title_holder = element.getElementsByClassName("widget-title")[0];
title_holder.innerHTML = temp.data.series_name;
data_holder.innerHTML = `
${url_canvas_start}
${temp.data.team1_short} vs ${temp.data.teeam2_short}
Match is Live
${temp.data.bat_team} | ${temp.data.bat_team_score}/${temp.data.bat_team_wickets} |
${temp.data.second_team} | ${temp.data.second_team_score}/${temp.data.second_team_wickets} |
${temp.data.toss_result}
${url_canvas_end}
`;
}else if( temp.data.state == 'In Progress' ){
title_holder = element.getElementsByClassName("widget-title")[0];
title_holder.innerHTML = temp.data.series_name;
second_team = '';
if( temp.data.second_team !== '' ){
second_team = `${temp.data.second_team} | ${temp.data.second_team_score}/${temp.data.second_team_wickets} |
`;
}
data_holder.innerHTML = `
${url_canvas_start}
${temp.data.team1_short} vs ${temp.data.teeam2_short}
Match is Live
${temp.data.bat_team} | ${temp.data.bat_team_score}/${temp.data.bat_team_wickets} (${temp.data.overs}) |
${second_team}
${temp.data.custom_status}
${url_canvas_end}
`;
}else if( temp.data.state == 'Innings Break' ){
title_holder = element.getElementsByClassName("widget-title")[0];
title_holder.innerHTML = temp.data.series_name;
second_team = '';
if( temp.data.second_team !== '' ){
second_team = `${temp.data.second_team} | ${temp.data.second_team_score}/${temp.data.second_team_wickets} |
`;
}
data_holder.innerHTML = `
${url_canvas_start}
${temp.data.team1_short} vs ${temp.data.teeam2_short}
${temp.data.custom_status}
${temp.data.bat_team} | ${temp.data.bat_team_score}/${temp.data.bat_team_wickets} (${temp.data.overs}) |
${second_team}
${url_canvas_end}
`;
}
}else{
element.outerHTML = '';
}
if( first_load ){
// load data every 2 minutes
setInterval( function(){
loadCricketData(""+widget_id,false);
}, 120000);
}
}else if(xmlhttp.status == 400) {
}else {
}
}
};
xmlhttp.open("GET", "//adserve.mahimeta.com/widget/cricket?"+params, true);
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.timeout = 8000;
var reporting = prepareAnalytics();
xmlhttp.send(JSON.stringify({reporting:reporting}));
}