shujo / listings-data-crawler

// ==UserScript==
// @name         listings-data-crawler
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Grab data from different websites.
// @author       josh&chris
// @license      MIT
// @icon         https://img.icons8.com/color/48/000000/bot.png
// @match        https://www.outbacktrading.com/*
// @match        https://www.nike.com/t/*
// @match        https://www.dockers.com/*
// @match        https://shop.roshommerson.com/pages/*
// @match        https://www.mountainhardwear.com/*
// @match        http://jamaoldwest.com/*
// @match        https://www.kuhl.com/kuhl/*
// @match        https://www.hanwag.com/shop/*
// @match        https://www.vans.com/shop/*
// @match        https://www.olukai.com/*
// @match        https://www.amazon.com/dp/*
// @match        https://www.chacos.com/US/en/*
// @match        https://www.tyr.com/shop/*
// @match        https://www.thefryecompany.com/*
// @match        https://palladiumboots.com/*
// @match        https://brandportal.asicsamerica.com/*
// @match        https://search.thefryecompany.com/*
// @match        https://www.quiksilver.com/*
// @match        https://www.fitflop.com/*
// @match        https://sellercentral.amazon.com/productsearch*
// @grant        GM_notification
// @run-at       document-end
// @require      http://code.jquery.com/jquery-3.3.1.min.js

// ==/UserScript==

(function() {
    'use strict';
    document.body.onkeyup = function(e){
        if(e.ctrlKey && e.keyCode == 13){ //keyboard shortcut: ctrl key + enter
            let url = $(location).attr("href");
            let mergeData = "";
            if(url.indexOf('www.outbacktrading.com') >= 0){
                mergeData = outbacktrading();
            }else if(url.indexOf('https://www.nike.com/t/') >= 0){
                mergeData = hurley();
            }else if(url.indexOf('https://www.dockers.com/US/en_US') >= 0){
                mergeData = dockersApparel();
            }else if(url.indexOf('https://shop.roshommerson.com/pages/') >= 0){
                mergeData = drewshoe();
            }else if(url.indexOf('https://www.mountainhardwear.com/') >= 0){
                mergeData = mountainhardwear();
            }else if(url.indexOf('http://jamaoldwest.com/') >= 0){
                mergeData = oldwest();
            }else if(url.indexOf('https://www.kuhl.com/kuhl/') >= 0){
                mergeData = kuhl();
            }else if(url.indexOf('https://www.hanwag.com/shop/') >= 0){
                mergeData = hanwag();
            }else if(url.indexOf('https://www.vans.com/shop/') >= 0){
                mergeData = vans();
            }else if(url.indexOf('https://www.olukai.com/') >= 0){
                mergeData = olukai();
            }else if(url.indexOf('https://www.chacos.com/US/en/') >= 0){
                mergeData = chaco();
            }else if(url.indexOf('https://www.tyr.com/shop/') >= 0){
                mergeData = tyr();
            }else if(url.indexOf('https://sellercentral.amazon.com/productsearch') >= 0){
                mergeData = addproduct();
            }else if(url.indexOf('https://www.thefryecompany.com/') >= 0){
                mergeData = frye();
            }else if(url.indexOf('https://palladiumboots.com/') >= 0){
                mergeData = palladium();
            }else if(url.indexOf('https://brandportal.asicsamerica.com/') >= 0){
                mergeData = asicsimages();
            }else if(url.indexOf('https://search.thefryecompany.com/') >= 0){
                mergeData = fryeprice();
            }else if(url.indexOf('https://www.amazon.com/dp/') >= 0){
                mergeData = amazondp();
            }else if(url.indexOf('https://www.quiksilver.com/') >= 0){
                mergeData = quiksilver();
            }else if(url.indexOf('https://www.fitflop.com/') >= 0){
                mergeData = fitflop();
            }

            const els = document.createElement('textarea');
            els.value = mergeData;
            document.body.appendChild(els);
            els.select();
            document.execCommand('copy');
            document.body.removeChild(els)
            GM_notification( { title: "Info", text: "Copied Successfully!", timeout: 2000, image: "https://img.icons8.com/color/50/000000/paste.png" } );
        }
    }
})();

function fitflop(){
    let title = getInnerText("h1.pdp-form__title-product-title");
    let type = getInnerText("div.pdp-form__title > p");
    let color = getInnerText("span.pdp__color-swatches-name");
    let desc = getInnerText('div.product-summary');
    let bullets = getInnerHTML("div.product-description");
    let image = getIMG("div.image-zoomer > picture > img");
    return verifyData(title) + "\t" + verifyData(type) + "\t" + verifyData(color) + "\t" + verifyData(image) + "\t" + verifyData(desc) + "\t" + verifyData(bullets);
}


