Skip to content

Commit f2d4fe7

Browse files
committed
Update api-link-parser.js
1 parent 26afc61 commit f2d4fe7

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

api-link-parser.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function decodeLink(url) {
1515
url = decodeURIComponent(url);
1616

1717

18-
const isEmbed = urlQuery.has('embed');
18+
const isEmbed = (window.top !== window);
1919

2020
const isLiveViewDisabled = (urlQuery.get('live') === 'false' || urlQuery.get('l') === 'f');
2121

@@ -99,35 +99,32 @@ function decodeLink(url) {
9999
// show file in live view
100100
linkData.openLive = true;
101101

102-
} else if (isEmbed) { // if link is embed
103-
104-
// show file link
105-
linkData.redirect = baseURL + '/full?dir=' +
106-
linkData.user + ',' + linkData.repo +
107-
',' + linkData.contents +
108-
'&file=' + linkData.file;
109-
110-
linkData.redirectText = 'Open ' + linkData.user + '/' + linkData.repo + ' with Codeit';
111-
112102
} // else, show the file's code
113103

114104
} else if (isEmbed) { // if linking to directory
115105
// and link is embed
116106

117107
// show directory link
118-
linkData.redirect = baseURL + '/full?dir=' +
108+
linkData.redirect = encodeURIComponent(
109+
baseURL + '/full?dir=' +
119110
linkData.user + ',' + linkData.repo +
120-
',' + linkData.contents;
111+
',' + linkData.contents
112+
);
121113

122-
linkData.redirectText = 'Open ' + linkData.user + '/' + linkData.repo + ' with Codeit';
114+
linkData.redirectText = encodeURI(
115+
'Open ' +
116+
linkData.user + '/' +
117+
linkData.repo.split(':')[0] +
118+
' with Codeit'
119+
);
123120

124121
}
125122

126123
} else {
127124

128125
// show codeit link
129-
linkData.redirect = baseURL + '/full';
130-
linkData.redirectText = 'Open Codeit';
126+
linkData.redirect = encodeURIComponent(baseURL + '/full');
127+
linkData.redirectText = encodeURI('Open Codeit');
131128

132129
}
133130

0 commit comments

Comments
 (0)