| ... |
... |
@@ -1,7 +1,7 @@ |
| 1 |
1 |
{{html clean="false"}} |
| 2 |
2 |
|
| 3 |
|
-<label for="driveURL">Drive document url</label> |
| 4 |
|
-<input type="text" id="driveURL" placeholder="Put drive document url here" /> |
|
3 |
+<label for="driveUrl">Drive document url</label> |
|
4 |
+<input type="text" id="driveUrl" placeholder="Put drive document url here" /> |
| 5 |
5 |
<button id="opencollab">Open Collab</button> |
| 6 |
6 |
<script> |
| 7 |
7 |
(function() { |
| ... |
... |
@@ -10,23 +10,16 @@ |
| 10 |
10 |
openCollabButton.addEventListener("click", findCollab); |
| 11 |
11 |
}); |
| 12 |
12 |
function findCollab() { |
| 13 |
|
- const driveURL = document.getElementById("driveURL"); |
| 14 |
|
- const driveId = getDriveId(driveURL.value); |
|
13 |
+ const driveUrl = document.getElementById("driveUrl"); |
|
14 |
+ const driveId = getDriveId(driveURL); |
| 15 |
15 |
if(driveId) { |
| 16 |
16 |
console.log('Perform request with id:', driveId); |
| 17 |
|
- fetch(`/rest/v1/collabs?driveId=${driveId}`) |
| 18 |
|
- .then(res => res.json()) |
| 19 |
|
- .then(json => { |
| 20 |
|
- console.log(json); |
| 21 |
|
- const { link } = json; |
| 22 |
|
- window.location.pathname = link; |
| 23 |
|
- }) |
| 24 |
24 |
} |
| 25 |
25 |
} |
| 26 |
26 |
function getDriveId(driveURL) { |
| 27 |
27 |
const url = new URL(driveURL); |
| 28 |
|
- const re = /\/(library|lib)\/([^/]*)\/.*/; |
| 29 |
|
- const id = re.exec(url.pathname)[2]; |
|
21 |
+ const re = /\/library\/([^/]*)\/.*/; |
|
22 |
+ const id = re.exec(url.pathname)[1]; |
| 30 |
30 |
return id; |
| 31 |
31 |
} |
| 32 |
32 |
})(); |