<html>
<head>
<meta charset="utf-8">
<style>
body {
background-color: #222;
color: #FFF;
}
</style>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
var parseLinks = function(data) {
var div = data.match(/<div class="reddit-link .*?><\/div><\/div>/g);
var href, title, week, diff, lastLink, extra, lastWeek;
for(var i = 0, len = div.length; i < len; i++) {
href = div[i].match(/href="(.*?)"/)[1];
title = div[i].match(/href.*>(.*)<\/a><br /)[1]
extra = title.match(/^(?:\[Monthly |\[Weekly )/i);
try {
week = title.match(/Challenge\s*#\s*(\d{1,})/i)[1];
diff = title.match(/\[Easy]|\[Intermediate]|\[Hard]|\[Difficult]/i)[0];
}
catch(e){
if( extra == null ) {
console.log('warning: div unhandled\n',href,'\n',title,'\n',div[i]);
continue;
}
week = lastWeek;
diff = '[Bonus]';
}
lastWeek = week;
diff = diff[0] + diff[1].toUpperCase() + diff.slice(2).toLowerCase();
if( diff == '[Difficult]' ) diff = '[Hard]';
weeks[week] || (weeks[week] = {'[Easy]':[],'[Intermediate]':[],'[Hard]':[],'[Bonus]':[]});
weeks[week][diff].push(' [' + title + '](' + href + ') ');
extra = null;
};
lastLink = div[div.length-1].match(/id-(.*?) /)[1];
if( div.length < 25 || (div.length + links >= scrapeFor) ) genOutput();
else { links += div.length; scrape( 'after=' + lastLink + '&' ); }
};
var genOutput = function() {
var output = 'Easy | Intermediate | Hard | Weekly/Bonus<br />' +
'-----|--------------|------|-------------<br />' +
'| []() | []() | []() | **-** |<br />';
Object.keys(weeks).sort((a,b) => b-a).forEach(function(week) {
for(var diff in weeks[week]) {
if( weeks[week][diff].length == 0 ) weeks[week][diff].push('[]()');
}
['[Easy]','[Intermediate]','[Hard]','[Bonus]'].forEach(function(diff){
output += '|' + weeks[week][diff].join();
});
output += '|<br />';
});
document.getElementsByTagName('body')[0].insertAdjacentHTML('afterbegin', output);
};
var scrape = function(after='') {
var script = document.createElement('script');
script.src = 'https://www.reddit.com/r/dailyprogrammer/new.embed?' + after + 'callback=parseLinks';
document.getElementsByTagName('body')[0].appendChild(script);
script.parentNode.removeChild(script);
};
var weeks = {};
var links = 0;
var scrapeFor = 30;
scrape();
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |