Skip to main content
workaround for election countdowns and other future date/times
Source Link
rojo
  • 331
  • 1
  • 8
// ==UserScript==
// @name        SE realtime dates
// @namespace   http://stackapps.com/
// @description show Stack Exchange timestamps as realtime counters
// @include     /^https?:\/\/(\w+\.)?(stack(overflow|exchange|apps)|serverfault|superuser|askubuntu|onstartups|mathoverflow|mso)\.com\/.+/
// @version     1
// @grant       none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = (new Date() - new Date(this.el.title.replace(' ','T'))) / 1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) clearInterval(timers.pop());
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
// ==UserScript==
// @name         SE realtime dates
// @namespace    http://stackapps.com/
// @description  show Stack Exchange timestamps as realtime counters
// @match        *://stackexchange.com/*
// @match        *://*.stackexchange.com/*/*
// @match        *://stackoverflow.com/*/*
// @match        *://*.stackoverflow.com/*/*
// @match        *://stackapps.com/*/*
// @match        *://serverfault.com/*/*
// @match        *://superuser.com/*/*
// @match        *://askubuntu.com/*/*
// @match        *://mathoverflow.net/*/*
// @version      1.2.1
// @downloadURL  https://github.com/calraith/gm_scripts/raw/master/se_grace_timer.user.js
// @grant        none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = (new Date() - new Date(this.el.title.replace(' ','T'))) / 1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299 || x < 0) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) clearInterval(timers.pop());
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
// ==UserScript==
// @name        SE realtime dates
// @namespace   http://stackapps.com/
// @description show Stack Exchange timestamps as realtime counters
// @include     /^https?:\/\/(\w+\.)?(stack(overflow|exchange|apps)|serverfault|superuser|askubuntu|onstartups|mathoverflow|mso)\.com\/.+/
// @version     1
// @grant       none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = (new Date() - new Date(this.el.title.replace(' ','T'))) / 1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) clearInterval(timers.pop());
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
// ==UserScript==
// @name         SE realtime dates
// @namespace    http://stackapps.com/
// @description  show Stack Exchange timestamps as realtime counters
// @match        *://stackexchange.com/*
// @match        *://*.stackexchange.com/*/*
// @match        *://stackoverflow.com/*/*
// @match        *://*.stackoverflow.com/*/*
// @match        *://stackapps.com/*/*
// @match        *://serverfault.com/*/*
// @match        *://superuser.com/*/*
// @match        *://askubuntu.com/*/*
// @match        *://mathoverflow.net/*/*
// @version      1.2.1
// @downloadURL  https://github.com/calraith/gm_scripts/raw/master/se_grace_timer.user.js
// @grant        none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = (new Date() - new Date(this.el.title.replace(' ','T'))) / 1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299 || x < 0) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) clearInterval(timers.pop());
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
added GitHub link
Source Link
rojo
  • 331
  • 1
  • 8

Here's a Greasemonkey / Tampermonkey script that'll run a stop watch until an edit reaches 5 minutes of age. Give it a try and see what you think. It might have bugs, but it's close enough for government work I think. (That's a United States idiom meaning it's poorit has the mediocre quality one might expect from the lowest bidder, but it works well enough.) Bear in mind that it only works on new posts and post edits, not on comments.

Edit: I added the script to GitHub (direct install) so you can install it without having to copypaste this code block.

Here's a Greasemonkey / Tampermonkey script that'll run a stop watch until an edit reaches 5 minutes of age. Give it a try and see what you think. It might have bugs, but it's close enough for government work I think. (That's a United States idiom meaning it's poor quality, but it works well enough.) Bear in mind that it only works on new posts and post edits, not on comments.

Here's a Greasemonkey / Tampermonkey script that'll run a stop watch until an edit reaches 5 minutes of age. Give it a try and see what you think. It might have bugs, but it's close enough for government work I think. (That's a United States idiom meaning it has the mediocre quality one might expect from the lowest bidder, but it works well enough.) Bear in mind that it only works on new posts and post edits, not on comments.

Edit: I added the script to GitHub (direct install) so you can install it without having to copypaste this code block.

a little more efficient looping of timers
Source Link
rojo
  • 331
  • 1
  • 8
// ==UserScript==
// @name        SE realtime dates
// @namespace   http://stackapps.com/
// @description show Stack Exchange timestamps as realtime counters
// @include     /^https?:\/\/(\w+\.)?(stack(overflow|exchange|apps)|serverfault|superuser|askubuntu|onstartups|mathoverflow|mso)\.com\/.+/
// @version     1
// @grant       none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = Math.round((new Date() - new Date(this.el.title.replace(' ','T'))) / 1000);1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) {
        if (timers[0]) clearInterval(timers[0]);
        timers.splicepop(0,1);
    });
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
// ==UserScript==
// @name        SE realtime dates
// @namespace   http://stackapps.com/
// @description show Stack Exchange timestamps as realtime counters
// @include     /^https?:\/\/(\w+\.)?(stack(overflow|exchange|apps)|serverfault|superuser|askubuntu|onstartups|mathoverflow|mso)\.com\/.+/
// @version     1
// @grant       none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = Math.round((new Date() - new Date(this.el.title.replace(' ','T'))) / 1000);
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) {
        if (timers[0]) clearInterval(timers[0]);
        timers.splice(0,1);
    };
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
// ==UserScript==
// @name        SE realtime dates
// @namespace   http://stackapps.com/
// @description show Stack Exchange timestamps as realtime counters
// @include     /^https?:\/\/(\w+\.)?(stack(overflow|exchange|apps)|serverfault|superuser|askubuntu|onstartups|mathoverflow|mso)\.com\/.+/
// @version     1
// @grant       none
// ==/UserScript==

function setIntervalWithContext(code, delay, context) {
    return setInterval(function() {
        code.call(context);
    }, delay);
}

function startTimer(el) {
    if (!el.title) return;
    this.el = el;
    this.interval = setIntervalWithContext(function() {
        if (!this.el) return clearInterval(this.interval);
        var x = (new Date() - new Date(this.el.title.replace(' ','T'))) / 1000;
        if (x>299&&x<360) this.el.innerHTML = '5 mins ago';
        if (isNaN(x) || x > 299) return clearInterval(this.interval);
        var m = Math.floor(x / 60) % 60,
            s = Math.floor(x % 60),
            s = (s < 10) ? '0' + s : s;
        this.el.innerHTML = m+':'+s+' ago';
    }, 250, this);
    timers.push(this.interval);
}

function addTimers() {
    while (timers.length) clearInterval(timers.pop());
    var timestamps = document.getElementsByClassName('relativetime');
    for (var i=0; i<timestamps.length; i++) {
        var stopwatch = new startTimer(timestamps[i]);
    }
}

var timers = [];
addTimers();
addEventListener('click', function() { setTimeout(addTimers, 1000) }, true);
added better handling of "click to refresh"
Source Link
rojo
  • 331
  • 1
  • 8
Loading
Source Link
rojo
  • 331
  • 1
  • 8
Loading