PageSourceSearch

https://spurno.github.io/js/site-ads.js

js spurno.github.io collected 2026-10-03 09:59:04 UTC 2,796 bytes, 79 lines download raw bytes

1(function() {
2  var content = document.querySelector('article .blog-content');
3  if (!content) return;
4
5  var AD_CLIENT = 'ca-pub-9371167470298440';
6  var AD_SLOTS = ['8914674393', '6391429399', '9087255784', '6814031410'];
7
8  function randomSlot() {
9    return AD_SLOTS[Math.floor(Math.random() * AD_SLOTS.length)];
10  }
11
12  function createAdElement(isSidebar) {
13    var ins = document.createElement('ins');
14    ins.className = 'adsbygoogle';
15    ins.style.cssText = 'display:block; text-align:center;';
16    ins.setAttribute('data-ad-client', AD_CLIENT);
17    ins.setAttribute('data-ad-slot', randomSlot());
18    if (isSidebar) {
19      ins.setAttribute('data-ad-format', 'auto');
20      ins.setAttribute('data-full-width-responsive', 'true');
21    } else {
22      ins.setAttribute('data-ad-format', 'fluid');
23      ins.setAttribute('data-ad-layout', 'in-article');
24    }
25    return ins;
26  }
27
28  function pushAd() {
29    try { (adsbygoogle = window.adsbygoogle || []).push({}); } catch(e) {}
30  }
31
32  // ── Insert up to 4 inline ads in .blog-content ──
33  var existingArticleAds = content.querySelectorAll('.ad-inline').length;
34  var neededArticleAds = Math.max(0, 4 - existingArticleAds);
35
36  if (neededArticleAds > 0) {
37    var candidates = [];
38    var children = content.children;
39    for (var i = 0; i < children.length; i++) {
40      var tag = children[i].tagName;
41      if ((tag === 'H2' || tag === 'H3' || tag === 'P') && !children[i].closest('.ad-inline')) {
42        candidates.push(children[i]);
43      }
44    }
45
46    var step = Math.max(1, Math.floor(candidates.length / (neededArticleAds + 1)));
47    var inserted = 0;
48    for (var p = step; p < candidates.length && inserted < neededArticleAds; p += step) {
49      var wrapper = document.createElement('div');
50      wrapper.className = 'ad-inline';
51      wrapper.appendChild(createAdElement(false));
52      content.insertBefore(wrapper, candidates[p]);
53      pushAd();
54      inserted++;
55    }
56  }
57
58  // ── Insert 1 sidebar ad in aside.sidebar ──
59  var sidebar = document.querySelector('aside.sidebar');
60  if (sidebar) {
61    var existingSidebarAds = sidebar.querySelectorAll('.sidebar-section .adsbygoogle').length;
62    var neededSidebarAds = Math.max(0, 1 - existingSidebarAds);
63
64    if (neededSidebarAds > 0) {
65      var sidebarSections = sidebar.querySelectorAll('.sidebar-section');
66      var ref = sidebarSections[sidebarSections.length - 1];
67      if (ref) {
68        for (var a = 0; a < neededSidebarAds; a++) {
69          var section = document.createElement('div');
70          section.className = 'sidebar-section sidebar-ad-section';
71          section.appendChild(createAdElement(true));
72          ref.parentNode.insertBefore(section, ref.nextSibling);
73          pushAd();
74          ref = section;
75        }
76      }
77    }
78  }
79})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.