Skip to content

Commit d27c7b8

Browse files
committed
Merge branch 'hotfix/1.0.6'
2 parents 7a73dad + 4d98edf commit d27c7b8

12 files changed

+302
-245
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Gitd Download Manager Browser Extension
22

3-
It is a browser extension that allows you to download only the files/folders you want without having to download all of the public repository. Github.com, Bitbucket.org, Gitlab.com provides all of the public repos in git services to download selected files and folders as a zip files with a single click, without the need for any API key or token.
3+
It is a browser extension that allows you to download only the files/folders you want without having to download all of the public repository. Github.com, Bitbucket.org, Gitlab.com, Gitea.com provides all of the public repos in git services to download selected files and folders as a zip files with a single click, without the need for any API key or token.
44

5-
The "Gitd Start" button is ready for use on every screen you see.
5+
If you see "Gitd Start" button, It is ready for use on every screen you see. You have to to click (checkboxes appears) and can starting to select files.
66

77
> Note: Gitd Download Manager browser extension creates download lists using Gitdownloadmanager.com api service.
88
99
![video](gif/gitdmanager.gif)
1010

1111
## Features
1212

13-
- Support only Github.com, Bitbucket.org, Gitlab.com public repositories page
13+
- Support only Github.com, Bitbucket.org, Gitlab.com, Gitea.com public repositories page
1414
- Not neeeded ApiKey/ApiToken
1515
- Support single or multiple files download
1616
- Download selected contents as a zip file with one click
1717
- Support all branches
18-
- Maximum Selection Limit: 5
19-
- Maximum Download Files: 5000
18+
- Maximum Selection Limit: 10
19+
- Maximum Download Files: 10000
2020

2121
![screenshot](screenshots/gitd-manager-github-download.jpeg)
2222

@@ -113,6 +113,13 @@ See LICENSE for more details.
113113

114114
## Changelog
115115

116+
v1.0.6
117+
118+
- add Gitea.com service
119+
- increased selection limit and files
120+
- remove auto initialize all of the services. excepts Github.com
121+
- remove Github.com turbo event listeners
122+
116123
v1.0.5
117124

118125
- fix checkboxes not working when browser back event

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.4
1+
1.0.6

extension/background.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ let urlFilters = {
2727
{
2828
hostEquals:'bitbucket.org',
2929
schemes:["https"]
30+
},
31+
{
32+
hostEquals:'gitea.com',
33+
schemes:["https"]
3034
}
3135
]
3236
}
@@ -44,11 +48,21 @@ chrome.webNavigation.onCompleted.addListener(function (details) {
4448
})
4549
}, urlFilters)
4650

47-
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
48-
chrome.tabs.sendMessage(details.tabId, {
49-
action: 'IM_CHANGED'
50-
})
51-
}, urlFilters)
51+
// adds a listener to tab change
52+
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
53+
// check for a URL in the changeInfo parameter (url is only added when it is changed)
54+
if (changeInfo.url) {
55+
chrome.tabs.sendMessage(tabId, {
56+
action: 'URL_CHANGED'
57+
})
58+
}
59+
})
60+
61+
// chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
62+
// chrome.tabs.sendMessage(details.tabId, {
63+
// action: 'IM_CHANGED'
64+
// })
65+
// }, urlFilters)
5266

