Skip to content

Commit f52d524

Browse files
Use optional chaining when reading meta title in README script
1 parent 1ace732 commit f52d524

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Google-Drive-View-Only-PDF-Script-Downloader
2-
1+
```markdown
32
Here you can use this script to download view only pdf file from Google Drive. This script works like a screenshot capturing all pdf pages to bulk of images with better resolution quality and combine it all into one pdf file.
43

54
### Big-Note: Use this script wisely!
@@ -87,8 +86,11 @@ Here you can use this script to download view only pdf file from Google Drive. T
8786
}
8887

8988
// check if title contains .pdf in end of the title
90-
let title = document.querySelector('meta[itemprop="name"]').content;
91-
if (title.split(".").pop() !== "pdf") {
89+
// Use optional chaining to avoid errors if the meta tag isn't present.
90+
// Fall back to document.title when necessary. Note: if the PDF is inside a cross-origin iframe,
91+
// parent scripts cannot access the iframe document due to same-origin policy.
92+
let title = document.querySelector('meta[itemprop="name"]')?.content || document.title || 'download.pdf';
93+
if ((title.split(".").pop() || "").toLowerCase() !== "pdf") {
9294
title = title + ".pdf";
9395
}
9496

@@ -126,3 +128,4 @@ Here you can use this script to download view only pdf file from Google Drive. T
126128
This script is modified with source from :
127129
- [mhsohan/How-to-download-protected-view-only-files-from-google-drive-](https://github.com/mhsohan/How-to-download-protected-view-only-files-from-google-drive-)
128130
- [zeltox/Google-Drive-PDF-Downloader](https://github.com/zeltox/Google-Drive-PDF-Downloader)
131+
```

0 commit comments

Comments
 (0)