diff --git a/js/frontend.js b/js/frontend.js index a4524d6..a25367f 100644 --- a/js/frontend.js +++ b/js/frontend.js @@ -12,28 +12,30 @@ chrome.storage.sync.get(['url']).then((result) => { } urls.forEach((url) => { if (url === window.location.host) { - let cloneButtons = document.querySelectorAll('#ssh_project_clone, #http_project_clone'); + let cloneButtons = document.querySelectorAll('[data-testid="copy-ssh-url-button"], [data-testid="copy-http-url-button"]'); + let cloneInputs = document.querySelectorAll('#copy-ssh-url-input, #copy-http-url-input'); let cloneOptionsDropdown = document.querySelectorAll('.clone-options-dropdown > li > a'); let mobileCloneButtons = document.querySelector('.mobile-git-clone .clone-dropdown-btn'); + let mobileDropdownValues = document.querySelectorAll('.dropdown-menu-inner-content'); const currentPath = window.location.pathname; const beforeVal = 'git clone '; const copyNameBtnVal = 'Checkout'; - const copyNameBtnClasses = 'gl-display-none gl-md-display-block btn gl-button btn-default gl-mr-3'; + const copyNameBtnClasses = 'gl-hidden md:gl-block btn gl-button btn-default gl-mr-3'; let branchNameEl; - function modifyMobileCloneButtons() { - ; - mobileCloneButtons.dataset.clipboardText = - beforeVal + mobileCloneButtons.dataset.clipboardText; + function modifyMobileView() { + mobileCloneButtons.dataset.clipboardText = beforeVal + mobileCloneButtons.dataset.clipboardText; + mobileDropdownValues.forEach((item) => { + item.innerText = beforeVal + item.innerText; + }); } function createCopyBranchNameButton(branchNameEl) { const headerActions = document.querySelector('.detail-page-header-actions'); - const branchName = branchNameEl.innerHTML; let cloneBranchNameBtn = document.createElement('button'); cloneBranchNameBtn.className = copyNameBtnClasses; cloneBranchNameBtn.innerText = copyNameBtnVal; - if (branchName) { + if (branchNameEl) { cloneBranchNameBtn.addEventListener('click', () => { - navigator.clipboard.writeText('git fetch && git checkout ' + branchName + ' && git pull').then(() => { }, () => { }); + navigator.clipboard.writeText('git fetch && git checkout ' + branchNameEl.dataset.clipboardText + ' && git pull').then(() => { }, () => { }); }); } if (headerActions) { @@ -42,7 +44,7 @@ chrome.storage.sync.get(['url']).then((result) => { } if (currentPath.includes('merge_requests/')) { let checkInterval = window.setInterval(() => { - branchNameEl = document.querySelector('.label-branch a'); + branchNameEl = document.querySelector('.merge-request-details .btn-default-tertiary'); if (branchNameEl) { createCopyBranchNameButton(branchNameEl); clearInterval(checkInterval); @@ -50,16 +52,20 @@ chrome.storage.sync.get(['url']).then((result) => { }, 300); } try { - cloneButtons.forEach(function (item) { - ; + cloneButtons.forEach((item) => { + const currentVal = item.dataset.clipboardText; + item.setAttribute('data-clipboard-text', beforeVal + currentVal); + }); + cloneInputs.forEach((item) => { item.value = beforeVal + item.value; }); cloneOptionsDropdown.forEach((item) => { - item.addEventListener('click', modifyMobileCloneButtons); + item.addEventListener('click', modifyMobileView); }); - modifyMobileCloneButtons(); + modifyMobileView(); + } + catch (err) { } - catch (err) { } } }); }); diff --git a/manifest.json b/manifest.json index b104707..4bbb2d0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "GL Git Clone", "description": "Adds 'git clone' to the ssh/https clone url, so you simply can copy and paste it into your terminal.", - "version": "1.6", + "version": "2.0.0", "manifest_version": 3, "content_scripts": [ { diff --git a/options_page/index.html b/options_page/index.html index e282f45..4e0504b 100644 --- a/options_page/index.html +++ b/options_page/index.html @@ -14,7 +14,7 @@

Options

Multiple seperated by comma

diff --git a/package-lock.json b/package-lock.json index f002032..6ff7f3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gl-gitclone", - "version": "1.6.1", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gl-gitclone", - "version": "1.6.1", + "version": "2.0.0", "license": "MIT", "devDependencies": { "prettier": "^3.2.5", diff --git a/package.json b/package.json index d9118bf..e900e51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gl-gitclone", - "version": "1.6.1", + "version": "2.0.0", "description": "Adds 'git clone' to the ssh/https clone url, so you simply can copy and paste it into your terminal.", "main": "./js/frontend.js", "scripts": { diff --git a/ts/frontend.ts b/ts/frontend.ts index 7d4bd62..17a453b 100644 --- a/ts/frontend.ts +++ b/ts/frontend.ts @@ -12,33 +12,42 @@ chrome.storage.sync.get(['url']).then((result) => { urls.forEach((url: string) => { if (url === window.location.host) { - let cloneButtons: NodeList | null = document.querySelectorAll('#ssh_project_clone, #http_project_clone') + let cloneButtons: NodeList | null = document.querySelectorAll( + '[data-testid="copy-ssh-url-button"], [data-testid="copy-http-url-button"]' + ) + let cloneInputs: NodeList | null = document.querySelectorAll('#copy-ssh-url-input, #copy-http-url-input') let cloneOptionsDropdown: NodeList | null = document.querySelectorAll('.clone-options-dropdown > li > a') let mobileCloneButtons: HTMLElement | null = document.querySelector('.mobile-git-clone .clone-dropdown-btn') + let mobileDropdownValues: NodeListOf = document.querySelectorAll('.dropdown-menu-inner-content') const currentPath: string = window.location.pathname const beforeVal: string = 'git clone ' const copyNameBtnVal: string = 'Checkout' - const copyNameBtnClasses: string = 'gl-display-none gl-md-display-block btn gl-button btn-default gl-mr-3' + const copyNameBtnClasses: string = 'gl-hidden md:gl-block btn gl-button btn-default gl-mr-3' let branchNameEl: HTMLElement | null - function modifyMobileCloneButtons() { + function modifyMobileView() { ;(mobileCloneButtons! as HTMLInputElement).dataset.clipboardText = beforeVal + (mobileCloneButtons! as HTMLInputElement).dataset.clipboardText + + mobileDropdownValues.forEach((item) => { + item.innerText = beforeVal + item.innerText + }) } function createCopyBranchNameButton(branchNameEl: HTMLElement) { const headerActions: HTMLElement | null = document.querySelector('.detail-page-header-actions') - const branchName: string = branchNameEl.innerHTML let cloneBranchNameBtn: HTMLElement | null = document.createElement('button') cloneBranchNameBtn.className = copyNameBtnClasses cloneBranchNameBtn.innerText = copyNameBtnVal - if (branchName) { + if (branchNameEl) { cloneBranchNameBtn.addEventListener('click', () => { - navigator.clipboard.writeText('git fetch && git checkout ' + branchName + ' && git pull').then( - () => {}, - () => {} - ) + navigator.clipboard + .writeText('git fetch && git checkout ' + branchNameEl.dataset.clipboardText + ' && git pull') + .then( + () => {}, + () => {} + ) }) } @@ -49,7 +58,7 @@ chrome.storage.sync.get(['url']).then((result) => { if (currentPath.includes('merge_requests/')) { let checkInterval = window.setInterval(() => { - branchNameEl = document.querySelector('.label-branch a') + branchNameEl = document.querySelector('.merge-request-details .btn-default-tertiary') if (branchNameEl) { createCopyBranchNameButton(branchNameEl) @@ -59,15 +68,20 @@ chrome.storage.sync.get(['url']).then((result) => { } try { - cloneButtons.forEach(function (item) { + cloneButtons.forEach((item) => { + const currentVal = (item as HTMLButtonElement).dataset.clipboardText + ;(item as HTMLButtonElement).setAttribute('data-clipboard-text', beforeVal + currentVal) + }) + + cloneInputs.forEach((item) => { ;(item as HTMLInputElement).value = beforeVal + (item as HTMLInputElement).value }) cloneOptionsDropdown.forEach((item) => { - item.addEventListener('click', modifyMobileCloneButtons) + item.addEventListener('click', modifyMobileView) }) - modifyMobileCloneButtons() + modifyMobileView() } catch (err) {} } })