JSFiddle - React, Tailwind, and code Playground

by hbsto

JavaScript

"use strict";

(function(window){
    
    var proxyUrl = 'http://crossorigin.me/',
        siteUrl  = 'http://off.aladin.co.kr/usedstore/wsearchresult.aspx?SearchWord=$keyword&OffCode=$offcode&x=0&y=0',
        offcodeList = {
            gangnam: '강남',
            geondae: '건대',
            gwangju: '광주',
            nowon: '노원',
            daegu: '대구'
        },
        keyword = '%BB%E7%B0%C7',
        $ol = $('<ol/>').appendTo('BODY');
    
    var promises = [];
    
    for( var offcode in offcodeList ){
        promises.push( getSearchResult( offcode ) );
    }
    
    $.when.apply(this, promises).then(function(){
        $.each(arguments, parseResult);
    });
    
    function parseResult(idx, result){
        
        var $doc = $(result[0]),
            $searchList = $doc.find('#Search3_Result > .ss_book_box');
        
        $searchList.each(function(){
            
            var $this = $(this),
                $li = $('<li/>').appendTo( $ol ),
                $img = $this.find('A:first').attr('target', 'blank'),
                name = $this.find('LI:eq(1)').html(),
                writer = $this.find('LI:eq(2)').html();
            
            $li.append( $img, '<br/>', name, '<br/>', writer );
            
        });
        
        //console.dir( $doc );
        console.dir( $searchList );
        
    }
    
    function getSearchResult( offcode ){
        return $.get(
            proxyUrl + (siteUrl.replace('$keyword', keyword).replace('$offcode', offcode))
        );
    }
    
    
    //http://crossorigin.me/http://off.aladin.co.kr/usedstore/wsearchresult.aspx?SearchWord=%B9%D9%C0%CC%BA%ED&x=0&y=0
    
})(this);