Commit efb74216 authored by ronald's avatar ronald

added handling for no result and no second list images, added notification

parent 027534b3
'use strict';
var initial = 0;
var skus = [];
var noImages = "";
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
......@@ -18,16 +19,23 @@ chrome.extension.onMessage.addListener(function(request,sender,sendResponse){
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);
}
});
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() {
......@@ -19,24 +17,20 @@ if (link.match(/login/g)){
});
//If at asset page, automate scrollDown and fliter process
} else if (link.match(/asset\?/g)) {
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);
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");
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() {
......@@ -77,9 +71,13 @@ 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);
window.open("https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="+ a[index+2] + "&r=north");
chrome.runtime.sendMessage({noImage : "true"});
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
......@@ -104,16 +102,14 @@ if (link.match(/login/g)){
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);
chrome.runtime.sendMessage({nothing : "true", currentSku : currentSku});
}
secondList.forEach(function(a) {
a.click();
});
document.querySelector("#assets_btn_download_asset").click();
setTimeout(function(){
if(index+2 != reducedLength)
if(index+2 != a.length)
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