Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gu imageworks extension
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
joetsuihk
gu imageworks extension
Commits
027534b3
Commit
027534b3
authored
Sep 07, 2020
by
ronald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added handling on "No results" and not copy list images
parent
a3696193
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
6 deletions
+39
-6
background.js
background.js
+11
-2
contentScript.js
contentScript.js
+28
-4
No files found.
background.js
View file @
027534b3
...
...
@@ -13,8 +13,17 @@ chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
});
chrome
.
extension
.
onMessage
.
addListener
(
function
(
request
,
sender
,
sendResponse
){
skus
=
request
.
idArray
.
split
(
','
);
console
.
log
(
skus
);
if
(
request
.
idArray
)
{
skus
=
request
.
idArray
.
split
(
','
);
console
.
log
(
skus
);
}
else
if
(
request
.
nothing
==
"true"
)
{
console
.
log
(
"Message : nothing "
);
initial
++
;
}
else
if
(
request
.
noImage
==
"true"
)
{
console
.
log
(
"Message : noImages"
);
initial
+=
2
;
}
console
.
log
(
"Current index : "
,
initial
);
});
chrome
.
downloads
.
onDeterminingFilename
.
addListener
(
function
(
item
,
suggest
)
{
...
...
contentScript.js
View file @
027534b3
var
link
=
document
.
location
.
href
;
var
logined
=
false
;
var
a
=
[];
var
index
=
0
;
var
reducedLength
;
//If at login site, fill in login infos
if
(
link
.
match
(
/login/g
)){
window
.
onload
=
function
()
{
...
...
@@ -16,29 +19,37 @@ if (link.match(/login/g)){
});
//If at asset page, automate scrollDown and fliter process
}
else
if
(
link
.
match
(
/asset
\?
/g
))
{
var
index
;
var
a
;
//Get back the current sku's index from idArray
chrome
.
storage
.
local
.
get
(
'idArray'
,
function
(
items
)
{
a
=
items
.
idArray
.
split
(
','
);
var
sku
=
document
.
location
.
href
.
match
(
/
[
0-9
]{6}
/g
).
toString
();
index
=
a
.
indexOf
(
sku
);
reducedLength
=
a
.
length
;
});
console
.
log
(
"Array : "
,
a
);
window
.
onload
=
function
()
{
var
currentSku
=
document
.
location
.
href
.
match
(
/w=.*&/g
);
currentSku
=
currentSku
.
toString
().
replace
(
/
(
w=|&
)
/g
,
""
);
var
el
=
document
.
querySelector
(
".jsx-334935779 .asset-list"
);
var
count
;
if
(
el
.
innerText
.
match
(
"No Results"
))
{
console
.
log
(
"Nothing to Download!! , index: "
,
index
,
" "
,
a
);
window
.
open
(
"https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="
+
a
[
index
+
2
]
+
"&r=north"
);
chrome
.
runtime
.
sendMessage
({
noImage
:
"true"
});
return
;
}
var
count
=
0
;
//Scroll down every 4 second, if 3 times no scroll change, download images
var
scroll
=
setInterval
(
function
()
{
var
currentScrollTop
=
el
.
scrollTop
;
el
.
scrollBy
(
0
,
5000
);
var
scrolledTop
=
el
.
scrollTop
;
console
.
log
(
scrolledTop
-
currentScrollTop
);
if
(
scrolledTop
-
currentScrollTop
==
0
)
{
count
+=
1
;
}
else
{
count
=
0
;
}
console
.
log
(
"Count : "
,
count
);
if
(
count
==
3
)
{
clearInterval
(
scroll
);
var
downloadlist
=
document
.
querySelectorAll
(
".panel-inner"
);
...
...
@@ -65,6 +76,12 @@ if (link.match(/login/g)){
}
});
downloadlist
=
document
.
querySelectorAll
(
".panel-inner .is-checked"
);
if
(
downloadlist
.
length
==
0
)
{
console
.
log
(
"Nothing to Download!! , index: "
,
index
,
" "
,
a
);
window
.
open
(
"https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="
+
a
[
index
+
2
]
+
"&r=north"
);
chrome
.
runtime
.
sendMessage
({
noImage
:
"true"
});
return
;
}
// To prevent file loss for duplicate images name in zip file, will download twice for one sku
// Duplicated files download at second file "sku(copy).zip"
var
nameList
=
[];
...
...
@@ -84,12 +101,19 @@ if (link.match(/login/g)){
document
.
querySelector
(
"#assets_btn_download_asset"
).
click
();
//After first list download, download second list 5s later
setTimeout
(
function
(){
console
.
log
(
"Second List : "
,
secondList
);
if
(
secondList
.
length
==
0
)
{
console
.
log
(
"Second List has nothing"
);
chrome
.
runtime
.
sendMessage
({
nothing
:
"true"
});
reducedLength
--
;
console
.
log
(
"Reduced length : "
,
reducedLength
);
}
secondList
.
forEach
(
function
(
a
)
{
a
.
click
();
});
document
.
querySelector
(
"#assets_btn_download_asset"
).
click
();
setTimeout
(
function
(){
if
(
index
+
2
!=
a
.
l
ength
)
if
(
index
+
2
!=
reducedL
ength
)
window
.
open
(
"https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="
+
a
[
index
+
2
]
+
"&r=north"
);
},
5000
);
},
5000
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment