Commit 027534b3 authored by ronald's avatar ronald

Added handling on "No results" and not copy list images

parent a3696193
......@@ -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) {
......
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.length)
if(index+2 != reducedLength)
window.open("https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="+ a[index+2] + "&r=north");
},5000);
},5000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment