Skip to content

Commit

Permalink
Merge pull request #84 from ticalc-travis/generated-repo-links
Browse files Browse the repository at this point in the history
Enhancements to auto-generated repo links
  • Loading branch information
Legend-of-iPhoenix authored Mar 23, 2018
2 parents 5526568 + 11e0a1a commit 6f987dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ <h1 id="title">TheButton</h1>
</tr>
</table>
</div>

<br />
<!-- ripped shamelessly from the MDN -->
<script type="text/javascript">
var windowObjectReference = null; // global variable
Expand Down Expand Up @@ -85,6 +87,7 @@ <h1 id="title">TheButton</h1>
<div id="footer">
<!-- repo links generated automatically -->
<p id="repolink"></p>
<p id="livelink"></p>
<p id="about"><a href="/TheButton/about/" target="aboutPage" onclick="openAbout(); return false;">About</a></p>
<input type="button" value="Log Out" id="logoutbutton" class="hidden">
</div>
Expand Down
33 changes: 29 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,37 @@ if (location.href.endsWith("?logout")) {
work.
*/
var linkOverride;
/*
add strings to otherRepos (in “username/repo-name” format) as
desired to produce additional links for forks
*/
var otherRepos = [];
window.onload = e => {
var i = location.hostname.split("").reverse().join("").substring(10).split("").reverse().join(""),
t = "GitHub Repo: "
t += "legend-of-iphoenix" != i ? '<a href="https://github.com/' + i + location.pathname + '">This fork</a> | <a href="https://github.com/Legend-of-iPhoenix/TheButton">Original by _iPhoenix_</a>' : '<a href="https://github.com/Legend-of-iPhoenix/TheButton">Here</a>',
t = linkOverride ? 'GitHub Repo: <a href="'+linkOverride+'">This Fork</a> | <a href="https://github.com/Legend-of-iPhoenix/TheButton">Original by _iPhoenix_</a>':t;
document.getElementById("repolink").innerHTML = t
this_repo_url = (linkOverride ? linkOverride : 'https://github.com/' + i + '/' + location.pathname.split('/')[1]);
is_original = i == 'legend-of-iphoenix';
tr = 'GitHub repo: <a href="' + this_repo_url + '">' + (is_original ? 'Here' : i + ' (this fork)') + '</a>';
if (!is_original) tr += ' | <a href="https://github.com/Legend-of-iPhoenix/TheButton">Legend-of-iPhoenix (original)</a>';

tl = '';
if (!is_original) {
tl += '<b>' + i + '</b> | <a href="https://legend-of-iphoenix.github.io/TheButton/">Legend-of-iPhoenix</a>';
} else if (otherRepos.length) {
tl += '<b>' + i + '</b>';
}
for (i=0; i<otherRepos.length; i++) {
repo = otherRepos[i].split('/');
tr += ' | <a href="https://github.com/' + repo[0] + '/' + repo[1] + '">' + repo[0] + '</a>';
tl += (tl ? ' | ' : '') + '<a href="https://' + repo[0] + '.github.io/' + repo[1] + '">' + repo[0] + '</a>';
}
if (tl) tl = 'Live site: ' + tl;

document.getElementById("repolink").innerHTML = tr;
if (tl) {
document.getElementById("livelink").innerHTML = tl;
} else {
document.getElementById("livelink").remove();
}
document.getElementById("logoutbutton").onclick = function() {
firebase.auth().signOut();
location.reload();
Expand Down

0 comments on commit 6f987dc

Please sign in to comment.