Wikipedia Modified Warning

By Lenny Domnitser Last update Dec 5, 2006 — Installed 509 times. Daily Installs: 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
// ==UserScript==
// @name          Wikipedia Modified Warning
// @namespace     tag:domnit.org,2006-04:gmscripts
// @description   Shows a warning if an English Wikipedia page has been modified within the last X minutes (default is 5).
// @include       http://en.wikipedia.org/wiki/*
// ==/UserScript==

/*

Info
----

You can set a different threshold by using the "Change Wikipedia Modified Warning threshold" user script command.

IMPORTANT NOTE: You may have to change your Wikipedia date/time preferences. Set Date format to No preference and fill the time zone in from the browser.

(C) 2006 Lenny Domnitser
Use this freely under the GNU GPL, http://www.gnu.org/licenses/gpl.html

History
-------

2006-12-04 - Created

*/

const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

var threshold = GM_getValue('threshold', 5);

var viewed = new Date;

var messageBox;
function doIt() {
  if(messageBox) {
    messageBox.parentNode.removeChild(messageBox);
  }
  var m = document.getElementById('lastmod').textContent.match(/(\d+):(\d+), (\d+) (\w+) (\d+)/);
  var hour = m[1];
  var minute = m[2];
  var day = m[3];
  var month = MONTHS.indexOf(m[4]);
  var year = m[5];
  var modified = new Date(year, month, day, hour, minute);
  if(viewed - modified < threshold * 60000) {
    var insertBeforeMe = document.getElementById('jump-to-nav').nextSibling;
    messageBox = document.createElement('div');
    messageBox.setAttribute('style', 'background: #cfc;\
        border: 1px solid #9c9;\
        font-weight: bold;\
        margin: 0.5em auto;\
        max-width: 28em;\
        padding: 0.5em;');
    messageBox.appendChild(document.createTextNode('This page has been modified within the last ' + threshold + ' minutes.'));
    insertBeforeMe.parentNode.insertBefore(messageBox, insertBeforeMe);
  }
}

doIt();

GM_registerMenuCommand('Change Wikipedia Modified Warning threshold', function() {
  var value = prompt('Warn about Wikipedia pages modified within how many minutes of viewing?', threshold);
  if(value == null) {
    // cancelled
  } else {
    threshold = parseInt(value);
    if(value >= 1) {
      GM_setValue('threshold', threshold);
      doIt();
    } else {
      alert('Choose at least 1 minute.');
    }
  }
});