5367
// gitdmanager api request listener
5468
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {

extension/contentScript.js

Lines changed: 91 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,52 @@
22

33
// declare debug mode var
44
let gitdDebugMode = false
5+
let gitdProcessRunning = false
6+
7+
// templates
8+
const gitdInitTemplateContainer = `<div id="gitd-container-template"><div class="gitd-shortcut-button">
9+
<button id="gitdStartButton" @click="activateGitdInit" type="button" class="gitd-btn gitd-btn-sm gitd-btn-warning">
10+
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor" class="bi bi-card-checklist" viewBox="0 0 16 16">
11+
<path d="M14.5 3a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5h-13a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h13zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"/>
12+
<path d="M7 5.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm-1.496-.854a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0l-.5-.5a.5.5 0 1 1 .708-.708l.146.147 1.146-1.147a.5.5 0 0 1 .708 0zM7 9.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm-1.496-.854a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0l-.5-.5a.5.5 0 0 1 .708-.708l.146.147 1.146-1.147a.5.5 0 0 1 .708 0z"/>
13+
</svg>
14+
<span x-text="gitdInitText">Gitd Start</span>
15+
</button>
16+
</div></div>`
17+
18+
// track body change (x-data)
19+
// trackBodyAttributes("x-data")
520

621
// listen runtime message from bg
722
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
823
switch (request.action) {
9-
case "IM_CHANGED":
24+
/*case "IM_CHANGED":
1025
// Dom Content Loading but not finish
11-
if (isDebugActive()) console.log("content-script", "im changed")
26+
if (gitdDebugMode) console.log("content-script", "im changed")
1227
13-
// inject templates
14-
injectGitdTemplates()
28+
// start process
29+
// initGitdProcess("IM_CHANGED")
1530
16-
setTimeout(function() {
17-
// Trigger the button element with a click
18-
triggerGitdStart()
19-
}, 1500)
20-
21-
break;
31+
break;*/
2232
/*case "IM_LOADING":
2333
// Dom Content Loading but not finish
24-
if (isDebugActive()) console.log("content-script", "im loading")
34+
if (gitdDebugMode) console.log("content-script", "im loading")
2535
2636
break;*/
37+
case "URL_CHANGED":
38+
// url changed
39+
if (gitdDebugMode) console.log("content-script", "url changed")
40+
41+
// start process
42+
initGitdProcess("URL_CHANGED")
43+
44+
break;
2745
case "IM_READY":
2846
// Everything Loading finished. Ready to use.
29-
if (isDebugActive()) console.log("content-script", "im ready")
30-
31-
// inject templates
32-
injectGitdTemplates()
47+
if (gitdDebugMode) console.log("content-script", "im ready")
3348

34-
setTimeout(function() {
35-
// Trigger the button element with a click
36-
triggerGitdStart()
37-
}, 1500)
49+
// start process
50+
initGitdProcess("IM_READY")
3851

3952
// inject gitdmanager
4053
injectGitdScripts("lib/gitdmanager.js")
@@ -52,12 +65,13 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
5265
});
5366

5467
// listen browser submit event
68+
// via: chrome dev tools: getEventListeners(window) -> return all events
5569
// Request: gitdmanager (browser) -> contentScript -> background
5670
// Response: background -> contentScript -> gitdmanager (browser)
5771
window.addEventListener("submit-action", function(evt) {
58-
if (isDebugActive()) console.log("content-script","submit-action", evt.detail)
72+
if (gitdDebugMode) console.log("content-script","submit-action", evt.detail)
5973
chrome.runtime.sendMessage(JSON.parse(evt.detail), function(response) {
60-
if (isDebugActive()) console.log("bg-response", response);
74+
if (gitdDebugMode) console.log("bg-response", response);
6175

6276
window.dispatchEvent(new CustomEvent(
6377
'submit-action-response',
@@ -72,37 +86,75 @@ window.addEventListener("submit-action", function(evt) {
7286
// via: chrome dev tools: getEventListeners(window) -> return all events
7387
// only for github "turbo:load" event listen
7488
// window.addEventListener("turbo:load", function(evt) {
75-
// if (isDebugActive()) console.log("content-script", "turbo:load", evt)
76-
77-
// setTimeout(function() {
78-
// // inject templates
79-
// injectGitdTemplates()
89+
// if (gitdDebugMode) console.log("content-script", "turbo:load", evt)
8090

81-
// // init checkboxes
82-
// initQuickSelectionCheckboxes()
83-
// }, 1500)
91+
// // start process
92+
// initGitdProcess("turbo:load")
8493

8594
// }, false);
8695

8796
// debug mode listener
8897
window.addEventListener("debug-mode-changed", function(evt) {
89-
if (isDebugActive()) console.log("content-script", "debug-mode-changed", evt)
98+
if (gitdDebugMode) console.log("content-script", "debug-mode-changed", evt)
9099

91100
gitdDebugMode = evt.detail
92101

93102
}, false);
94103

95-
// check debug mode
96-
function isDebugActive() {
97-
return gitdDebugMode
98-
}
104+
// init gitd with process control
105+
function initGitdProcess(where) {
106+
if (gitdProcessRunning) {
107+
if (gitdDebugMode) console.log("gitdProcessRunning is not finished yet", where);
108+
return
109+
}
110+
111+
// process start
112+
gitdProcessRunning = true
113+
114+
if (document.getElementById("gitdStartButton") === null) {
115+
/////////////////// inject templates
116+
// remove template
117+
if (document.getElementById("gitd-container-template")) {
118+
document.getElementById("gitd-container-template").remove()
119+
}
99120

100-
// inject templates
101-
function injectGitdTemplates() {
102-
if (!document.body.hasAttribute("x-data")) {
121+
// remove checkboxes if exists
122+
let gitdCheckboxes = document.querySelectorAll(".gitd-tree-checkbox-container")
123+
if (gitdCheckboxes.length > 0) {
124+
// remove checkbox
125+
gitdCheckboxes.forEach(e => e.remove())
126+
}
127+
128+
// add x-data and template container
103129
document.body.setAttribute("x-data", "gitdManager")
104-
document.body.insertAdjacentHTML("beforeend", gitdInitTemplate)
130+
document.body.insertAdjacentHTML("beforeend", gitdInitTemplateContainer)
105131
}
132+
133+
//////////////////// triggger button
134+
// if (where === "IM_CHANGED") {
135+
// hostname
136+
let hostname = window.location.hostname
137+
138+
if (hostname === "github.com") {
139+
setTimeout(function() {
140+
if (gitdDebugMode) console.log("triggerGitdStart");
141+
142+
let gitdStartButton = document.getElementById("gitdStartButton")
143+
if ( !!gitdStartButton && (gitdStartButton.getAttribute("data-trigger") === null || where === "URL_CHANGED") ) {
144+
if (gitdDebugMode) console.log("gitdStartButton", "trigger", "click", gitdStartButton)
145+
146+
gitdStartButton.setAttribute("data-trigger", where)
147+
gitdStartButton.click()
148+
}
149+
150+
// process finished
151+
gitdProcessRunning = false
152+
}, 1500)
153+
}
154+
// }
155+
156+
// // process finished
157+
// gitdProcessRunning = false
106158
}
107159

108160
// inject scripts
@@ -113,71 +165,5 @@ function injectGitdScripts(scrPath) {
113165
s.parentNode.removeChild(s);
114166
};
115167
(document.body || document.documentElement).appendChild(s)
116-
if (isDebugActive()) console.log("injectGitdScripts", s);
117-
}
118-
119-
// trigger gitdStartButton
120-
function triggerGitdStart() {
121-
let gitdStartButton = document.getElementById("gitdStartButton")
122-
if (!!gitdStartButton) {
123-
if (isDebugActive()) console.log("gitdStartButton", "trigger", "click", gitdStartButton)
124-
gitdStartButton.click()
125-
}
168+
if (gitdDebugMode) console.log("injectGitdScripts", s);
126169
}
127-
128-
// init quick selection checkboxes
129-
// function initQuickSelectionCheckboxes() {
130-
// // check gitd-init attribute
131-
// if (document.querySelector(".gitd-tree-checkbox") === null) {
132-
133-
// // check new design
134-
// let newDesign = false
135-
136-
// // checkbox add
137-
// let navItem = document.querySelectorAll("div.js-navigation-item > div:first-child > svg") // old design
138-
// if (navItem.length == 0) {
139-
// navItem = document.querySelectorAll("table > tbody > tr > td > div.react-directory-filename-column > svg") // new design
140-
// newDesign = true
141-
// }
142-
143-
// if (navItem.length > 0) {
144-
145-
// // inject checkbox
146-
// for (const key in navItem) {
147-
// if (Object.hasOwnProperty.call(navItem, key)) {
148-
// const element = navItem[key];
149-
150-
// // type: none: 0 - file: 1 - folder: 2
151-
// let itemType = element.getAttribute("aria-label") // old desing
152-
// if (newDesign) {
153-
// itemType = element.getAttribute("class") // new design
154-
// }
155-
156-
// if (itemType === "Directory") {
157-
// itemType = 2
158-
// } else if (itemType === "File") {
159-
// itemType = 1
160-
// } else if (itemType == "icon-directory") {
161-
// itemType = 2
162-
// } else {
163-
// itemType = 1
164-
// }
165-
166-
// let pathElement = element.parentElement.nextElementSibling?.querySelector("div > span > a") // old desing
167-
// if (newDesign) {
168-
// pathElement = element.parentElement.querySelector("div.overflow-hidden > h3 > div > a") // new design
169-
// }
170-
171-
// if (!!pathElement) {
172-
// let insertPosition = "beforebegin"
173-
// if (newDesign) {
174-
// insertPosition = "afterbegin"
175-
// }
176-
177-
// element.parentElement.insertAdjacentHTML(insertPosition, "<div role=\"gridcell\" class=\"mr-3 flex-shrink-0\"><input class=\"gitd-tree-checkbox\" type=\"checkbox\" data-name=\""+pathElement.innerText+"\" data-type=\""+itemType+"\" @click=\"toggleSelectList\"></div>")
178-
// }
179-
// }
180-
// }
181-
// }
182-
// }
183-
// }

0 commit comments

Comments
 (0)