From d2fc5d30a58c81885b966d3b2615f736945bca79 Mon Sep 17 00:00:00 2001 From: v1nc Date: Thu, 7 May 2020 22:44:01 +0000 Subject: [PATCH 1/4] Fixed github links for apps for foked launchers Github links for apps are statically linked to github.com/espruino. These links are wrong if you run a fork App Launcher, probably with unpublished apps. I added onClick eventListeners for every github link that generate the right url, if the launcher is not accessed via the main domain. --- js/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index fdefa22d5..6d478fe5f 100644 --- a/js/index.js +++ b/js/index.js @@ -225,7 +225,7 @@ function refreshLibrary() {

${escapeHtml(app.name)} ${versionInfo}

${escapeHtml(app.description)}${app.readme?`
${readme}`:""}

- See the code on GitHub + See the code on GitHub
@@ -242,6 +242,22 @@ function refreshLibrary() { var tab = document.querySelector("#tab-librarycontainer a"); tab.classList.add("badge"); tab.setAttribute("data-badge", appJSON.length); + //github icon onClick + htmlToArray(panelbody.getElementsByClassName("link-github")).forEach(link => { + button.addEventListener("click",event => { + var username = window.location.href; + var url = "https://github.com/espruino/BangleApps/tree/master/apps/"+link.getAttribute("appid"); + if(!username.startsWith("https://banglejs.com/apps")){ + username = username.substr(0,username.lastIndexOf(".")); + if(username.startsWith("https://")){username=username.substr(8,username.length)} + if(username.startsWith("http://")){username=username.substr(7,username.length)} + if(username.startsWith("www.")){username=username.substr(4,username.length)} + username = username.substr(0,username.lastIndexOf(".")); + url = "https://github.com/"+username+"/BangleApps/tree/master/apps/"+link.getAttribute("appid"); + } + window.open(url); + }); + }); htmlToArray(panelbody.getElementsByTagName("button")).forEach(button => { button.addEventListener("click",event => { var button = event.currentTarget; From 2f87efe98c65d3bdebc241f471c46ae1c35cdf2a Mon Sep 17 00:00:00 2001 From: v1nc Date: Fri, 8 May 2020 00:58:21 +0200 Subject: [PATCH 2/4] fix typo --- js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index 6d478fe5f..061e18558 100644 --- a/js/index.js +++ b/js/index.js @@ -244,7 +244,7 @@ function refreshLibrary() { tab.setAttribute("data-badge", appJSON.length); //github icon onClick htmlToArray(panelbody.getElementsByClassName("link-github")).forEach(link => { - button.addEventListener("click",event => { + link.addEventListener("click",event => { var username = window.location.href; var url = "https://github.com/espruino/BangleApps/tree/master/apps/"+link.getAttribute("appid"); if(!username.startsWith("https://banglejs.com/apps")){ From 16004243a8c7c8caf078e22a9aad90aa697d74c4 Mon Sep 17 00:00:00 2001 From: v1nc Date: Fri, 8 May 2020 23:02:49 +0200 Subject: [PATCH 3/4] set href to replace onclick listener --- js/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/index.js b/js/index.js index 061e18558..cbab96880 100644 --- a/js/index.js +++ b/js/index.js @@ -244,7 +244,7 @@ function refreshLibrary() { tab.setAttribute("data-badge", appJSON.length); //github icon onClick htmlToArray(panelbody.getElementsByClassName("link-github")).forEach(link => { - link.addEventListener("click",event => { + var username = window.location.href; var url = "https://github.com/espruino/BangleApps/tree/master/apps/"+link.getAttribute("appid"); if(!username.startsWith("https://banglejs.com/apps")){ @@ -255,8 +255,8 @@ function refreshLibrary() { username = username.substr(0,username.lastIndexOf(".")); url = "https://github.com/"+username+"/BangleApps/tree/master/apps/"+link.getAttribute("appid"); } - window.open(url); - }); + link.href=url; + }); htmlToArray(panelbody.getElementsByTagName("button")).forEach(button => { button.addEventListener("click",event => { From 9be1fb1164460134d3ed60969a7c6c4315f5be2d Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 11 May 2020 08:28:23 +0100 Subject: [PATCH 4/4] Tweak github links so they don't break for localhost, and still open in a new window --- js/index.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/js/index.js b/js/index.js index cbab96880..7b896b782 100644 --- a/js/index.js +++ b/js/index.js @@ -218,6 +218,12 @@ function refreshLibrary() { if (versionInfo) versionInfo = " ("+versionInfo+")"; var readme = `Read more...`; var favourite = favourites.find(e => e == app.id); + + var username = "espruino"; + var githubMatch = window.location.href.match(/\/(\w+)\.github\.io/); + if(githubMatch) username = githubMatch[1]; + var url = `https://github.com/${username}/BangleApps/tree/master/apps/${app.id}`; + return `
${escapeHtml(app.name)}

@@ -225,7 +231,7 @@ function refreshLibrary() {

${escapeHtml(app.name)} ${versionInfo}

${escapeHtml(app.description)}${app.readme?`
${readme}`:""}

- See the code on GitHub + See the code on GitHub
@@ -242,22 +248,6 @@ function refreshLibrary() { var tab = document.querySelector("#tab-librarycontainer a"); tab.classList.add("badge"); tab.setAttribute("data-badge", appJSON.length); - //github icon onClick - htmlToArray(panelbody.getElementsByClassName("link-github")).forEach(link => { - - var username = window.location.href; - var url = "https://github.com/espruino/BangleApps/tree/master/apps/"+link.getAttribute("appid"); - if(!username.startsWith("https://banglejs.com/apps")){ - username = username.substr(0,username.lastIndexOf(".")); - if(username.startsWith("https://")){username=username.substr(8,username.length)} - if(username.startsWith("http://")){username=username.substr(7,username.length)} - if(username.startsWith("www.")){username=username.substr(4,username.length)} - username = username.substr(0,username.lastIndexOf(".")); - url = "https://github.com/"+username+"/BangleApps/tree/master/apps/"+link.getAttribute("appid"); - } - link.href=url; - - }); htmlToArray(panelbody.getElementsByTagName("button")).forEach(button => { button.addEventListener("click",event => { var button = event.currentTarget;