function tyr(){
    let images = document.querySelectorAll("ul.additional-images > li > a");
    let urls = [];
    for(let x in images){
        let img = images[x].href
        if(img!==null || img!==undefined || img!==""){
            urls.push(img);
        }
    }
    let title = getInnerText("div.product-name > h1");
    let desc = getInnerText('div[itemprop="description"]');
    return title + "\t" + urls.join("|") + "\t" + desc;
}

function quiksilver(){
    let title = getInnerText("h1.r-productname");
    let color = getInnerText("div.r-attrTitle.r-attrTitle-color");
    let images = [];
    $('div.slick--product-thumbnails.r-default-product-thumbnails > ul > li > div').each(function(){
    //$('div.slick-slide.slick-current.slick-active > ul > li > div').each(function(){
        let image = $(this).find("img").attr("relhires");
        images.push(verifyData(image));
    });
    let bullets = [];
    $('div.r-slide-action-block-content > ul > li').each(function(){
        let bullet = $(this).text();
        bullets.push(verifyData(bullet));
    });
    return title + "\t" + color + "\t" + images.join("|") + "\t" + bullets.join("|");
}

function amazondp(){
    let title = getInnerText("#productTitle");
    let image = getIMG("#imgTagWrapperId > img");
    let color = getInnerText("#variation_color_name > div > span");
    let bullets = [];
    $('#feature-bullets > ul > li > span').each(function(){
        bullets.push($(this).text().trim());
    });
    //let type = $("#wayfinding-breadcrumbs_feature_div > ul > li:last-child").text();
    let desc = getInnerText("#productDescription");
    return title + "\tn/a\t" + color + "\t" + image + "\t" + desc + "\t" + bullets.join("|").replace(/\n|\t|\r/g,'');
}

function fryeprice(){
    let title = getInnerText("a.product-item-link");
    let price = getInnerText('span.price.bfx-price');
    return title + '\t' + price;
}

function asicsimages(){
    $("#submitButton").click()
}

function palladium(){
    let title = getInnerText('h1.product_name');
    let color = getInnerText('p.product_color_title > strong');
    let desc = getInnerText('#tab1');
    let bullets = getInnerHTML('#tab2 > ul');
    return title + '\t' + color + '\t' + desc + '\t' + bullets;
}

function wrangler(){
    let gender = getInnerText('div.product-info-main > div.product.attribute.gender');
    let title = getInnerText('div.product-info-main > div > h1.page-title');
    let color = getInnerText('#product-options-wrapper > div > div > div.swatch-attribute.color_name > div > span.swatch-attribute-selected-option');
    let image = getUrl('div.owl-item.active > div > div > a')
    let desc = getInnerText('#product-detail > div:nth-child(2) > div > div.col-md-6 > p');
    let bullets = getInnerHTML('#product-detail > div:nth-child(2) > div > div:nth-child(2) > p');
    return color + '\t' + gender + '\t' + title + '\t' + image + '\t' + desc + '\t' + bullets;
}
function frye(){
    let gender = getInnerText('div.product-info-main > div.product.attribute.gender');
    let title = getInnerText('div.product-info-main > div > h1.page-title');
    let color = getInnerText('#product-options-wrapper > div > div > div.swatch-attribute.color_name > div > span.swatch-attribute-selected-option');
    let image = getUrl('div.owl-item.active > div > div > a')
    let desc = getInnerText('#product-detail > div:nth-child(2) > div > div.col-md-6 > p');
    let bullets = getInnerHTML('#product-detail > div:nth-child(2) > div > div:nth-child(2) > p');
    return color + '\t' + gender + '\t' + title + '\t' + image + '\t' + desc + '\t' + bullets;
}

function addproduct(){
    let title = getInnerText('#non-empty-search-results > div.a-box.product > div > div.a-fixed-left-grid.product > div > div.a-fixed-left-grid-col.a-col-right > div > div > div.a-fixed-right-grid-col.description.a-col-left > span.a-text-bold');
    let upc = getInnerText('#non-empty-search-results > div.a-box.product > div > div.a-fixed-left-grid.product > div > div.a-fixed-left-grid-col.a-col-right > div > div > div.a-fixed-right-grid-col.description.a-col-left > span:nth-child(2)');
    let asin = getUrl('#non-empty-search-results > div.a-box.product > div > div.a-fixed-left-grid.product > div > div.a-fixed-left-grid-col.a-col-right > div > div > div.a-fixed-right-grid-col.description.a-col-left > a');
    return upc + '\t' + asin.substr(asin.length-10) + '\t' + title;
}

function chaco(){
    let images = [];
    $('div.hires-thumbnails > ul > li').each(()=>{
        let image = $(this).find('img').attr('src');
        console.log(image);
    })
    //return images.join("|");
}

