someone_

something

Aug 22nd, 2012
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/system/bin/sh
  2.  
  3. name=`basename $0`
  4.  
  5. usage () {
  6.     echo "$name - 4chan thread downloader"
  7.     echo ""
  8.     echo "Usage: $name [4chan thread URL] <time value and/or return target>"
  9.     echo ""
  10.     echo "  <time value>"
  11.     echo "     1: run script once"
  12.     echo "     Between 9 and 1000: Set the initial"
  13.     echo "      waiting time between runs"
  14.     echo "     Default: 10 seconds"
  15.     echo ""
  16.     echo "  <return target>"
  17.     echo "     Set the target path of the 'Return'"
  18.     echo "      link"
  19.     echo "     Default: ./"
  20.     exit 0
  21. }
  22.  
  23. [ $# -eq 0 ] && usage
  24.  
  25. for arg in $@; do
  26.     urltest=$(echo "$arg" | sed -e "s_^https_http_" | egrep -o "^http://boards.4chan.org/[a-z0-9]+/res/[0-9]+")
  27.     timetest=$(echo "$arg" |egrep "^[0-9]{1,3}$")
  28.     if [ $urltest ]; then
  29.         URL="$urltest"
  30.     elif [ $timetest ]; then
  31.         SLP="$arg"
  32.     else
  33.         RET="$arg"
  34.     fi
  35. done
  36.  
  37. [ ! $URL ] && usage
  38.  
  39. echo "4chan downloader"
  40.  
  41. LOC=$(echo "$URL" | sed 's_.*/\([^/]\+\)/res/\(.\+\)_\1\_\2_')
  42.  
  43. if [ ! $LOC ]; then
  44.     echo "Can't determine the thread's number"
  45.     echo "Use valid URL without hash or search tags"
  46.     echo ""
  47.     usage
  48. fi
  49.  
  50. ST="static.4chan.org"
  51.  
  52. [ ! $SLP ] && SLP="10"
  53. [ ! $RET ] && RET="./"
  54.  
  55. if [ -s /system/build.prop ]; then
  56.     for path in $(echo "$PATH" | sed "s_:_\n_g"); do
  57.         if [ -s ${path}/busybox ]; then
  58.             alias echo="${path}/busybox echo -ne"
  59.             alias read="${path}/busybox sh read -n 1 Q"
  60.             alias sed="${path}/busybox sed"
  61.             break
  62.         fi
  63.     done
  64. else
  65.     alias echo="echo -ne"
  66. fi
  67.  
  68. SLAP=$SLP
  69.  
  70. NO=$(echo "$LOC" | grep -o '[0-9]\+$')
  71. N="\n"
  72. R="\r"
  73. LM=""
  74.  
  75. thejob () {
  76.     if [ ! -d $LOC ]; then
  77.         mkdir $LOC
  78.     fi
  79.  
  80.     if [ ! -d $LOC/misc ]; then
  81.         mkdir $LOC/misc
  82.     fi
  83.  
  84.     egrep "//.\.thumbs\.4chan\.org/[a-z0-9]+/thumb/[0-9]*s\.jpg" $LOC.html -o | sed 's_^//_http://_g' > $LOC/misc/misc
  85.  
  86.     egrep "//${ST}/image/(spoiler[^\x2E]*\.png|filedeleted-res\.gif|favicon[^\x2E]*\.ico|[a-z]*icon\.gif)" $LOC.html -o | sed 's_^//_http://_g' >> $LOC/misc/misc
  87.  
  88.     egrep "//${ST}/image/country/[a-z]*/?[\w]+\...." $LOC.html -o | sed 's_^//_http://_g' >> $LOC/misc/misc
  89.  
  90.     egrep "//${ST}/css/[a-z]+\.[0-9]+\.css" $LOC.html -o | sed -e 's_^//_http:&_' | head -n1 > $LOC/misc/css
  91.  
  92.     egrep "//${ST}/css/[a-z]+\.[0-9]+\.css" $LOC.html -o | sed -e 's_^//_http:&_' | egrep 'tomorrow|prettify' >> $LOC/misc/css
  93.  
  94.     egrep "//${ST}/image/title/[a-z]+/[0-9a-z]+\.(jpg|png|gif)" $LOC.html -o | sed 's_^//_http://_g' > $LOC/misc/logo
  95.  
  96.     egrep "//images\.4chan\.org/[a-z0-9]+/src/[0-9]*\.(jpg|png|gif)" $LOC.html -o | sed 's_^//_http://_g' > $LOC/images
  97.  
  98.     egrep "^(<!DOCTYPE|<link rel|</head>)" $LOC.html > a
  99.  
  100.     head -n2 a > $LOC.html
  101.  
  102.     cat << EOF >> $LOC.html
  103. <!<script>var d=document,dE=d.documentElement,lS=localStorage,z,i,u="threaddl_arch_theme",e;Element.prototype.gA=function(a){return this.getAttribute(a);};Element.prototype.pN=function(){return this.parentNode;};String.prototype.iO=function(a){return this.indexOf(a);};function s(a,b,c){a.setAttribute(b,c);}function sT(b){lS.setItem(u,b);for(i=0;(z=d.getElementsByTagName("link")[i]);i++){if(z.gA("rel").iO("style")!=1&&z.gA("title")){z.disabled=true;if(z.gA("title")==(b?"switch":"Tomorrow"))z.disabled=false;}}}sT(parseInt(lS.getItem(u))||0);(function(){var a,b,c,e,f,g,h,i,j,k,l=parseInt(lS.qp_opt),m,n=parseInt(lS.img_hover),o;k={hover:function(a){var b,c,d,e,f,g,h;d=a.clientX,e=a.clientY;g=k.el.style;b=dE.clientHeight,c=dE.clientWidth;f=k.el.offsetHeight;h=e-120;g.top=b<=f||h<=0?"0px":h+f>=b?b-f+"px":h+"px";if(d<=c-400){g.left=d+45+"px";return g.right=null}else{g.left=null;return g.right=c-d+45+"px"}},hoverend:function(){a.rm(k.el);return delete k.el}};a=function(a,b){if(b==null){b=d.body}return b.querySelector(a)};a.extend=function(a,b){var c;for(c in b){a[c]=b[c]}};a.extend(a,{id:function(a){return d.getElementById(a)},addStyle:function(b){var c;c=a.el("style",{textContent:b});a.add(d.head,c);return c},x:function(a,b){b===null&&(b=d.body);return d.evaluate(a,b,null,8,null).singleNodeValue},addClass:function(a,b){return a.classList.add(b)},rmClass:function(a,b){return a.classList.remove(b)},rm:function(a){return a.pN().removeChild(a)},tn:function(a){return d.createTextNode(a)},nodes:function(a){var b,c,e=0;if(!(a instanceof Array)){return a}b=d.createDocumentFragment();for(;e<a.length;e++){c=a[e];b.appendChild(c)}return b},add:function(b,c){return b.appendChild(a.nodes(c))},after:function(b,c){return b.pN().insertBefore(a.nodes(c),b.nextSibling)},el:function(b,c){var e=d.createElement(b);if(c){a.extend(e,c)}return e},on:function(a,b,c){var d,e=0,f=b.split(" ");for(;e<f.length;e++){d=f[e];a.addEventListener(d,c,false)}},off:function(a,b,c){var d,e=0,f=b.split(" ");for(;e<f.length;e++){d=f[e];a.removeEventListener(d,c,false)}}});b=function(a,b){if(b==null){b=d.body}return [].slice.call(b.querySelectorAll(a))};c={post:function(b,d){var e=a.id("pc"+b);e&&a.add(d,c.cleanPost(e.cloneNode(true)))},cleanPost:function(c){var d,e,f,g,h,i=Date.now(),j=a(".post",c),k=_j=_k=_l=0,l=[].slice.call(c.childNodes),m=b(".inline",j),n=b(".inlined",j);for(;k<l.length;k++){if((d=l[k])!==j){a.rm(d)}}for(;_j<m.length;_j++){a.rm(m[_j])}for(;_k<n.length;_k++){a.rmClass(n[_k],"inlined")}(f=b("[id]",c)).push(c);for(;_l<f.length;_l++){(e=f[_l]).id=""+i+"_"+e.id}a.rmClass(c,"forwarded");a.rmClass(c,"qphl");a.rmClass(j,"highlight");a.rmClass(j,"qphl");return c}};j={init:function(){return e.callbacks.push(this.node)},node:function(b){var c=a(".postInfo > .dateTime",b.el);if(b.isInlined){return}j.date=new Date(c.dataset.utc*1e3);c.title="4chan time: "+c.textContent;return c.textContent=j.zeroPad(j.date.getMonth()+1)+"/"+j.zeroPad(j.date.getDate())+"/"+(j.date.getFullYear()-2e3)+"("+j.day[j.date.getDay()]+")"+j.zeroPad(j.date.getHours())+":"+j.zeroPad(j.date.getMinutes())},day:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],zeroPad:function(a){if(10>a){return"0"+a}else{return a}}};g={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d,e,f,g,j,k={},n=0,m=b.quotes;if(b.isInlined){return}for(;m.length>n;n++){j=m[n];if(g=j.hash.slice(2)){k[g]=true}}c=a.el("a",{href:"#p"+b.ID,className:"backlink",textContent:">>"+b.ID});for(g in k){if(!(e=a.id("pi"+g))||/\bop\b/.test(e.pN().className)){continue}f=c.cloneNode(true);l&&a.on(f,"mouseover",i.mouseover);a.on(f,"click",h.toggle);if(!(d=a.id("blc"+g))){d=a.el("span",{className:"container",id:"blc"+g});a.add(e,d)}a.add(d,[a.tn(" "),f])}}};h={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d=_j=0,e=b.quotes,f=b.backlinks;for(;e.length>d;d++){c=e[d];if(!c.hash){continue}c.removeAttribute("onclick");a.on(c,"click",h.toggle)}for(;f.length>_j;_j++){a.on(f[_j],"click",h.toggle)}},toggle:function(b){if(b.shiftKey||b.altKey||b.ctrlKey||b.metaKey||b.button!==0){return}b.preventDefault();var c=this.dataset.id||this.hash.slice(2);if(/\binlined\b/.test(this.className)){h.rm(this,c)}else{if(a.x("ancestor::div[contains(@id,'p"+c+"')]",this)){return}h.add(this,c)}return this.classList.toggle("inlined")},add:function(b,d){var e=d,f=a.id("p"+e),g=a.el("div",{id:"i"+e,className:"inline"}),h=/\bbacklink\b/.test(b.className),i=h?b.pN():a.x("ancestor-or-self::*[parent::blockquote][1]",b);a.after(i,g);c.post(e,g);if(!f){return}if(h){a.addClass(f.pN(),"forwarded");++f.dataset.forwarded||(f.dataset.forwarded=1)}},rm:function(c,d){var e,f,g,h,i;e=a.x("following::div[@id='i"+d+"']",c);a.rm(e);i=b(".backlink.inlined",e);for(g=0,h=i.length;h>g;g++){f=i[g];e=a.id(f.hash.slice(1));if(!--e.dataset.forwarded){a.rmClass(e.pN(),"forwarded")}}if(/\bbacklink\b/.test(c.className)){e=a.id("p"+d);if(!--e.dataset.forwarded){return a.rmClass(e.pN(),"forwarded")}}}};i={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d=_j=0,e=b.quotes,f=b.backlinks;for(;e.length>d;d++){c=e[d];if(c.hash||/\bdeadlink\b/.test(c.className)){a.on(c,"mouseover",i.mouseover)}}for(;f.length>_j;_j++){a.on(f[_j],"mouseover",i.mouseover)}},mouseover:function(e){var f,g=this.hash.slice(2),h,j,l,m=0,n;if(/\binlined\b/.test(this.className)){return}if(h=a.id("qp")){if(h===k.el){delete k.el}a.rm(h)}if(k.el){return}h=k.el=a.el("div",{id:"qp",className:"reply dialog"});k.hover(e);a.add(d.body,h);f=a.id("p"+g);c.post(g,h);a.on(this,"mousemove",k.hover);a.on(this,"mouseout click",i.mouseout);if(!f){return}if(/\bop\b/.test(f.className)){a.addClass(f.pN(),"qphl")}else{a.addClass(f,"qphl")}l=a.x("ancestor::*[@id][1]",this).id.match(/\d+$/)[0];n=b(".quotelink, .backlink",h);for(;n.length>m;m++){j=n[m];if(j.hash.slice(2)===l){a.addClass(j,"forwardlink")}}},mouseout:function(b){var c;k.hoverend();if(c=a.id(this.hash.slice(1))){a.rmClass(c,"qphl");a.rmClass(c.pN(),"qphl")}a.off(this,"mousemove",k.hover);return a.off(this,"mouseout click",i.mouseout)}};m={init:function(){return e.callbacks.push(this.node)},node:function(b){if(!b.img){return}return a.on(b.img,"mouseover",m.mouseover)},mouseover:function(){var b;if(b=a.id("ihover")){if(b===k.el){delete k.el}a.rm(b)}if(k.el){return}b=k.el=a.el("img",{id:"ihover",src:this.pN().href});a.add(d.body,b);a.on(b,"load",m.load);a.on(this,"mousemove",k.hover);return a.on(this,"mouseout",m.mouseout)},load:function(){var a;if(!this.pN()){return}a=this.style;return k.hover({clientX:-45+parseInt(a.left),clientY:120+parseInt(a.top)})},mouseout:function(){k.hoverend();a.off(this,"mousemove",k.hover);return a.off(this,"mouseout",m.mouseout)}};o={init:function(){return e.callbacks.push(this.node)},node:function(b){if(!b.img){return}return a.on(b.img.pN(),'click',o.cb.toggle)},cb:{toggle:function(e){if(e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.button!==0){return}e.preventDefault();return o.toggle(this)}},toggle:function(b){var c,e=b.firstChild;if(e.hidden){c=b.getBoundingClientRect();if(d.body.gA("class")!=='i'){if(c.top<0){d.body.scrollTop+=c.top-42}if(c.left<0){d.body.scrollLeft+=c.left}}else{if(c.top<0){dE.scrollTop+=c.top-42}if(c.left<0){dE.scrollLeft+=c.left}}return o.contract(e)}else{return o.expand(e)}},contract:function(b){b.hidden=false;return b.nextSibling.hidden=true},expand:function(b){var c,d;if(a.x('ancestor-or-self::*[@hidden]',b)){return}b.hidden=true;if(d=b.nextSibling){d.hidden=false;return}c=b.pN();d=a.el('img',{src:c.href,alt:b.alt});return a.add(c,d)}};e={init:function(){(function(){var c=b('a.fileThumb'),i=0;/WebKit/.test(navigator.userAgent)||s(d.body,'class','i');for(;c.length>i;i++){var n=a.nodes([a.tn(' '),a.el('a',{textContent:'google',href:'http://www.google.com/searchbyimage?image_url='+c[i].href,target:'_blank'})]);-1!==location.protocol.iO('http')&&c[i].previousElementSibling.appendChild(n)}for(c=b('span.abbr a'),i=0;c.length>i;i++){s(c[i],'onclick','javascript:e=this.pN().pN().lastChild.style;e.display=e.display=="block"?"none":"block"')}}());a.add(a("div.navLinks"),[a.tn(" ["),a.el("a",{href:"javascript:;",textContent:"QuotePreview is "+(l?"ON":"OFF"),onclick:function(){lS.qp_opt=l?0:1;window.location.reload()}}),a.tn("] ["),a.el("a",{href:"javascript:;",textContent:"ImageHover is "+(n?"ON":"OFF"),onclick:function(){lS.img_hover=n?0:1;window.location.reload()}}),a.tn("]")]);j.init();h.init();l&&i.init();n&&m.init();o.init();g.init();e.ready()},ready:function(){var c=[],d=0,f=b(".postContainer",a.id("delform"));for(;f.length>d;d++){c.push(e.preParse(f[d]))}e.node(c);if(MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.OMutationObserver){observer=new MutationObserver(e.observer);observer.observe(a(".board"),{childList:true,subtree:true})}else{a.on(a(".board"),"DOMNodeInserted",e.listener)}},preParse:function(c){var d=a(".post",c),e=c.pN().className,f={root:c,el:d,"class":d.className,ID:d.id.match(/\d+$/)[0],threadID:a.x("ancestor::div[parent::div[@class='board']]",c).id.match(/\d+$/)[0],isInlined:/\binline\b/.test(e),blockquote:d.lastElementChild,quotes:b("a.quotelink[href^='#p']",d),backlinks:d.getElementsByClassName("backlink"),img:false},g;if(g=a('img[data-md5]',d)){f.img=g}return f},node:function(a){for(var b=0,c=e.callbacks;c.length>b;b++){var d=c[b];try{for(var f=0;a.length>f;f++){d(a[f])}}catch(g){alert("Error: "+g.message+"\nReport the bug to HandyAnon@Steam\n\nURL: "+window.location+"\n"+g.stack)}}},observer:function(a){var b,c,d,f,g,h,i,j;d=[];for(f=0,h=a.length;h>f;f++){c=a[f];j=c.addedNodes;for(g=0,i=j.length;i>g;g++){b=j[g];if(/\bpostContainer\b/.test(b.className)){d.push(e.preParse(b))}}}if(d.length){return e.node(d)}},listener:function(a){var b;b=a.target;if(/\bpostContainer\b/.test(b.className)){return e.node([e.preParse(b)])}},callbacks:[]};a.on(d,"DOMContentLoaded",e.init)}).call(this);function imgexp(b){var a=b.firstElementChild,c,db=d.body;if(null===b.gA("exp")){s(a,"i-old",a.src);a.gA("style")&&(s(a,"i-olds",a.gA("style")),a.removeAttribute("style"));a.removeAttribute("src");a.src=b.href;s(b,"exp","");}else{a.gA("i-olds")&&(s(a,"style",a.gA("i-olds")),a.removeAttribute("i-olds"));a.src=a.gA("i-old");a.removeAttribute("i-old");b.removeAttribute("exp");c=b.getBoundingClientRect().top;if("i"===db.class){0>c&&(db.scrollTop+=c-42);}else{0>c&&(dE.scrollTop+=c-42);};}}//Hungary is best country</script><style>img[data-md5]+img{max-width:100%!important;}.i img[data-md5]+img{width:100%!important;}.op:after{clear:both;content:'';display:block;}#qp{padding:2px 2px 5px;position:fixed;border:1px solid rgba(128,128,128,0.5);}#qp .post{border:none;margin:0;padding:0;}#qp img{max-height:300px;max-width:500px;}.qphl{outline:2px solid rgba(216,94,49,.7);}.inlined{opacity:.5;}.inline{border:1px solid rgba(128,128,128,0.5);display:table;margin:2px;padding:2px;}.inline .post{background:none;border:none;margin:0;padding:0;}.forwarded{display:none;}.quotelink.forwardlink,.backlink.forwardlink{text-decoration:none;border-bottom:1px dashed;}#ihover{max-height:97%;max-width:75%;padding-bottom:18px;position:fixed;}</style>
  104. EOF
  105.  
  106.     tail -n1 a >> $LOC.html
  107.  
  108.     rm a
  109.  
  110.     sed -i -e '1 s/<script.*$/!>/' -e '2 {s_<script_!>\n&_
  111.         s_<link [^>]*RSS feed[^>]*>__
  112.         s@//'$ST'/image/\(favicon[^\x2E]*\.ico\)@'$LOC'/misc/\1@
  113.         s_<link rel="alternate style[^-]*\(<link[^>]*tomorrow\.[^>]*>\)[^-]*<_\1<_
  114.         s@//'$ST'/css/\([a-z0-9\.]\{1,75\}\.css\)@'$LOC'/misc/\1@g
  115.         s/^/<!/}' -e '$ {s_</head>_<!&_
  116.         s_<div id="boardNavDesktop" class="desktop">_\n_
  117.         s_<div class="boardBanner"_\n<!&_
  118.         s_<hr class="above_\n_
  119.         s_\(<div class="navLinks desktop">.<a href="\.\./\./[^#]*\)#bottom\(">Bottom</a>.\)_\n<!\n<!\1javascript:dE.scrollIntoView(false)\2</div><hr>\n_
  120.         s_\(<form name="delform" id="delform"\)[^>]*_\n<!\1_
  121.         s@//.\.thumbs\.4chan\.org/[^/]*/thumb/\([0-9]*s\.jpg\)@'$LOC'/misc/\1@g
  122.         s@//images\.4chan\.org/[^/]*/src/\([0-9]*\....\)@'$LOC'/\1@g
  123.         s@//'$ST'/image/title/[^/]*/[a-z0-9-]*\.\(...\)@'$LOC'/misc/logo.\1@g
  124.         s@//'$ST'/image/\(spoiler[^\x2E]*\....\)@'$LOC'/misc/\1@g
  125.         s@//'$ST'/image/\(filedeleted-res\.gif\)@'$LOC'/misc/\1@g
  126.         s@//'$ST'/image/country/\([^/]*/\?[^\x2E]*\....\)@'$LOC'/misc/\1@g
  127.         s@//'$ST'/image/\([a-z]*icon.gif\)@'$LOC'/misc/\1@g
  128.         s_\(<a href="\)'$NO'#p_\1#p_g
  129.         s_<a href="#p'$NO'"[^>]*>&gt;&gt;'$NO'_& (OP)_g
  130.         s_\(<a href="[0-9]\+\)\(#p[^>]*>[^<]*\)_\1.html\2 (Cross-thread)_g
  131.         s_\(</div></div></div><hr>\)<div class="mobile"_\1\n_
  132.         s_\(<div class="navLinks navLinksBot desktop">.<a href="\.\./\./"[^>]*>Return</a>. .<a href="\)#top\(">Top</a>.\)_\n<!</form><span style="float:right;">Style: [ <a href="javascript:sT(1);dE.scrollIntoView(false)">Default</a> | <a href="javascript:sT(0);dE.scrollIntoView(false)">Tomorrow</a> ]</span>\1javascript:dE.scrollIntoView()\2\n_
  133.         s@</body>@\n<!</div>&@}' -e '{s:\(<a href="\)\.\./\./\([^>]*>Return</a>\):\1'"$RET"'\2:g
  134.         s_\(<a[^>]*href="\)//_\1http://_g
  135.         s_\(<a[^>]*\) onclick="replyhl[^"]*"_\1_g
  136.         s_\(<a href="javascript:\)quote[^>]*_\1;"_g
  137.         s_<div class="postInfoM_\n_g
  138.         s_<div class="file"_\n<!&_g
  139.         s_<div class="postInfo desktop"_\n<!&_g
  140.         s_<a href="/ic\?/anim\.php?file=[0-9]*" target="\_blank">_<a title="View is supported only on 4chan">_g
  141.         s_\(<input type="checkbox"\)[^>]*_\1_g
  142.         s_<a onclick="toggle..exif[^"]*"_<a_g}' $LOC.html
  143.  
  144.     grep '^<!' $LOC.html > a
  145.  
  146.     sed -i -e '2,$ s_^<!__' a
  147.  
  148.     tr -d '\n' < a > $LOC.html
  149.  
  150.     sed -i -e 's_!>_\n_g' $LOC.html
  151.  
  152.     rm a
  153.  
  154.     # :a;N;$!ba;
  155.  
  156.     cd $LOC
  157.  
  158.     if [ -s a ]; then
  159.         rm $(basename `cat a`) a
  160.     fi
  161.  
  162.     for image in $(cat images); do
  163.         echo $image > a
  164.         wget -q -nc $image
  165.         > a
  166.     done
  167.  
  168.     rm images a
  169.  
  170.     cd misc
  171.  
  172.     if [ -s a ]; then
  173.         rm $(basename `cat a`) a
  174.     fi
  175.  
  176.     for misc in $(cat misc); do
  177.         echo $misc > a
  178.         wget -q -nc $misc
  179.         > a
  180.     done
  181.  
  182.     CSS=$(basename `head -n1 css`)
  183.  
  184.     if [ "$CSSt" != "$CSS" ]; then
  185.         CSSt=CSS
  186.         if [ "$(ls|grep '.css')" ]; then
  187.             rm *.css
  188.         fi
  189.         wget -q -nc -i css
  190.         wget -q -nc "$(grep -o 'fade-\?[a-z0-9]*\.png' $CSS | sed -e 's_.*_http://'$ST'/image/&_')"
  191.         sed -i -e 's_/image/\(fade[^\x2E]*\.png\)_\1_g' $CSS
  192.     fi
  193.  
  194.     if [ "$(ls|grep logo.)" ]; then
  195.         rm "$(ls|grep logo.)"
  196.     fi
  197.  
  198.     wget -q -i logo -O "logo.$(sed 's_\._\n_g' logo|tail -n1)"
  199.  
  200.     rm misc logo css a
  201.  
  202.     touch .nomedia
  203.  
  204.     cd ../..
  205. }
  206.  
  207. exito () {
  208.     echo "Session completed. Exiting     $N"
  209.     exit 0
  210. }
  211.  
  212. echo "${N}Downloading to $LOC$N${N}------------------------------$N"
  213.  
  214. while true; do
  215.     trap exito 1 2 3 15
  216.  
  217.     stat="$(wget -S --spider "$URL" 2>&1)"
  218.  
  219.     if [ "$(echo "$stat" |grep '404 Not Found')" ]; then
  220.         if [ -s $LOC.html ]; then
  221.             echo "Thread has 404'd or 4chan is down. Stopping script${N}"
  222.         else
  223.             echo "Thread does not exist. Stopping script${N}"
  224.         fi
  225.         exit 0
  226.     fi
  227.  
  228.     if [ "$LM" != "$(echo "$stat" |grep Last-Modified)" ]; then
  229.         LM="$(echo "$stat" |grep Last-Modified)"
  230.         SLAP=$SLP
  231.         wget -np -nd -nH -q -erobots=off $URL -O $LOC.html
  232.         thejob
  233.     else
  234.         SLAP=`expr "$SLAP" + "5"`
  235.     fi
  236.  
  237.     trap - 1 2 3 15
  238.  
  239.     if [ $SLP = "1" ]; then
  240.         exito
  241.     fi
  242.  
  243.     echo OK
  244.  
  245.     sleep $SLAP
  246.  
  247.     echo "\b\b  \b\b"
  248. done
RAW Paste Data