Skip to content

Commit a893816

Browse files
authored
feat: add check if version is latest (#1)
1 parent 68fd18c commit a893816

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

static/scripts/check_version.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*global document */
2+
(async function () {
3+
if (!window.location.href.includes('parseplatform.org')) {
4+
return;
5+
}
6+
const sdk = window.location.href.split('parseplatform.org/')[1].split('/')[0];
7+
if (sdk !== 'Parse-SDK-JS' && sdk !== 'parse-server') {
8+
return;
9+
}
10+
const location = window.location.href.split('api/');
11+
if (location.length === 1 || !location[1]) {
12+
return;
13+
}
14+
const apiVersion = location[1].split('/')[0];
15+
const { url } = await fetch(
16+
`https://unpkg.com/browse/parse${
17+
sdk === 'parse-server' ? '-server' : ''
18+
}/package.json`
19+
);
20+
const latest = url.split('@')[1].split('/')[0];
21+
if (apiVersion !== latest) {
22+
const main = document.getElementById('main');
23+
const alertDiv = document.createElement('div');
24+
alertDiv.style.width = '100%';
25+
alertDiv.style.paddingTop = '20px';
26+
alertDiv.style.textAlign = 'center';
27+
alertDiv.style.color = 'red';
28+
alertDiv.innerHTML = 'This version of the SDK is outdated.';
29+
const link = document.createElement('a');
30+
link.style.marginLeft = '10px';
31+
link.setAttribute('href', window.location.href.split(apiVersion)[0]);
32+
link.innerHTML = `Go to ${latest}`;
33+
alertDiv.appendChild(link);
34+
main.insertBefore(alertDiv, main.firstChild);
35+
}
36+
})();

tmpl/layout.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343

4444
<script>prettyPrint();</script>
4545
<script src="scripts/linenumber.js"></script>
46+
<script src="scripts/check_version.js"></script>
4647
</body>
4748
</html>

0 commit comments

Comments
 (0)