Last active
August 29, 2015 14:05
-
-
Save Kreijstal/b725da4699c8ba13fd45 to your computer and use it in GitHub Desktop.
Some script to get filenames and images form threads on ponychans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDups(){ | |
var outstring=""; | |
for(var i=0;i<dups.length;i++){ | |
console.log(g[dups[i]].post) | |
outstring+=Object.keys(g[dups[i]].dups).concat(g[dups[i]].post).map(function(a){return ">>"+a}).join('\n')+'\n\n'; | |
} | |
return outstring | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function thempostsURL(leposts,n){ | |
var urls=[]; | |
for(var x in leposts){ | |
if(n){ | |
if(!leposts[x].otherSources[n]) | |
urls.push(leposts[x].href);} | |
else { | |
urls.push(leposts[x].href); | |
} | |
} | |
return urls; | |
} | |
g=[]; | |
for(var x,y,dups=[],d=document.getElementsByClassName('fileText'),i=0,n,l=d.length;i<l;i++){ | |
var filename=d[i].children[0]; | |
x=filename.title||filename.textContent | |
y=filename; | |
var postname=d[i].id.match(/[0-9]+/)[0],dup=true; | |
g.push({postNumber:postname,image:y.href,filename:x,source:"4chan"}) | |
} | |
var posts=themposts(g,pon["Backgrounds"]); | |
open("data:text/json,"+JSON.stringify(posts)); | |
open("data:text/plain,"+escape(thempostsURL(posts,"postimg").join('\n'))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function thempostsURL(leposts,n){ | |
var urls=[]; | |
for(var x in leposts){ | |
if(n){ | |
if(!leposts[x].otherSources[n]) | |
urls.push(leposts[x].href);} | |
else { | |
urls.push(leposts[x].otherSources["heinessen"][0]); | |
} | |
} | |
return urls; | |
} | |
p=document.getElementsByClassName('content')[0].children[0]; | |
f=p.children[0].childNodes[0].textContent; | |
f=f.substr(f.indexOf(',')+1) | |
g=[{postNumber:(p).id.match(/\d+/)[0], | |
image:p.getElementsByTagName('img')[0].parentNode.href, | |
filename:f.substr(f.indexOf(',')+1).trim(), | |
source:"heinessen"}]; | |
for(var x,y,dups=[],d=document.getElementsByClassName('thumb'),i=1,n,l=d.length;i<l;i++){ | |
var y=d[i].parentNode; | |
var D=y.parentNode; | |
var filename=D.querySelector('.reply>span').childNodes[0].textContent; | |
filename=filename.substr(filename.indexOf(',')+1) | |
x=filename.substr(filename.indexOf(',')+1).trim(); | |
var postname=D.id.match(/[0-9]+/)[0],dup=true; | |
g.push({postNumber:postname,image:y.href,filename:x,source:"heinessen"}) | |
} | |
var posts=themposts(g,pon["Specifics/cute"]); | |
open("data:text/json,"+JSON.stringify(posts)); | |
open("data:text/plain,"+escape(thempostsURL(posts).join('\n'))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g=[]; | |
for(var x,y,dups=[],d=document.getElementsByClassName('filesize'),i=0,n,l=d.length;i<l;i++){ | |
y=d[i].children[0]; | |
x=d[i].childNodes[2].textContent; | |
x=x.substr(x.indexOf(',')+1) | |
x=x.substr(x.indexOf(',')+1); | |
var postname=d[i].parentNode.children[3].name||d[i].parentNode.id.match(/[0-9]+/)[0],dup=true; | |
x=x.replace(/[^a-zA-Z]+$/,'').trim(); | |
g.push({postNumber:postname,image:y.href,filename:x,source:"ponychan"}) | |
} | |
open("data:text/json,"+JSON.stringify(themposts(g))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postImgGetURLs(callback){ | |
var ret=[],fg=document.getElementById('bbcode_link'),ar,weird | |
if(!fg){ | |
return [document.getElementById('code_2').value]} | |
$Rainb.HTTPRequestsRetry(weird=fg.value.split('\n').map(function(e){return e+"full"}),function(a){ret.push($Rainb.el("div",{"__properties":{innerHTML:a.responseText}}).querySelector("center>img").src)},function(){ | |
callback(ret); | |
})(); | |
return weird; | |
} | |
function pushIfNotThere(array,item){//I SHOULD HAVE WRITTEN THIS FUNCTION A LONG TIME AGO. | |
for(var i=0,l=array.length;i<l;i++){ | |
if(array[i]===item)return false; | |
} | |
return array.push(item); | |
} | |
function replaceImages(filenames,urls){ | |
var filename,nonreplaced=[]; | |
foobat:for(var x in filenames){ | |
filename=filenames[x].href.split('/').pop(); | |
for(var y=urls,url,i=0,l=y.length;i<l;i++){ | |
if(filenames[x]===y[i])continue foobat; | |
url=y[i].split('/'); | |
if(url[url.length-1]==filename){filenames[x].href=y.splice(i,1)[0]; | |
filenames[x].otherSources["postimg"]=filenames[x].otherSources["postimg"]||[]; | |
pushIfNotThere(filenames[x].otherSources["postimg"],filenames[x].href) | |
break;} | |
} | |
if(i==y.length&&!filenames[x].otherSources["postimg"]){ | |
nonreplaced.push(x); | |
} | |
} | |
return nonreplaced; | |
} | |
//"Backgrounds","Specifics/cute" | |
var spon=pon["Backgrounds"]; | |
weird=postImgGetURLs(mss); | |
function mss(imgurls){ | |
console.log(imgurls) | |
var missing=replaceImages(spon,imgurls); | |
var d=[]; | |
for(var i=0;i<missing.length;i++){ | |
d.push(spon[missing[i]].href); | |
} | |
console.log("MISSING",d.join('\n')); | |
open("data:text/json,"+JSON.stringify(pon)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rawURLS(urls,source){ | |
g=[]; | |
for(var x,y,dups=[],d=rawURLS,i=0,n,l=d.length;i<l;i++){ | |
var filename=d[i].children[0]; | |
x=filename.title||filename.textContent | |
y=filename; | |
var postname=d[i].id.match(/[0-9]+/)[0],dup=true; | |
g.push({postNumber:postname,image:y.href,filename:x,source:source}) | |
} | |
} | |
var posts=themposts(rawURLS(),pon["Backgrounds"]); | |
open("data:text/json,"+JSON.stringify(posts)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function themposts(posts,imageFilenames){ | |
var imageFilenames=imageFilenames||{}; | |
pony:for(var filename,dups=[],i=0,n,l=posts.length;i<l;i++){ | |
filename=posts[i].filename; | |
var postname=posts[i].postNumber,dup=true; | |
while(filename in imageFilenames){ | |
if(postname&&imageFilenames[filename].post===postname){ | |
imageFilenames[filename].otherSources=imageFilenames[filename].otherSources||{} | |
imageFilenames[filename].otherSources[posts[i].source]=imageFilenames[filename].otherSources[posts[i].source]||[]; | |
pushIfNotThere(imageFilenames[filename].otherSources[posts[i].source],posts[i].image); | |
imageFilenames[filename].href=posts[i].image; | |
continue pony;} | |
if(dup){ | |
if(!imageFilenames[filename].dups){dups.push(filename);imageFilenames[filename].dups={}} | |
imageFilenames[filename].dups[postname]=posts[i].image; | |
} | |
filename=filename.replace(/(?:\((\d+)\))?(\..+)?$/,function(a,b,c){return '('+((b|0)+1)+')'+(c?c:posts[i].image.match(/\.[^\.]+$/)[0])}) | |
dup=false | |
} | |
dup=true | |
imageFilenames[filename]=imageFilenames[filename]||{} | |
imageFilenames[filename].href=posts[i].image; | |
imageFilenames[filename].post=postname | |
imageFilenames[filename].otherSources=imageFilenames[filename].otherSources||{} | |
imageFilenames[filename].otherSources[posts[i].source]=[posts[i].image] | |
} | |
return imageFilenames; | |
} | |
function pushIfNotThere(array,item){//I SHOULD HAVE WRITTEN THIS FUNCTION A LONG TIME AGO. | |
for(var i=0,l=array.length;i<l;i++){ | |
if(array[i]===item)return false; | |
} | |
return array.push(item); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s='';for(x in g){ | |
s+="wget -nc "+g[x].href+" -O "+JSON.stringify(x)+'\n'; | |
} | |
var s='';for(x in g){ | |
s+="<img src=\""+g[x].href+"\">"+x; | |
} | |
open("data:text/html,"+s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment