Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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

Dismiss x
public
Bin info
SutnuiBorshikpro
0viewers