diff --git a/src-chrome/main.js b/src-chrome/main.js index 7c0a79f..0ff7376 100644 --- a/src-chrome/main.js +++ b/src-chrome/main.js @@ -1,24 +1,27 @@ (function() { - var buttonElement = document.querySelector("a.get-repo-btn"); + const divElement = document.querySelector('.get-repo-modal div ul'); + if (!divElement) { return; } - if ( buttonElement === null ) { - return; - } + const linkElement = divElement.children[0].querySelector('a'); - buttonElement.removeAttribute('href'); - buttonElement.innerText = 'Open in Tower'; - buttonElement.setAttribute('aria-label', buttonElement.getAttribute('aria-label').replace('GitHub Desktop', 'Tower')); - buttonElement.removeAttribute('data-open-app'); + linkElement.removeAttribute('href'); + linkElement.innerText = 'Open in Tower'; + linkElement.removeAttribute('data-open-app'); + linkElement.style.cursor = 'pointer'; - buttonElement.addEventListener('click', function(event) { + linkElement.addEventListener('click', event => { event.preventDefault(); - var repoModalElement = buttonElement.parentElement.parentElement; - var inputElements = repoModalElement.querySelectorAll('input[type="text"]'); + const data = JSON.parse(linkElement.getAttribute('data-hydro-click')); + let repositoryURL = data.payload.originating_url; + + var repoModalElement = document.querySelector('.get-repo-modal'); var isSSH = repoModalElement.classList.contains('on'); - var activeInputElement = inputElements[isSSH ? 1 : 0]; + if (isSSH) { + repositoryURL = repositoryURL.replace('https://github.com/', 'git@github.com:'); + } - window.location.href = 'gittower://openRepo/' + encodeURI(activeInputElement.value); + window.location.href = 'gittower://openRepo/' + encodeURI(repositoryURL); }); -}()); \ No newline at end of file +}()); diff --git a/src-chrome/manifest.json b/src-chrome/manifest.json index d01f3cc..0476974 100644 --- a/src-chrome/manifest.json +++ b/src-chrome/manifest.json @@ -1,6 +1,10 @@ { "manifest_version": 2, + "permissions": [ + "activeTab", + "declarativeContent" + ], "name": "Clone to Tower for Github", "description": "Use Github's \"Open in Desktop\" Button with Tower", "author": "Gerard Delmàs", @@ -8,12 +12,10 @@ "icons": { "128": "icon.png" }, - "version": "1.2.0", - - "content_scripts": [ - { - "matches": ["*://github.com/*"], - "js": ["main.js"] - } - ] + "version": "2.0.0", + "content_scripts": [{ + "js": ["main.js"], + "matches": ["https://*.github.com/*"], + "all_frames": true + }] } \ No newline at end of file diff --git a/src-safari/GithubTower.safariextension/main.js b/src-safari/GithubTower.safariextension/main.js index 7c0a79f..0ff7376 100644 --- a/src-safari/GithubTower.safariextension/main.js +++ b/src-safari/GithubTower.safariextension/main.js @@ -1,24 +1,27 @@ (function() { - var buttonElement = document.querySelector("a.get-repo-btn"); + const divElement = document.querySelector('.get-repo-modal div ul'); + if (!divElement) { return; } - if ( buttonElement === null ) { - return; - } + const linkElement = divElement.children[0].querySelector('a'); - buttonElement.removeAttribute('href'); - buttonElement.innerText = 'Open in Tower'; - buttonElement.setAttribute('aria-label', buttonElement.getAttribute('aria-label').replace('GitHub Desktop', 'Tower')); - buttonElement.removeAttribute('data-open-app'); + linkElement.removeAttribute('href'); + linkElement.innerText = 'Open in Tower'; + linkElement.removeAttribute('data-open-app'); + linkElement.style.cursor = 'pointer'; - buttonElement.addEventListener('click', function(event) { + linkElement.addEventListener('click', event => { event.preventDefault(); - var repoModalElement = buttonElement.parentElement.parentElement; - var inputElements = repoModalElement.querySelectorAll('input[type="text"]'); + const data = JSON.parse(linkElement.getAttribute('data-hydro-click')); + let repositoryURL = data.payload.originating_url; + + var repoModalElement = document.querySelector('.get-repo-modal'); var isSSH = repoModalElement.classList.contains('on'); - var activeInputElement = inputElements[isSSH ? 1 : 0]; + if (isSSH) { + repositoryURL = repositoryURL.replace('https://github.com/', 'git@github.com:'); + } - window.location.href = 'gittower://openRepo/' + encodeURI(activeInputElement.value); + window.location.href = 'gittower://openRepo/' + encodeURI(repositoryURL); }); -}()); \ No newline at end of file +}());