function olukai(){
    let title = getInnerText('h1.page-title > span');
    let title2 = getInnerText('div.category-name');
    let color = getInnerText('#product-options-wrapper > div > div > div.swatch-attribute.ol_color > div.swatch-attribute-label-container > span:nth-child(2)');
    let description = getInnerText('div.product.attribute.description > div.value > div.block.product.product-description > div > div.product.content-container > div:nth-child(1) > p');
    let image = getIMG('#magnifier-item-0');
    let features = document.querySelector('.product.content-container:not(:first-child)').innerHTML;
    return title + '\t' + title2 + '\t' + color + '\t' + image + '\t' + description + '\t' + verifyData(features);
}

function vans(){
    let title = getInnerText('#product-info > h1');
    let desc = getInnerText('#product-detail-1');
    return title + '\t' + desc;
}

function hanwag(){
    let title = getInnerText('#page-wrapper > div.product-detail-page > div.art-detail-page-top.article-detail-context > div:nth-child(2) > div > div > div.product-base-information > div:nth-child(1) > div.page-headline.txt-normal > h1');
    let color = getInnerText('#page-wrapper > div.product-detail-page > div.art-detail-page-top.article-detail-context > div:nth-child(2) > div > div > div.product-base-information > div:nth-child(2) > div.variations > div.js-product-option.product-option.clearfix.js-text-switch > div.head.clearfix > div.js-color-value.subheadline.info-text.js-value-wrap');
    let image = getIMG('#page-wrapper > div.product-detail-page > div.art-detail-page-top.article-detail-context > div:nth-child(2) > div > div > div.product-images > ul > li.item.active > img');
    let features = getInnerHTML('#page-wrapper > div.product-detail-page > div.art-detail-page-top.article-detail-context > div:nth-child(2) > div > div > div.product-description.default-text');
    return title + '\t' + color + '\t' + image + '\t' + features;
}

function kuhl(){
    let title = getInnerText('#pdpControls > div > div > div > div.pdp-details-controls-right > div.pdp-details-titlePrice.bottom > div > h1');
    let color = getInnerText('#display-color');
    let image = getIMG('#pdpImageList > div > div.pdp-imageList-listWrapper > div.pdp-imageList-container.pdp-imageList-container--images > div:nth-child(1) > img');
    let desc = getInnerHTML('#infobox-1');
    let feature1 = getInnerHTML('#infobox-2 > ul');
    let feature2 = getInnerHTML('#infobox-3 > ul');
    let feature3 = getInnerHTML('#infobox-4 > ul');
    let bullets = feature1 + feature2 + feature3;
    return title + '\t' + color + '\t' + image + '\t' + desc + '\t<ul>' + bullets.replace(new RegExp('n/a', 'g'),'') + '</ul>';
}

function oldwest(){
    let title = getInnerText('body > center > table:nth-child(7) > tbody > tr:nth-child(2) > td > table:nth-child(1) > tbody > tr:nth-child(1) > td:nth-child(5) > table > tbody > tr:nth-child(3) > td > table > tbody > tr > td > table > tbody > tr > td:nth-child(3) > a > font > b');
    let type = getInnerText('body > center > table:nth-child(7) > tbody > tr:nth-child(2) > td > table:nth-child(1) > tbody > tr:nth-child(1) > td:nth-child(5) > table > tbody > tr:nth-child(3) > td > table > tbody > tr > td > table > tbody > tr > td:nth-child(2) > a > font > b');
    let gender = getInnerText('body > center > table:nth-child(7) > tbody > tr:nth-child(2) > td > table:nth-child(1) > tbody > tr:nth-child(1) > td:nth-child(5) > table > tbody > tr:nth-child(3) > td > table > tbody > tr > td > table > tbody > tr > td:nth-child(1) > a > font > b');
    let image = getIMG('#image2');
    let bullets = getInnerHTML('body > center > table:nth-child(7) > tbody > tr:nth-child(2) > td > table:nth-child(1) > tbody > tr:nth-child(1) > td:nth-child(5) > table > tbody > tr:nth-child(9) > td > table > tbody > tr:nth-child(2) > td > font');
    return gender + '\t' + title + '\t' + type + '\t' + image.replace('productimage/','productimage/x_') + '\t' + bullets.replace(/~&nbsp;&nbsp;/g,'');
}

function mountainhardwear(){
    let title = getInnerText('h1.product-name.ml-1');
    let desc = getInnerText('div.product-summary');
    let bullets = getInnerHTML('div#itemDetails > ul');
    let material = getInnerHTML('#pdpMain > div.row.m-lg-0.clear.js-order-specs > div.col-lg-4.extra-rew.mt-2 > div.row.no-gutters.js-pdp-details > div > div > div > div > div:nth-child(2) > div.item-body > div > div > ul');

    return title + '\t' + material + '\t' + desc + '\t' + bullets;
}

