Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(w,d){
- var debug = 1;
- var code =
- "<scr"+"ipt async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"" +
- " crossorigin=\"anonymous\"></scr"+"ipt>" +
- "<ins class=\"adsbygoogle\"" +
- " style=\"display:block; text-align:center;\"" +
- " data-ad-layout=\"in-article\"" +
- " data-ad-format=\"fluid\"" +
- " data-ad-client=\"ca-pub-7908594684073100\"" +
- " data-ad-slot=\"9471555592\"></ins>" +
- "<scr"+"ipt>" +
- " (adsbygoogle = window.adsbygoogle || []).push({});" +
- "</scr"+"ipt>";
- function l(m) {if (debug) {console.log(m)}}
- function addCode(o){
- l(o);
- if(!o) {l('return'); return; }
- if(!o.position) {l('default pos'); o.position = 'after';}
- if(!o.target) {l('default target'); o.target = document.querySelector('body');}
- var wrapper = document.createElement('div');
- l(o.wrapper);l(Object.keys(o.wrapper).length);l((o.wrapper && Object.keys(o.wrapper).length));
- if(o.wrapper && Object.keys(o.wrapper).length)
- {
- l('got attrs for wrapper');
- Object.keys(o.wrapper).forEach(function(k){
- wrapper.setAttribute(k, o.wrapper[k]);
- });
- l(wrapper);
- }
- var temp = document.createElement('div');
- temp.innerHTML = o['code'];
- if(o.position === 'after'){l('after'); o.target.after(wrapper);}
- if(o.position === 'before'){l('before'); o.target.before(wrapper);}
- if(o.position === 'top'){l('top'); o.target.prepend(wrapper);}
- if(o.position === 'bottom'){l('bottom'); o.target.append(wrapper);}
- wrapper.append(temp);
- Array.from(temp.childNodes).forEach(function(node, index, array) {
- var newNode = document.createElement(node.tagName);
- for(let attr of node.attributes) {
- newNode.setAttribute(attr.name, attr.value);
- }
- var data = (node.text || node.textContent || node.innerHTML || null)
- if(data)
- {
- newNode.appendChild(document.createTextNode(data));
- }
- wrapper.appendChild(newNode);
- temp.removeChild(node);
- });
- console.log(wrapper);
- wrapper.removeChild(temp);
- }
- var path = w.location.pathname;
- console.log(path);
- var nodes = null;
- if(path.indexOf('/news/') !== -1)
- {
- l('news');
- nodes = document.querySelectorAll('#th-content .th-description > div > p:first-child, #th-content .th-description > div > p:nth-child(4n+1)');
- }
- else if(path.indexOf('/guide/') !== -1)
- {
- l('guide');
- nodes = document.querySelectorAll('#th-content .th-description > div:first-child');
- }
- else if(path === '/latest-news')
- {
- l('latest-news');
- nodes = document.querySelectorAll('#th-content .th-themepost:first-child, #th-content .th-themepost:nth-child(4n+1)');
- }
- if(nodes.length)
- {
- nodes.forEach(function(node){
- addCode({
- code: code,
- target: node,
- position: 'after',
- wrapper: {
- 'class': 'adsense_smart',
- 'style': 'padding: 0 0 15px 0; clear: both;'
- }
- });
- });
- }
- })(window, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement