Commit fce4e9b4 authored by joetsuihk's avatar joetsuihk

Merge branch 'development' into 'master'

MR dev => master

See merge request !1
parents 55734f95 048dffe2
# Image Downlaoder Extension
Aim : To automate process of downloading images from ImageWork Library
## Installation
Step 1 : Git clone the project
```
git clone http://gitlab.documentonready.com:1234/root/gu-imageworks-extension.git
```
Step 2 : Go to the following [link](chrome://extensions/) and turn on developer mode.
Step 3 : Click 'Load Unpacked' and Select the Folder cloned.
Step 4 : Turn on the extension when use
'use strict';
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {schemes: ['http','https','www']},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
var initial = 0;
var a;
chrome.extension.onMessage.addListener(function(request,sender,sendResponse){
chrome.storage.local.get('idArray',function(item) {
a = item.idArray.split(',');
});
console.log(a);
});
chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
var new_filename = a[initial] + ".zip";
suggest({filename: new_filename});
initial++;
});
\ No newline at end of file
var link = document.location.href;
var logined = false;
if (link.match(/login/g)){
window.onload = function() {
document.querySelector("#login_input_user_name").value="myra@documentonready.com";
document.querySelector("#login_input_password").value="GUmyra12345";
document.querySelector(".jss70").click();
}
} else if (link == "https://digitallibrary-external.fastretailing.com/" && !logined) {
logined = true;
chrome.storage.local.get('idArray', function (items) {
var a = items.idArray.split(',');
document.location.href = ("https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="+ a[0] + "&r=north");
});
} else if (link.match(/asset\?/g)) {
var index;
var a;
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 el = document.querySelector(".jsx-334935779 .asset-list");
var count;
var scroll = setInterval(function() {
var currentScrollTop = el.scrollTop;
el.scrollBy(0,5000);
var scrolledTop = el.scrollTop;
if(scrolledTop - currentScrollTop == 0) {
count +=1;
} else {
count = 0;
}
if(count == 3) {
clearInterval(scroll);
var downloadlist = document.querySelectorAll(".panel-inner");
downloadlist.forEach(function(a) {
if(a.innerText.match(/(jpg|gif)/g)) {
a.click();
if(a.innerText.match(/^G/g)) {
if(!a.innerText.match(/Model/g))
a.click();
}
}
});
document.querySelector("#assets_btn_download_asset").click();
if(index+1 != a.length)
window.open("https://digitallibrary-external.fastretailing.com/asset?t=datacategory%2Fasset&w="+ a[index+1] + "&r=north");
}
},4000);
}
}
This diff is collapsed.
{
"name" : "Image Downloader",
"version" : "1.0",
"description" : "The extension for downloading images",
"background" : {
"scripts" : ["background.js"],
"persistent" : false
},
"manifest_version" : 2,
"permissions" : ["tabs","*://*/*","activeTab","<all_urls>","declarativeContent","storage","downloads"],
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"128": "images/Emoji-Nervous-icon.png"
}
},
"icons": {
"128": "images/Emoji-Nervous-icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["jquery.min.js","contentScript.js"]
}
]
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="jquery.min.js"></script>
<script src="require.js"></script>
</head>
<body>
<div class= "main">
<h1>Image Downloader</h1>
<form>
<label>SKU to download: </label>
<textarea row="5",cols="6"></textarea>
</form>
<button id ="input">Input</button>
<button id="go-to-google">Go to Library</button>
<script src="popup.js"></script>
</div>
</body>
</html>
\ No newline at end of file
let toGoogle = document.getElementById('go-to-google');
let inputButton = document.getElementById('input');
var idArray;
inputButton.onclick = function(element) {
console.log("hi");
var text = document.querySelector("textarea").value.trim().split('\n');
idArray = text.join(',');
}
toGoogle.onclick = function(element) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const execute = chrome.tabs.executeScript(tabs[0].id,
{code: `document.location.href = "https://digitallibrary-external.fastretailing.com/";`});
});
};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.url) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.storage.local.set({idArray : idArray}, function () {
console.log("set storage");
});
chrome.runtime.sendMessage(null);
});
}
});
\ No newline at end of file
This diff is collapsed.
* {
margin: 0;
padding: 0;
}
html{
background-color: black;
overflow: hidden;
font-family: Arial, Helvetica, sans-serif;
border: 2px solid grey;
}
body {
padding: 10px 10px 20px;
}
h1 {
font-size: 15px;
padding: 2px 5px;
color: white;
white-space: nowrap;
border-bottom: 1px solid white;
margin-bottom: 10px;
}
form {
padding: 0 5px;
}
label {
color: white;
}
#go-to-google {
padding: 10px 5px ;
margin-top: 20px;
outline: none;
position: relative;
left: 50%;
transform: translateX(-50%);
border-radius: 17px;
font-weight: 700;
background-color: purple;
color: white;
box-shadow: 0 0 11px 6px grey;
}
\ No newline at end of file
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