-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (56 loc) · 2.23 KB
/
script.js
File metadata and controls
63 lines (56 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(function () {
var CTA_ID = 'sgai-cta-widget';
function buildCta() {
var el = document.createElement('div');
el.id = CTA_ID;
el.className = 'sgai-cta';
el.innerHTML = [
'<div class="sgai-cta__brand">',
' <img src="/logos/logo-color.svg" alt="" class="sgai-cta__brand-logo" />',
' <span>ScrapeGraphAI</span>',
'</div>',
'<div class="sgai-cta__title">Ready to build?</div>',
'<p class="sgai-cta__desc">Start extracting structured web data for free and scale seamlessly as your project grows.</p>',
'<a class="sgai-cta__btn sgai-cta__btn--primary" href="https://scrapegraphai.com/login">Start for free</a>',
'<a class="sgai-cta__btn sgai-cta__btn--secondary" href="https://scrapegraphai.com/pricing">See our plans</a>'
].join('');
return el;
}
function findTocAside() {
var candidates = document.querySelectorAll('aside, nav');
for (var i = 0; i < candidates.length; i++) {
var node = candidates[i];
var label = (node.getAttribute('aria-label') || '').toLowerCase();
if (label.indexOf('table of contents') !== -1 || label.indexOf('on this page') !== -1) {
return node;
}
}
var toc = document.querySelector('#table-of-contents, [data-toc], .toc');
if (toc) return toc.closest('aside') || toc.parentElement;
return null;
}
function inject() {
if (document.getElementById(CTA_ID)) return;
var host = findTocAside();
if (!host) return;
host.appendChild(buildCta());
}
function schedule() {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', inject);
} else {
inject();
}
}
schedule();
var observer = new MutationObserver(function () {
if (!document.getElementById(CTA_ID)) inject();
});
observer.observe(document.documentElement, { childList: true, subtree: true });
var origPush = history.pushState;
var origReplace = history.replaceState;
function onNav() { setTimeout(inject, 50); }
history.pushState = function () { var r = origPush.apply(this, arguments); onNav(); return r; };
history.replaceState = function () { var r = origReplace.apply(this, arguments); onNav(); return r; };
window.addEventListener('popstate', onNav);
})();