-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
408 lines (378 loc) · 16.1 KB
/
Copy pathscript.js
File metadata and controls
408 lines (378 loc) · 16.1 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// ===== Dynamic Footer Description =====
function injectFooterDescription() {
const logoImg = document.querySelector('footer img[src*="logo"]') || document.querySelector('footer img[src*="light"]') || document.querySelector('footer img[src*="dark"]');
const logoLink = logoImg ? logoImg.closest('a') : (document.querySelector('footer a[href*="/docs"]') || document.querySelector('footer a[href="/"]'));
if (logoLink && !document.querySelector('footer .footer-description')) {
const desc = document.createElement('p');
desc.className = 'footer-description';
desc.textContent = 'Self-hosted payment orchestrator with multi-brand support, white-label domains, and 100+ payment gateways.';
logoLink.parentNode.insertBefore(desc, logoLink.nextSibling);
}
}
// ===== GEO: Structured Data (JSON-LD) =====
function injectStructuredData() {
// 1. SoftwareApplication - global, every page (product identity for search + AI)
if (!document.querySelector('script[data-ownpay-schema="app"]')) {
const appSchema = {
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "OwnPay",
"alternateName": "OwnPay Payment Orchestrator",
"applicationCategory": "FinanceApplication",
"operatingSystem": "Linux, Docker, cPanel, Plesk, DirectAdmin",
"description": "Self-hosted, open-source payment orchestrator with multi-brand support, 100+ payment gateways, white-label checkout, double-entry ledger, and full REST API. Licensed under AGPL-3.0, free forever.",
"url": "https://ownpay.org",
"image": "https://ownpay.org/docs/dashboard.jpg",
"screenshot": "https://ownpay.org/docs/dashboard.jpg",
"softwareVersion": "0.2.0",
"softwareHelp": {
"@type": "CreativeWork",
"url": "https://ownpay.org/docs"
},
"downloadUrl": "https://github.com/own-pay/OwnPay/releases",
"installUrl": "https://ownpay.org/docs/installation",
"license": "https://www.gnu.org/licenses/agpl-3.0.html",
"isAccessibleForFree": true,
"inLanguage": "en",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD",
"availability": "https://schema.org/InStock"
},
"author": {
"@type": "Organization",
"name": "OwnPay",
"url": "https://ownpay.org"
},
"maintainer": {
"@type": "Organization",
"name": "OwnPay",
"url": "https://ownpay.org"
},
"sameAs": [
"https://github.com/own-pay/OwnPay"
],
"featureList": [
"Multi-brand payment management with tenant isolation",
"100+ payment gateway integrations including Stripe, PayPal, bKash, Nagad, GCash",
"White-label checkout pages with custom domains",
"Double-entry ledger bookkeeping for financial integrity",
"REST API with Merchant, Mobile, and Admin endpoints",
"Webhook system for real-time event notifications",
"Plugin architecture for gateways, addons, and themes",
"Mobile SMS verification via Android companion app",
"Role-based access control with granular permissions",
"Self-hosted deployment on shared hosting, VPS, or Docker"
],
"speakable": {
"@type": "SpeakableSpecification",
"cssSelector": ["h1", "h2", ".description"]
}
};
const el = document.createElement('script');
el.type = 'application/ld+json';
el.setAttribute('data-ownpay-schema', 'app');
el.textContent = JSON.stringify(appSchema);
document.head.appendChild(el);
}
// 2. Organization - global, every page (brand identity for Knowledge Panel)
if (!document.querySelector('script[data-ownpay-schema="org"]')) {
const orgSchema = {
"@context": "https://schema.org",
"@type": "Organization",
"name": "OwnPay",
"url": "https://ownpay.org",
"logo": "https://ownpay.org/docs/logo/light.svg",
"description": "OwnPay is an open-source, self-hosted payment orchestrator for managing multiple brands, 100+ payment gateways, and white-label checkout experiences.",
"sameAs": [
"https://github.com/own-pay/OwnPay",
"https://x.com/ownpayorg",
"https://youtube.com/@ownpayorg",
"https://facebook.com/ownpay.org",
"https://plugins.ownpay.org",
"https://update.ownpay.org",
"https://facebook.com/groups/ownpay.org",
"https://blog.ownpay.org"
],
"contactPoint": {
"@type": "ContactPoint",
"email": "support@ownpay.org",
"contactType": "customer support",
"url": "https://github.com/own-pay/OwnPay/issues/new"
}
};
const el = document.createElement('script');
el.type = 'application/ld+json';
el.setAttribute('data-ownpay-schema', 'org');
el.textContent = JSON.stringify(orgSchema);
document.head.appendChild(el);
}
// 3. WebSite with SearchAction - global (enables sitelinks search box)
if (!document.querySelector('script[data-ownpay-schema="website"]')) {
const websiteSchema = {
"@context": "https://schema.org",
"@type": "WebSite",
"name": "OwnPay Documentation",
"url": "https://ownpay.org/docs",
"inLanguage": "en",
"publisher": {
"@type": "Organization",
"name": "OwnPay"
},
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://ownpay.org/docs/search?q={search_term_string}"
},
"query-input": "required name=search_term_string"
}
};
const el = document.createElement('script');
el.type = 'application/ld+json';
el.setAttribute('data-ownpay-schema', 'website');
el.textContent = JSON.stringify(websiteSchema);
document.head.appendChild(el);
}
// 4. BreadcrumbList - dynamic, based on current URL path
if (!document.querySelector('script[data-ownpay-schema="breadcrumb"]')) {
const path = window.location.pathname.replace(/^\/docs\/?/, '').replace(/\/$/, '');
if (path) {
const segments = path.split('/').filter(Boolean);
const itemListElement = [
{ "@type": "ListItem", "position": 1, "name": "Documentation", "item": "https://ownpay.org/docs" }
];
let currentPath = '';
segments.forEach((segment, index) => {
currentPath += '/' + segment;
const name = segment
.replace(/-/g, ' ')
.replace(/\b\w/g, c => c.toUpperCase());
itemListElement.push({
"@type": "ListItem",
"position": index + 2,
"name": name,
"item": "https://ownpay.org/docs" + currentPath
});
});
const breadcrumbSchema = {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": itemListElement
};
const el = document.createElement('script');
el.type = 'application/ld+json';
el.setAttribute('data-ownpay-schema', 'breadcrumb');
el.textContent = JSON.stringify(breadcrumbSchema);
document.head.appendChild(el);
}
}
// 5. FAQPage - ONLY on the FAQ page
if (window.location.pathname.includes('/advanced-topics/faq') && !document.querySelector('script[data-ownpay-schema="faq"]')) {
const faqSchema = {
"@context": "https://schema.org",
"@type": "FAQPage",
"name": "OwnPay Frequently Asked Questions",
"description": "Common questions and answers about OwnPay installation, licensing, payment gateways, plugins, SMS verification, and troubleshooting.",
"datePublished": "2025-01-01",
"dateModified": "2026-07-15",
"mainEntity": [
{
"@type": "Question",
"name": "What is OwnPay?",
"acceptedAnswer": {
"@type": "Answer",
"text": "OwnPay is a self-hosted payment orchestrator. It allows a single platform owner to manage multiple white-labeled merchant stores (brands) under one installation, with double-entry ledger bookkeeping, 100+ payment gateways, and Android SMS verification."
}
},
{
"@type": "Question",
"name": "Is OwnPay a SaaS platform?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No. OwnPay is infrastructure you deploy and own. You control the server, database, credentials, and data. No third-party has access to your transactions."
}
},
{
"@type": "Question",
"name": "Is OwnPay free?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, OwnPay is open-source and licensed under AGPL-3.0. You deploy it on your own server and pay only for your hosting and payment gateway processing fees. There are no licensing fees."
}
},
{
"@type": "Question",
"name": "How do I install OwnPay?",
"acceptedAnswer": {
"@type": "Answer",
"text": "OwnPay supports shared hosting (cPanel, Plesk, DirectAdmin), VPS, and Docker. Requirements: PHP 8.3+, MySQL 5.7+ or MariaDB 10.3+, 512MB RAM minimum. Upload files, create a database, and visit your domain to run the web installer."
}
},
{
"@type": "Question",
"name": "What payment gateways does OwnPay support?",
"acceptedAnswer": {
"@type": "Answer",
"text": "OwnPay supports 100+ payment gateways including Stripe, PayPal, bKash, Nagad, GCash, Square, Razorpay, bank transfers, and more. You can also build custom gateway plugins using the plugin system."
}
},
{
"@type": "Question",
"name": "How is OwnPay different from Stripe or PayPal?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Stripe and PayPal are payment processors. OwnPay is a payment orchestrator - it connects to multiple gateways (including Stripe and PayPal) and gives you a unified interface to manage all payment methods across multiple brands."
}
},
{
"@type": "Question",
"name": "What are the system requirements for OwnPay?",
"acceptedAnswer": {
"@type": "Answer",
"text": "PHP 8.3 or higher, MySQL 5.7+ or MariaDB 10.3+, 512MB RAM minimum (2GB+ recommended), 1GB disk space minimum, and an SSL certificate for production."
}
},
{
"@type": "Question",
"name": "Does OwnPay have an API?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes. OwnPay provides three REST APIs: Merchant API for payment operations, Mobile API for companion app integration, and Admin API for platform management. All APIs use Bearer token authentication and include webhook support."
}
}
]
};
const el = document.createElement('script');
el.type = 'application/ld+json';
el.setAttribute('data-ownpay-schema', 'faq');
el.textContent = JSON.stringify(faqSchema);
document.head.appendChild(el);
}
}
// ===== GEO: llms.txt Discovery Link (head link + body directive) =====
function injectLlmsTxtLink() {
// 1. <link> tag in <head> for crawlers that probe link relations
if (!document.querySelector('link[rel="llms-txt"]')) {
const link = document.createElement('link');
link.rel = 'llms-txt';
link.href = 'https://ownpay.org/docs/llms.txt';
document.head.appendChild(link);
}
// 2. Visually-hidden body directive for agents that read page body
// clip-rect technique: exists in DOM but invisible to sighted users
if (!document.querySelector('[data-llms-directive]')) {
const div = document.createElement('div');
div.setAttribute('data-llms-directive', 'true');
div.setAttribute('aria-hidden', 'true');
div.style.cssText = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
div.innerHTML = 'For the complete OwnPay documentation index, see <a href="https://ownpay.org/docs/llms.txt">llms.txt</a>. Pages are available as Markdown by appending <code>.md</code> to any URL.';
if (document.body.firstChild) {
document.body.insertBefore(div, document.body.firstChild);
} else {
document.body.appendChild(div);
}
}
}
// ===== Rewrite Native Issue Links Client-Side =====
function rewriteNativeIssueLinks() {
// Redirect docs repo issues to main OwnPay repo (docs repo should not have its own issues)
const selectors = [
'a[href*="OwnPay-Documentation/issues/new"]',
'a[href*="ownpay-docs/issues/new"]'
];
const links = document.querySelectorAll(selectors.join(', '));
links.forEach(link => {
const href = link.getAttribute('href');
if (href) {
const newUrl = href
.replace('OwnPay-Documentation/issues/new', 'OwnPay/issues/new')
.replace('ownpay-docs/issues/new', 'OwnPay/issues/new');
if (newUrl !== href) link.setAttribute('href', newUrl);
}
});
}
// ===== Dynamic Latest Version Download Logic =====
let isFetchingVersion = false;
async function fetchLatestVersion() {
const versionElements = document.querySelectorAll('[data-latest-version]');
const downloadElements = document.querySelectorAll('[data-latest-download]');
if (versionElements.length === 0 && downloadElements.length === 0) {
return;
}
// 1. Try Cache
try {
const cachedData = sessionStorage.getItem('ownpay_latest_version');
if (cachedData) {
const { version, downloadUrl } = JSON.parse(cachedData);
updateVersionDOM(versionElements, downloadElements, version, downloadUrl);
return;
}
} catch (e) {
// Ignore cache error
}
// 2. Fetch API
// AbortController: cancel if the server takes more than 5 seconds.
// Guide: AbortController and AbortSignal (Modern Web Guidance)
// priority: 'low': deprioritize so this does not compete with user requests.
// Guide: deprioritize-background-fetches (Modern Web Guidance)
if (isFetchingVersion) return;
isFetchingVersion = true;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
try {
const response = await fetch('https://update.ownpay.org/api/v1/release', {
signal: controller.signal,
priority: 'low'
});
clearTimeout(timeoutId);
if (!response.ok) throw new Error(`HTTP error ${response.status}`);
const data = await response.json();
if (data && data.latest) {
const version = data.latest.version;
const downloadUrl = data.latest.download_url && data.latest.download_url.github;
if (version && downloadUrl) {
sessionStorage.setItem('ownpay_latest_version', JSON.stringify({ version, downloadUrl }));
updateVersionDOM(versionElements, downloadElements, version, downloadUrl);
}
}
} catch (error) {
clearTimeout(timeoutId);
// Fail silently (includes AbortError from timeout)
} finally {
isFetchingVersion = false;
}
}
function updateVersionDOM(versionElements, downloadElements, version, downloadUrl) {
versionElements.forEach(el => {
if (el.textContent !== version) {
el.textContent = version;
}
});
downloadElements.forEach(el => {
if (el.getAttribute('href') !== downloadUrl) {
el.setAttribute('href', downloadUrl);
}
});
}
// ===== Initialize =====
function init() {
injectFooterDescription();
injectStructuredData();
injectLlmsTxtLink();
rewriteNativeIssueLinks();
fetchLatestVersion();
}
let initTimeout = null;
function debouncedInit() {
if (initTimeout) clearTimeout(initTimeout);
initTimeout = setTimeout(init, 100);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
const observer = new MutationObserver(debouncedInit);
observer.observe(document.body, { childList: true, subtree: true });