<html>
<head>
<meta name="description" content="This script allows you to observe changes of a reddit post. It checks post content every 15 seconds. If change was detected you will be notified by 3 short beeps. Replace link in first code line with the comment link you want to track changes of">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
// This script allows you to observe changes of a reddit comment (only first level commnents to the post, not comment's replies).
// It checks commnet content every 15 seconds. If change was detected you will be notified by 3 short beeps.
// Replace link in first code line with the comment link you want to track changes of
var reddit_comment_link = 'https://www.reddit.com/r/Paladins/comments/7nss3e/hirez_expo_2018_live_thread/dsblsve/';
var json_api_link = reddit_comment_link.split('/').slice(0,7).join('/') + '.json?';
var comment_permalink = '/' + reddit_comment_link.split('/').slice(3).join('/');
var comment_body = '';
var audio = new Audio('http://gaschamber.hestfamily.com/tfc/sound/sc5x/mayday2.wav');
audio.volume = 0.5;
var last_update_time = null;
// if page doesn't have jQuery loaded we need to add it and wait until script will be loaded to call a callback function
function includejQuery(callback) {
if(window.jQuery){
callback();
} else {
var script = document.createElement('script');
script.onload = function() {
jQuery.noConflict();
callback();
};
script.src = "https://code.jquery.com/jquery-3.2.1.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
}
// returns time difference in between two timestamps in format '1h 2m 3s'
function get_time_difference (previous_time_stamp, current_timestamp){
result = '';
var diff_all_sec = Math.floor((current_timestamp - previous_time_stamp)/1000);
var diff_hours = Math.floor(diff_all_sec/60/60);
var diff_min = Math.floor((diff_all_sec - diff_hours*60*60)/60);
var diff_sec = Math.floor(diff_all_sec - diff_hours*60*60 - diff_min*60);
if ( diff_hours > 0){
result += diff_hours +'h ';
result += diff_min +'m ';
result += diff_sec +'s ';
} else if ( diff_min > 0) {
result += diff_min +'m ';
result += diff_sec +'s ';
} else if ( diff_sec > 0){
result += diff_sec +'s ';
}
return result;
}
function main(){
console.log('Receiving comment data...');
( function execute(){
jQuery.getJSON(json_api_link, function (data){
jQuery.each(data[1].data.children, function (i, item) {
if ( item.data.permalink == comment_permalink ) {
var current_time = Date.now();
if ( comment_body === '' ) { //on first run there no msg yet
last_update_time = Date.now();
comment_body = item.data.body;
//console.log ('Got initial comment');
console.log(comment_body);
} else {
if ( comment_body == item.data.body ) { // message was not changed
console.log('post was not changed for '+ get_time_difference(last_update_time, current_time)); // + new Date().toUTCString());
} else { // message changed
last_update_time = current_time;
audio.play();
setTimeout(function(){audio.play();}, 1500)
setTimeout(function(){audio.play();}, 3000)
console.log ('UPDATE!!');
comment_body = item.data.body;
console.log(comment_body);
}
}
}
});
});
setTimeout(execute, 15*1000);
})();
}
includejQuery(main);
//dmitriy.zhura@gmail.com
Output
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. |