Skip to content

Commit 708f46d

Browse files
committed
update + fix
1 parent bf2fe4d commit 708f46d

File tree

4 files changed

+82
-39
lines changed

4 files changed

+82
-39
lines changed

scripts/ggdrive_downloadPdf.js

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
export default {
2-
icon: "https://drive.google.com/favicon.ico",
2+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.document
3+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.spreadsheet
4+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
5+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.openxmlformats-officedocument.wordprocessingml.document
6+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.openxmlformats-officedocument.presentationml.presentation
7+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.jgraph.mxfile
8+
// https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.jam
9+
// https://drive-thirdparty.googleusercontent.com/32/type/application/octet-stream
10+
// https://drive-thirdparty.googleusercontent.com/32/type/application/pdf
11+
// https://drive-thirdparty.googleusercontent.com/32/type/application/epub+zip
12+
// https://drive-thirdparty.googleusercontent.com/32/type/video/mp4
13+
// https://drive-thirdparty.googleusercontent.com/32/type/image/png
14+
// https://drive-thirdparty.googleusercontent.com/32/type/audio/mpeg
15+
// https://drive-thirdparty.googleusercontent.com/32/type/text/markdown
16+
icon: "https://ssl.gstatic.com/docs/doclist/images/mediatype/icon_3_pdf_x32.png",
317
name: {
418
en: "GG Drive - Download PDF",
519
vi: "GG Drive - Tải PDF",
@@ -33,33 +47,59 @@ export default {
3347
document.querySelectorAll(".ndfHFb-c4YZDc-cYSp0e-DARUcf")
3448
);
3549

36-
if (pageContainers.length === 0) {
50+
let pageCount = pageContainers.length;
51+
if (pageCount === 0) {
3752
alert("Pdf page not found");
3853
return;
3954
}
4055

41-
// let infiContainer = document.createElement("div");
42-
// infiContainer.innerHTML = UsefulScriptGlobalPageContext.DOM
43-
// .createTrustedHtml(`
44-
// <div style="${[
45-
// "position: fixed",
46-
// "left: 10px",
47-
// "top: 10px",
48-
// "color: white",
49-
// "background: #0007",
50-
// "padding: 10px",
51-
// "font-size: 20px",
52-
// ].join(";")}">
53-
// PDF: ${pageContainers.length} trang
54-
// </div>`);
55-
// let infoDiv = infiContainer.querySelector("div");
56-
// document.body.append(infiContainer);
57-
58-
for (let i = 0; i < pageContainers.length; i++) {
56+
let delay = prompt(
57+
`Tìm được ${pageCount} trang pdf\n\n` +
58+
"Sẽ bắt đầu quá trình scoll để tải các trang\n" +
59+
"Scroll trang chậm sẽ hạn chế lỗi không tải được trang pdf\n\n" +
60+
"Vui lòng nhập độ trễ chuyển trang (ms) (>0):\n",
61+
50
62+
);
63+
64+
if (!delay) return;
65+
66+
let id = "ufs_ggdrive_downloadPdf";
67+
let info = document.querySelector("#" + id);
68+
69+
if (!info) {
70+
info = document.createElement("div");
71+
info.id = id;
72+
info.style = [
73+
"position: fixed",
74+
"left: 50%",
75+
"top: 50%",
76+
"transform: translate(-50%, -50%)",
77+
"color: white",
78+
"background: #000d",
79+
"border-radius: 5px",
80+
"padding: 10px",
81+
"font-size: 20px",
82+
"z-index: 1000",
83+
].join(";");
84+
info.innerText = "ABC";
85+
document.body.appendChild(info);
86+
}
87+
88+
let startTime = Date.now();
89+
function formatTime(ms) {
90+
return new Date(ms).toISOString().slice(11, 19);
91+
}
92+
function getTime() {
93+
return formatTime(Date.now() - startTime);
94+
}
95+
96+
for (let i = 0; i < pageCount; i++) {
5997
let page = pageContainers[i];
6098
page.scrollIntoView();
61-
console.log("Đang scroll PDF: trang " + i + "...");
62-
await sleep(100);
99+
info.innerText =
100+
`Đang scroll PDF:` +
101+
`trang ${i + 1}/${pageCount}... (${getTime()}s)`;
102+
await sleep(delay);
63103
}
64104

65105
let canvasElement = document.createElement("canvas");
@@ -70,12 +110,13 @@ export default {
70110
document.querySelectorAll("img[src^='blob:']")
71111
).filter((_) => _.complete);
72112

73-
console.log(
74-
`Đang đợi các trang load xong: ${imgs.length}/${pageContainers.length}`
75-
);
113+
info.innerText =
114+
`Đang đợi các trang load xong: ` +
115+
`${imgs.length}/${pageCount}` +
116+
`(${getTime()}s)`;
76117

77118
if (imgs.length === pageContainers.length) {
78-
console.log("Đang tạo PDF...");
119+
info.innerText = "Đang tạo PDF...";
79120
clearInterval(checkImagesLoadedInterval);
80121

81122
let pdf;
@@ -100,10 +141,10 @@ export default {
100141
pdf.addImage(imgData, "JPEG", 0, 0);
101142
if (i < imgs.length - 1) pdf.addPage([img.width, img.height]);
102143
}
103-
// infiContainer.remove();
104-
pdf.save("download.pdf");
144+
info.remove();
145+
pdf.save((document.title || "download") + ".pdf");
105146
}
106-
}, 500);
147+
}, 1000);
107148
}
108149
);
109150
},

scripts/ggdrive_downloadPresentation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCurrentTab } from "./helpers/utils.js";
22

33
export default {
4-
icon: "https://drive.google.com/favicon.ico",
4+
icon: "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.openxmlformats-officedocument.presentationml.presentation",
55
name: {
66
en: "GG Drive - Download PowerPoint (Slides/Presentation)",
77
vi: "GG Drive - Tải PowerPoint (Slides)",

scripts/ggdrive_downloadVideo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "./helpers/utils.js";
77

88
export default {
9-
icon: "https://drive.google.com/favicon.ico",
9+
icon: "https://drive-thirdparty.googleusercontent.com/32/type/video/mp4",
1010
name: {
1111
en: "GG Drive - Download video",
1212
vi: "GG Drive - Tải video",

scripts/googleShortcuts.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ export default {
99
vi: "Tạo mới google doc/sheet/slide/form/site/keep/calendar",
1010
},
1111

12-
onClick: function () {
12+
onClickExtension: function () {
1313
let urls = [
14-
["Google Doc", "https://doc.new"],
15-
["Google Sheet", "https://sheet.new"],
16-
["Google Slide", "https://slide.new"],
17-
["Google Form", "https://form.new"],
18-
["Google Site", "https://site.new"],
19-
["Google Keep", "https://keep.new"],
14+
["Google Doc ", "https://doc.new"],
15+
["Google Sheet ", "https://sheet.new"],
16+
["Google Slide ", "https://slide.new"],
17+
["Google Form ", "https://form.new"],
18+
["Google Site ", "https://site.new"],
19+
["Google Keep ", "https://keep.new"],
2020
["Google Calendar", "https://calendar.new"],
2121
];
2222

2323
let option = prompt(
2424
"Create new:\n\n" +
25-
urls.map(([name, url], index) => `- ${index}: ${name}\n`).join(""),
25+
urls
26+
.map(([name, url], index) => `- ${index}: ${name} (${url})\n`)
27+
.join(""),
2628
0
2729
);
2830

0 commit comments

Comments
 (0)