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
f87e8c53
Commit
f87e8c53
authored
Sep 08, 2020
by
joetsuihk
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' into 'master'
Updated extension (added handling and notifications) See merge request
!4
parents
a3c1fb13
efb74216
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
background.js
background.js
+19
-2
contentScript.js
contentScript.js
+23
-3
No files found.
background.js
View file @
f87e8c53
'use strict'
;
var
initial
=
0
;
var
skus
=
[];
var
noImages
=
""
;
chrome
.
declarativeContent
.
onPageChanged
.
removeRules
(
undefined
,
function
()
{
chrome
.
declarativeContent
.
onPageChanged
.
addRules
([{
...
...
@@ -13,12 +14,28 @@ 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 "
);
noImages
+=
(
request
.
currentSku
+
": no duplicate files
\n
"
);
initial
++
;
}
else
if
(
request
.
noImage
==
"true"
)
{
console
.
log
(
"Message : noImages"
);
noImages
+=
(
request
.
currentSku
+
": no results/ no valid images
\n
"
);
initial
+=
2
;
}
console
.
log
(
"Current index : "
,
initial
);
console
.
log
(
"Current noImages : "
,
noImages
);
});
chrome
.
downloads
.
onDeterminingFilename
.
addListener
(
function
(
item
,
suggest
)
{
var
new_filename
=
skus
[
initial
]
+
".zip"
;
suggest
({
filename
:
new_filename
});
initial
++
;
if
(
skus
.
length
-
1
==
initial
)
{
console
.
log
(
"Last file was downloaded"
);
alert
(
noImages
);
}
});
contentScript.js
View file @
f87e8c53
var
link
=
document
.
location
.
href
;
var
logined
=
false
;
//If at login site, fill in login infos
if
(
link
.
match
(
/login/g
)){
window
.
onload
=
function
()
{
...
...
@@ -16,29 +17,33 @@ if (link.match(/login/g)){
});
//If at asset page, automate scrollDown and fliter process
}
else
if
(
link
.
match
(
/asset
\?
/g
))
{
var
index
;
var
a
;
var
a
=
[];
var
index
=
0
;
var
noImage
=
false
;
//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
);
});
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
;
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 +70,16 @@ if (link.match(/login/g)){
}
});
downloadlist
=
document
.
querySelectorAll
(
".panel-inner .is-checked"
);
if
(
downloadlist
.
length
==
0
)
{
noImage
=
true
;
}
if
(
noImage
)
{
console
.
log
(
"Nothing to Download!! , index: "
,
index
,
" "
,
a
);
if
(
index
+
2
!=
a
.
length
)
window
.
open
(
"https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="
+
a
[
index
+
2
]
+
"&r=north"
);
chrome
.
runtime
.
sendMessage
({
noImage
:
"true"
,
currentSku
:
currentSku
});
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,6 +99,11 @@ 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"
,
currentSku
:
currentSku
});
}
secondList
.
forEach
(
function
(
a
)
{
a
.
click
();
});
...
...
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