-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
184 lines (152 loc) · 5.53 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OnlyOffice Link Redirect</title>
<style>
/* Material styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
.instructions {
position: absolute;
top: 10px;
width: 80vw;
font-size: x-small;
background-color: #f9f9f9;
border-left: 6px solid #007bff;
margin-bottom: 20px;
padding: 10px 20px;
}
</style>
</head>
<body>
<div class="instructions">
<h2>This tool matches onlyoffice.eu URLs and redirects us to the corresponding office.wcrp-cmip.org.</h2>
<p></p>
<p></p>
<p> On redirect, the updated URL
is copied to the clipboard. Please use this to update the original link if possible. </p>
<br>
<code>
API Usage:
<br><br>
redirect.wcrp-cmip.org/url?<b>insert_url_here</b>
<br><br><br>
Alternatively, enter the `fileID` or onlyoffice.eu link in the cell below.
</code>
</div>
<br><br>
<script>
// Function to parse URL parameters
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
// Function to fetch data from the API
async function fetchData(id) {
await fetch(`mapping/${id}.json`)
.then(response => response.json())
.then(data => {
// Extract new_id from response
console.log(data)
var newId = data.new_id;
// Create new URL with new_id
var newUrl = 'https://office.wcrp-cmip.org/Products/Files/DocEditor.aspx?fileid=' + newId;
// Copy new URL to clipboard
if (navigator.clipboard) {
navigator.clipboard.writeText(newUrl)
.then(() => {
// Redirect to new URL
window.location.href = newUrl;
})
.catch(err => {
console.error('Failed to copy URL: ', err);
});
} else {
console.error(navigator);
window.location.href = newUrl;
}
})
.catch(error => {
console.error('Error fetching data:', error);
alert(`File id: ${id} not found. Please check your link and try again.`);
});
}
async function parseURL(url) {
var fileIdIndex = url.indexOf('fileid=');
if (fileIdIndex !== -1) {
fileId = url.substring(fileIdIndex + 7);
console.warn(fileId)
await fetchData(fileId);
} else {
console.error('File ID not found in URL');
}
}
// Main function to handle URL parameters
function main() {
var url = getUrlParameter('url');
var fileId = '';
if (url) {
parseURL(url).then(d => d)
} else {
// Create input form
var form = document.createElement('form');
form.innerHTML = '<input type="text" id="idInput" placeholder="Enter ID"><button id="submitButton">Submit</button>';
document.body.appendChild(form);
// Event listener for form submission
form.addEventListener('submit', function (event) {
event.preventDefault();
var input = document.getElementById('idInput');
var id = input.value;
if (id.includes('onlyoffice.eu')) {
parseURL(id).then(d => d)
} else if (!isNaN(parseInt(id))) {
fetchData(id).then(d => d);
} else {
alert(`Entry "${id}" is not a valid url or integer link. Please try again`)
}
});
}
}
// Call main function when page loads
window.onload = main;
</script>
</body>
</html>