-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject-section.js
More file actions
53 lines (43 loc) · 2.21 KB
/
inject-section.js
File metadata and controls
53 lines (43 loc) · 2.21 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
const fs = require('fs');
const path = require('path');
const folderPath = './pinescript-strategies';
const htmlSnippetToInject = `
<section class="cta-section custom-strategy-cta">
<h2 class="cta-title">Enhance Your Trading</h2>
<p>Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.</p>
<p>This strategy runs in live mode on TradingView, helping you identify potential opportunities.</p>
<a href="https://offlinepixel.gumroad.com/l/trader-on-the-go" class="btn custom-btn" target="_blank" rel="noopener noreferrer">
Get Invite Only Script
</a>
</section>`;
async function injectHtmlIntoFiles() {
try {
const files = await fs.promises.readdir(folderPath);
console.log(`Found ${files.length} items in '${folderPath}'.`);
for (const file of files) {
if (path.extname(file).toLowerCase() === '.html') {
const filePath = path.join(folderPath, file);
try {
let fileContent = await fs.promises.readFile(filePath, 'utf8');
const targetTag = '</article>';
if (fileContent.includes(targetTag)) {
const modifiedContent = fileContent.replace(targetTag, htmlSnippetToInject + '\n' + targetTag);
await fs.promises.writeFile(filePath, modifiedContent, 'utf8');
console.log(`Successfully injected HTML into ${file}`);
} else {
console.warn(`'${targetTag}' not found in ${file}. Skipping injection.`);
}
} catch (readWriteError) {
console.error(`Error processing file ${file}:`, readWriteError.message);
}
} else {
console.log(`Skipping non-HTML file: ${file}`);
}
}
console.log('\nHTML injection process completed.');
} catch (dirError) {
console.error(`Error reading directory '${folderPath}':`, dirError.message);
console.error('Please ensure the folder path is correct and accessible.');
}
}
injectHtmlIntoFiles();