Skip to content

Commit

Permalink
Merge pull request #16 from pt1602/bugfix/core-function
Browse files Browse the repository at this point in the history
fix(core): functionality restored
  • Loading branch information
pt1602 authored Jul 3, 2024
2 parents 117311d + f34fe20 commit 59b47bd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
36 changes: 21 additions & 15 deletions js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -42,24 +44,28 @@ 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);
}
}, 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) { }
}
});
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion options_page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h1>Options</h1>
<label>
Your instances:
<input type="text" data-url-input/>
<input type="text" data-url-input />
</label>
<p class="info">Multiple seperated by comma</p>
<button data-save>Save</button>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
40 changes: 27 additions & 13 deletions ts/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLSpanElement> = 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(
() => {},
() => {}
)
})
}

Expand All @@ -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)
Expand All @@ -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) {}
}
})
Expand Down

0 comments on commit 59b47bd

Please sign in to comment.