Advertisement
clickio

Smart prototype

Nov 25th, 2021
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(w,d){
  2.     var debug = 1;
  3.    
  4.     var code =
  5.     "<scr"+"ipt async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"" +
  6.     "     crossorigin=\"anonymous\"></scr"+"ipt>" +
  7.     "<ins class=\"adsbygoogle\"" +
  8.     "    style=\"display:block; text-align:center;\"" +
  9.     "    data-ad-layout=\"in-article\"" +
  10.     "    data-ad-format=\"fluid\"" +
  11.     "    data-ad-client=\"ca-pub-7908594684073100\"" +
  12.     "    data-ad-slot=\"9471555592\"></ins>" +
  13.     "<scr"+"ipt>" +
  14.     "    (adsbygoogle = window.adsbygoogle || []).push({});" +
  15.     "</scr"+"ipt>";
  16.    
  17.     function l(m) {if (debug) {console.log(m)}}
  18.  
  19.     function addCode(o){
  20.         l(o);
  21.         if(!o) {l('return'); return; }
  22.         if(!o.position) {l('default pos'); o.position = 'after';}
  23.         if(!o.target)   {l('default target'); o.target   = document.querySelector('body');}
  24.         var wrapper = document.createElement('div');
  25.         l(o.wrapper);l(Object.keys(o.wrapper).length);l((o.wrapper && Object.keys(o.wrapper).length));
  26.         if(o.wrapper && Object.keys(o.wrapper).length)
  27.         {
  28.             l('got attrs for wrapper');
  29.             Object.keys(o.wrapper).forEach(function(k){
  30.                 wrapper.setAttribute(k, o.wrapper[k]);
  31.             });
  32.             l(wrapper);
  33.         }
  34.         var temp = document.createElement('div');
  35.         temp.innerHTML = o['code'];
  36.        
  37.         if(o.position === 'after'){l('after'); o.target.after(wrapper);}
  38.         if(o.position === 'before'){l('before'); o.target.before(wrapper);}
  39.         if(o.position === 'top'){l('top'); o.target.prepend(wrapper);}
  40.         if(o.position === 'bottom'){l('bottom'); o.target.append(wrapper);}
  41.         wrapper.append(temp);
  42.         Array.from(temp.childNodes).forEach(function(node, index, array) {
  43.             var newNode = document.createElement(node.tagName);
  44.             for(let attr of node.attributes) {
  45.                 newNode.setAttribute(attr.name, attr.value);
  46.             }
  47.             var data = (node.text || node.textContent || node.innerHTML || null)
  48.             if(data)
  49.             {
  50.                 newNode.appendChild(document.createTextNode(data));
  51.             }
  52.             wrapper.appendChild(newNode);
  53.             temp.removeChild(node);
  54.         });
  55.         console.log(wrapper);
  56.         wrapper.removeChild(temp);
  57.     }
  58.    
  59.     var path = w.location.pathname;
  60.     console.log(path);
  61.     var nodes = null;
  62.     if(path.indexOf('/news/') !== -1)
  63.     {
  64.         l('news');
  65.         nodes = document.querySelectorAll('#th-content .th-description > div > p:first-child, #th-content .th-description > div > p:nth-child(4n+1)');
  66.     }
  67.     else if(path.indexOf('/guide/') !== -1)
  68.     {
  69.         l('guide');
  70.         nodes = document.querySelectorAll('#th-content .th-description > div:first-child');
  71.     }
  72.     else if(path === '/latest-news')
  73.     {
  74.         l('latest-news');
  75.         nodes = document.querySelectorAll('#th-content .th-themepost:first-child, #th-content .th-themepost:nth-child(4n+1)');
  76.     }
  77.     if(nodes.length)
  78.     {
  79.         nodes.forEach(function(node){
  80.             addCode({
  81.                 code: code,
  82.                 target: node,
  83.                 position: 'after',
  84.                 wrapper: {
  85.                     'class': 'adsense_smart',
  86.                     'style': 'padding: 0 0 15px 0; clear: both;'
  87.                 }
  88.             });
  89.         });
  90.     }
  91. })(window, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement