forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
23 lines (20 loc) · 889 Bytes
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function print(message, tag = 'pre') {
var element = document.createElement(tag);
element.innerHTML = message;
console.log('PRINT:', message);
document.getElementById('main').appendChild(element);
}
function makeGitHubLink(currentUrl, filePath) {
var prefix = currentUrl.split('//')[0];
var domainComponents = currentUrl.split('//')[1].split('/')[0].split('.');
var basePath = currentUrl.split('//')[1].split('/')[1];
basePath = '/' + basePath + (basePath.length ? '/' : '');
var targetDomain = (domainComponents.length > 1)
? 'github.com/' + domainComponents[0]
: domainComponents[0];
return prefix + '//' + targetDomain + basePath + (domainComponents.length > 1 ? 'blob/gh-pages/' : '') + filePath;
}
(function (elementId) {
var element = document.getElementById(elementId);
element.href = makeGitHubLink(location.href, 'index.js');
})('source-code');