Wiki source code of DriveParentCollab
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{html clean="false"}} |
| 2 | |||
| |
2.1 | 3 | <label for="driveURL">Drive document url</label> |
| 4 | <input type="text" id="driveURL" placeholder="Put drive document url here" /> | ||
| |
1.1 | 5 | <button id="opencollab">Open Collab</button> |
| 6 | <script> | ||
| 7 | (function() { | ||
| 8 | window.addEventListener("DOMContentLoaded", function() { | ||
| 9 | const openCollabButton = document.getElementById("opencollab"); | ||
| 10 | openCollabButton.addEventListener("click", findCollab); | ||
| 11 | }); | ||
| 12 | function findCollab() { | ||
| |
2.1 | 13 | const driveURL = document.getElementById("driveURL"); |
| |
2.2 | 14 | const driveId = getDriveId(driveURL.value); |
| |
1.1 | 15 | if(driveId) { |
| 16 | console.log('Perform request with id:', driveId); | ||
| |
6.1 | 17 | fetch(`/rest/v1/collabs?driveId=${driveId}`) |
| 18 | .then(res => res.json()) | ||
| 19 | .then(json => { | ||
| |
7.1 | 20 | console.log(json); |
| |
6.1 | 21 | const { link } = json; |
| |
7.1 | 22 | console.log(link) |
| 23 | // window.location.pathname = link; | ||
| |
6.1 | 24 | }) |
| |
1.1 | 25 | } |
| 26 | } | ||
| 27 | function getDriveId(driveURL) { | ||
| 28 | const url = new URL(driveURL); | ||
| |
4.1 | 29 | const re = /\/(library|lib)\/([^/]*)\/.*/; |
| |
5.1 | 30 | const id = re.exec(url.pathname)[2]; |
| |
1.1 | 31 | return id; |
| 32 | } | ||
| 33 | })(); | ||
| 34 | </script> | ||
| 35 | {{/html}} |