[Tutorial] emanon's Image Dowloander Java Script
Posted: Sun Aug 14, 2005 4:55 pm
This is a little different than an extension, but is very handy nonetheless...
Imagine yourself browsing a site that has a lots of images in the same directory and you notice the images have part of the url that is sequentially numbered. You say to yourself, "Geez, instead of loading these images one at a time, I wish I could get them all on one page." Now you can with this little javascript "bookmarklet". To use this all you have to do is:
1) right click on an empty spot onyour Personal Bookmarks Toolbar
2) Select New Bookmark
3) Give it a clever name like "num links new page"
4) copy and paste the code from the end of this post into the location field.
5) close and if necessary drag the newly created link to an area that is accessable.
6) Next time you are at a site with sequentially numbered pages, click on the bookmarklette and a new window opens with the URL at the top and text boxes to specify ranges for the numbered portions. Enter the appropriate values and the list automagically appears.
7) The original page must remain open for the javascript to work.
8) Once you have the links listed, you may use either DownThemAll mentioned above, or the Linky extension to "Show all Image Links in One tab" which will as you guessed, open all the images on one tab for your viewing convenience.
java script:->
CODEjavascript:(function(){ function selectColor(i) { return [%22#fdc%22, %22#cdf%22, %22#bfd%22, %22#dbf%22, %22#fbd%22] [i%5]; } var u=location.href, ul=u.length; var tparts=[%22%22], zparts=[], nz=0; function isDigit(c) { return (%220%22 <= c && c <= %229%22); } for (i=0; i<ul; ) { for (; i<ul && !isDigit(u.charAt(i)); ++i) tparts[nz] += u.charAt(i); if(i<ul) { zparts[nz]=%22%22; for (; i<ul && isDigit(u.charAt(i)); ++i) zparts[nz] += u.charAt(i); tparts[nz+1]=%22%22; ++nz; } } if(!nz) { alert(%22No numbers in URL.%22); return; } D=window.open().document; D.write(); D.close(); function a(n) { A(D.body,n); } function A(p,n) { p.appendChild(n); } function E(q) { return D.createElement(q); } function cT(t) { return D.createTextNode(t) } function cBR() { return E(%22br%22); } function cS(t,ci) { var s=E(%22span%22); s.style.background=selectColor(ci); s.style.fontWeight=%22bold%22; A(s, cT(t)); return s; } function cTB(v,oc) { var b=E(%22input%22); b.size=6; b.value=v; b.addEventListener(%22input%22, oc, false); return b; } function cCB(t,oc) { var L=E(%22label%22), b=E(%22input%22); b.type=%22checkbox%22; b.checked=true; b.onchange=oc; A(L,b); A(L,cT(t)); return L; } function cL(nz,tparts,zparts) { var L=E(%22a%22); var u=%22%22; for (var i=0; i<nz; ++i) { A(L,cT(tparts)); A(L,cS(zparts, i)); u += tparts+zparts; } A(L,cT(tparts[nz])); u += tparts[nz]; L.href=u; L.target=%22_blank%22; return L; } a(cT(%22Original URL: %22)); a(cBR()); a(cL(nz, tparts, zparts)); a(cBR()); a(cBR()); var fromBoxes=[], toBoxes=[], padChecks=[]; for (i=0; i<nz; ++i) { a(cT(%22Run %22)); a(cS(zparts, i)); a(cT(%22 from %22)); a(fromBoxes=cTB(zparts, listURLs)); a(cT(%22 to %22)); a(toBoxes=cTB(zparts, listURLs)); a(cT(%22 (%22)); a(j=cCB(%22 Pad with zeroes to maintain length%22, listURLs)); padChecks=j.childNodes[0]; a(cT(%22)%22)); a(cBR()); } a(cBR()); resultDiv=E(%22div%22); a(resultDiv); listURLs(); function listURLs() { while (resultDiv.childNodes.length) resultDiv.removeChild(resultDiv.childNodes[0]); var lows=[], highs=[]; for (i=0; i<nz; ++i) { lows[i]=parseInt(fromBoxes[i].value, 10); highs[i]=parseInt(toBoxes[i].value, 10); if(highs[i]-lows[i] > 999) { A(resultDiv, cT(%22Too many%22)); return; } } urls=[]; function cb(sta) { var newzparts=[]; for (var i=0; i<nz; ++i) { var z=%22%22+sta[i]; if(padChecks[i].checked) while (z.length < zparts[i].length) z=%220%22+z; newzparts[i]=z; } A(resultDiv, cL(nz, tparts, newzparts)); A(resultDiv, cBR()); } fors(nz, cb, lows, highs); } function fors (n, callback, lows, highs) { function fors_inner (states, v) { if(v >= n) callback(states); else for (states[v]=lows[v]; states[v] <= highs[v]; ++(states[v])) fors_inner(states, v+1); } fors_inner ([], 0); } })()
Imagine yourself browsing a site that has a lots of images in the same directory and you notice the images have part of the url that is sequentially numbered. You say to yourself, "Geez, instead of loading these images one at a time, I wish I could get them all on one page." Now you can with this little javascript "bookmarklet". To use this all you have to do is:
1) right click on an empty spot onyour Personal Bookmarks Toolbar
2) Select New Bookmark
3) Give it a clever name like "num links new page"
4) copy and paste the code from the end of this post into the location field.
5) close and if necessary drag the newly created link to an area that is accessable.
6) Next time you are at a site with sequentially numbered pages, click on the bookmarklette and a new window opens with the URL at the top and text boxes to specify ranges for the numbered portions. Enter the appropriate values and the list automagically appears.
7) The original page must remain open for the javascript to work.
8) Once you have the links listed, you may use either DownThemAll mentioned above, or the Linky extension to "Show all Image Links in One tab" which will as you guessed, open all the images on one tab for your viewing convenience.
java script:->
CODEjavascript:(function(){ function selectColor(i) { return [%22#fdc%22, %22#cdf%22, %22#bfd%22, %22#dbf%22, %22#fbd%22] [i%5]; } var u=location.href, ul=u.length; var tparts=[%22%22], zparts=[], nz=0; function isDigit(c) { return (%220%22 <= c && c <= %229%22); } for (i=0; i<ul; ) { for (; i<ul && !isDigit(u.charAt(i)); ++i) tparts[nz] += u.charAt(i); if(i<ul) { zparts[nz]=%22%22; for (; i<ul && isDigit(u.charAt(i)); ++i) zparts[nz] += u.charAt(i); tparts[nz+1]=%22%22; ++nz; } } if(!nz) { alert(%22No numbers in URL.%22); return; } D=window.open().document; D.write(); D.close(); function a(n) { A(D.body,n); } function A(p,n) { p.appendChild(n); } function E(q) { return D.createElement(q); } function cT(t) { return D.createTextNode(t) } function cBR() { return E(%22br%22); } function cS(t,ci) { var s=E(%22span%22); s.style.background=selectColor(ci); s.style.fontWeight=%22bold%22; A(s, cT(t)); return s; } function cTB(v,oc) { var b=E(%22input%22); b.size=6; b.value=v; b.addEventListener(%22input%22, oc, false); return b; } function cCB(t,oc) { var L=E(%22label%22), b=E(%22input%22); b.type=%22checkbox%22; b.checked=true; b.onchange=oc; A(L,b); A(L,cT(t)); return L; } function cL(nz,tparts,zparts) { var L=E(%22a%22); var u=%22%22; for (var i=0; i<nz; ++i) { A(L,cT(tparts)); A(L,cS(zparts, i)); u += tparts+zparts; } A(L,cT(tparts[nz])); u += tparts[nz]; L.href=u; L.target=%22_blank%22; return L; } a(cT(%22Original URL: %22)); a(cBR()); a(cL(nz, tparts, zparts)); a(cBR()); a(cBR()); var fromBoxes=[], toBoxes=[], padChecks=[]; for (i=0; i<nz; ++i) { a(cT(%22Run %22)); a(cS(zparts, i)); a(cT(%22 from %22)); a(fromBoxes=cTB(zparts, listURLs)); a(cT(%22 to %22)); a(toBoxes=cTB(zparts, listURLs)); a(cT(%22 (%22)); a(j=cCB(%22 Pad with zeroes to maintain length%22, listURLs)); padChecks=j.childNodes[0]; a(cT(%22)%22)); a(cBR()); } a(cBR()); resultDiv=E(%22div%22); a(resultDiv); listURLs(); function listURLs() { while (resultDiv.childNodes.length) resultDiv.removeChild(resultDiv.childNodes[0]); var lows=[], highs=[]; for (i=0; i<nz; ++i) { lows[i]=parseInt(fromBoxes[i].value, 10); highs[i]=parseInt(toBoxes[i].value, 10); if(highs[i]-lows[i] > 999) { A(resultDiv, cT(%22Too many%22)); return; } } urls=[]; function cb(sta) { var newzparts=[]; for (var i=0; i<nz; ++i) { var z=%22%22+sta[i]; if(padChecks[i].checked) while (z.length < zparts[i].length) z=%220%22+z; newzparts[i]=z; } A(resultDiv, cL(nz, tparts, newzparts)); A(resultDiv, cBR()); } fors(nz, cb, lows, highs); } function fors (n, callback, lows, highs) { function fors_inner (states, v) { if(v >= n) callback(states); else for (states[v]=lows[v]; states[v] <= highs[v]; ++(states[v])) fors_inner(states, v+1); } fors_inner ([], 0); } })()