-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathokcdLikesToPdf.js
40 lines (32 loc) · 1.22 KB
/
okcdLikesToPdf.js
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
// Include jsPDF library in the script
(function() {
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js';
script.onload = extractUrlsAndGeneratePDF;
document.head.appendChild(script);
})();
function extractUrlsAndGeneratePDF() {
const { jsPDF } = window.jspdf;
// Define a regular expression pattern to match the specific URL structure
let pattern = /https:\/\/cdn\.okccdn\.com\/php\/load_okc_image\.php\/images\/225x225\/225x225\/\d+x\d+\/\d+x\d+\/2\/\d+\.jpeg/g;
// Get the entire HTML content of the page
let htmlContent = document.documentElement.innerHTML;
// Find all matching URLs
let matchingUrls = htmlContent.match(pattern) || [];
// Remove duplicates, if any
matchingUrls = [...new Set(matchingUrls)];
// Create a new jsPDF instance
const doc = new jsPDF();
// Add URLs to the PDF
let lineHeight = 10;
matchingUrls.forEach((url, index) => {
if (index !== 0 && index % 25 === 0) {
doc.addPage();
lineHeight = 10;
}
doc.text(url, 10, lineHeight);
lineHeight += 10;
});
// Save the PDF
doc.save('okcdLikes.pdf');
}