-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (42 loc) · 1.62 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Share supporter</title>
</head>
<body>
<h1>Google Drive Share Supporter</h1>
<div>
<div fot="link">input share link (ex: https://drive.google.com/file/d/xxxxxxxxxxxxxxxxx/view?usp=sharing)</div>
<input type="text" id="link" style="width:50%;" />
<button onclick="changeLink()">Change to Viewer link</button>
<br />
<br />
<div id="viewer-link"></div>
</div>
<script>
const MATCH_FORM = new RegExp("https://drive.google.com/file/d/.+/view.*")
const LINK_FORM = "https://docs.google.com/viewer?pid=explorer&efh=false&a=v&chrome=false&embedded=true&srcid=";
const input = document.getElementById("link");
input.addEventListener("keyup", (e) => {
if (e.keyCode === 13) {
changeLink();
}
})
function changeLink() {
const viewerLink = document.getElementById("viewer-link");
const v = input.value;
if (!v.match(MATCH_FORM)) {
viewerLink.innerHTML = `<label style="color:red">Invalid link</label>: ${v}`
return;
}
const url = new URL(v);
const result = LINK_FORM + url.pathname.split("/")[3]; // /file/d/xxx/view?
viewerLink.innerHTML = `<div style="color:blue">COPIED!!</div>${result}`;
navigator.clipboard.writeText(result);
}
</script>
</body>
</html>