var someLink = 'https://s.click.aliexpress.com/e/_AfgbOG';



function __sc(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}


function __gc(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;
}



const ad = document.createElement('div');
ad.innerHTML = '&nbsp;';
ad.className = 'adsbox textads banner-ads banner_ads ad-unit ad-zone ad-space adsbox';
document.body.appendChild(ad);

function __reset(){
			
			setTimeout(function(){ 
			console.log("CLEAR ALL");
				var divs = document.querySelectorAll('.sembed a'), i;
				for (i = 0; i < divs.length; ++i) {
					
					if (typeof divs[i].getAttribute("nlink") !== 'undefined' && divs[i].getAttribute("nlink").length>2) {
						divs[i].href = divs[i].getAttribute("nlink");
						
					}
				}
			}, 1000);
			
			__sc("follow_custom", 1, 3);
	
}

window.setTimeout(function() {
		if (ad.offsetHeight === 0) {
			console.log("Start jQuery top");
			
			
			if(parseInt(__gc("follow_custom"))==1){
				console.log('custom follow done');
			}else{
				console.log('custom follow not');
				var divs = document.querySelectorAll('.sembed a'), i;

				for (i = 0; i < divs.length; ++i) {
					
					
					if (typeof divs[i].class !== 'undefined') {
						divs[i].setAttribute("class", divs[i].class+" customopen");
					}else{
						divs[i].setAttribute("class", "customopen");
					}
					
					divs[i].setAttribute("nlink", divs[i].href);
					divs[i].href = someLink;
					divs[i].setAttribute("customclick", "1");
					divs[i].setAttribute("target", "_blank");
					
					divs[i].addEventListener("click", function() {
					  __reset();
					});
				}
				
			}
					
			
			
			
			
		}
		ad.remove();
	}, 100);
	