function drewshoe(){
    let title = getInnerText('div#color_and_selection > div#selection_info');

    return title;
}

function outbacktrading(){
    let title = getInnerText('#ejs-main-section > div.row-fluid > div > div:nth-child(1) > div > div:nth-child(2) > div.span8 > div:nth-child(1) > h1');
    let desc = getInnerText('#ejs-main-section > div.row-fluid > div > div:nth-child(1) > div > div:nth-child(2) > div.span8 > div:nth-child(1) > p.product-description');
    let color = getInnerText('#Color > option:nth-child(1)');
    let bullets = getInnerHTML('div#tab-2');
    let image1 = getIMG('#product-detail-gallery-thumbs > div > ul > li:nth-child(1) > a > img');
    let image2 = getIMG('#product-detail-gallery-thumbs > div > ul > li:nth-child(2) > a > img');
    let image3 = getIMG('#product-detail-gallery-thumbs > div > ul > li:nth-child(3) > a > img');
    let image4 = getIMG('#product-detail-gallery-thumbs > div > ul > li:nth-child(4) > a > img');
    let image5 = getIMG('#product-detail-gallery-thumbs > div > ul > li:nth-child(5) > a > img');

    return title + '\t' + color + '\t' + image1 + '\t' + image2+ '\t' + image3 + '\t' + image4 + '\t' + image5 + '\t' + desc + '\t' + bullets.replace(/• /g,'');
}

function hurley(){
    let title = getInnerText('#RightRail > div > div:nth-child(1) > div > div.ncss-base.pr12-sm > h2');
    let title1 = getInnerText('#pdp_product_title');
    let image = getIMG('#pdp-6-up > button:nth-child(1) > div > picture:nth-child(3) > img');
    let image2 = getIMG('#pdp-6-up > button:nth-child(2) > div > picture:nth-child(3) > img');
    let color = getInnerText('li.description-preview__color-description.ncss-li');
    let style = getInnerText('li.description-preview__style-color.ncss-li');
    let desc = getInnerText('#RightRail > div > div.pt4-sm.prl6-sm.prl0-lg > div.description-preview > p');
    let bullets = getInnerHTML('div.pi-pdpmainbody');
    bullets = bullets.replace(/\r|\t|\n/g,'')
    return style + '\t' + title + '\t' + title1 + '\t' + color + '\t' + image + '\t' + image2 + '\t' + desc + '\t' + bullets;
}

function dockersApparel(){
    let title = getInnerText('div.product-details.page-title > h1');
    let color = getInnerText('div.variant-selector.product-swatches > div > div.variant-name > span.variant-selected.active-color');
    let image1 = getIMG('div:nth-child(1) > a > div > picture > img');
    let image2 = getIMG('div:nth-child(2) > a > div > picture > img');
    let image3 = getIMG('div:nth-child(3) > a > div > picture > img');
    let image4 = getIMG('div:nth-child(4) > a > div > picture > img');
    let desc = getInnerText('#pdpPageTabsRoot > div > div:nth-child(1) > div > div.contentContainer > div:nth-child(1)');
    let style = getInnerText('#pdpPageTabsRoot > div > div:nth-child(1) > div > div.contentContainer > div.style-product-code.hidden-md.hidden-lg');
    let bullets = getInnerHTML('#pdpPageTabsRoot > div > div:nth-child(2) > div:nth-child(1) > div.pdp-spec-feature-list.contentContainer > ul');
    return style + '\t' + title + '\t' + color + '\t' + image1 + '&fmt=jpg&fit=constrain,1&wid=2000&hei=2000\t' + image2 + '&fmt=jpg&fit=constrain,1&wid=2000&hei=2000\t'
        + image3 + '&fmt=jpg&fit=constrain,1&wid=2000&hei=2000\t' + image4 + '&fmt=jpg&fit=constrain,1&wid=2000&hei=2000\t' + desc + '\t' + bullets;
}


function getUrl(e){
    if($(e).length){
        return $(e).attr('href');
    }else{
        return "n/a";
    }
}

function getIMG(e){
    if($(e).length){
        return $(e).attr('src');
    }else{
        return "n/a";
    }
}

function getInnerText(e){
    if($(e).length){
        return $(e).text().replace(/\n|\t|\r/g,'').replace(/\s+/g,' ').trim();
    }else{
        return "n/a";
    }
}

function getInnerHTML(e){
    if($(e).length){
        return $(e).html().replace(/\n|\t|\r/g,'').replace(/\s+/g,' ').trim();
    }else{
        return "n/a";
    }
}
let verifyData = (data) =>{
	if(data!=undefined){
        return data.replace(/\n|\t|\r|…/g,'').replace(/\s+/g,' ').trim();
	}else{
        return "n/a";
	}
}