The Alligator Comments Fixer

By Jordon Kalilich Last update Feb 26, 2008 — Installed 69 times.
// The Alligator Comments Fixer, a Greasemonkey user script
// Version 0.4 - February 26, 2008
// Copyright 2007, 2008 Jordon Kalilich (http://www.theworldofstuff.com/)
// Released under the GPL version 3
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name          The Alligator Comments Fixer
// @namespace     http://www.theworldofstuff.com/greasemonkey/
// @description   Makes article comments on alligator.org more readable.
// @include       http://www.alligator.org/*
// @include       http://alligator.org/*
// ==/UserScript==

// clean up comments
var comments = document.evaluate("//div[@class='simpleblog-response']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
if (comments) {
   for (i = 0; i < comments.snapshotLength; i++) {
      comments.snapshotItem(i).innerHTML = comments.snapshotItem(i).innerHTML.replace(/(^"\s+|\s+"$)/g,'');
   }
   GM_addStyle('.simpleblog-results p, .simpleblog-name, .simpleblog-date, .simpleblog-response {font-size: 13px ! important; line-height: 20px ! important}');
}
// move register/login form after comments
var forms = document.getElementsByTagName('form');
for (i = 0; i < forms.length; i++) {
   if (forms[i].action == window.location.href) { // if the login form exists
      var commentContainer = document.evaluate("//div[@class='simpleblog-results']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
      if (commentContainer) {
         // move registration form, if it exists, after the comment container
         var regForm = document.evaluate("//div[@class='simpleblog']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
         if (regForm) {
            commentContainer.parentNode.insertBefore(regForm, commentContainer.nextSibling);
         }
         // a note before the reg. form telling users they need to reg/login
         var note = document.evaluate("//div[@class='note']",document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
         if (note) {
            commentContainer.parentNode.insertBefore(note, commentContainer.nextSibling);
         }
      }
   break;
   }
}


// UPDATE NOTIFIER (Version 7: January 14, 2008)
// (Inspired by UserScript Update Notification by Seifer: http://userscripts.org/scripts/show/12193)
var scriptName = "The Alligator Comments Fixer";
var scriptID = '12999';
var scriptVersion = 0.4;
var scriptChanges = "Updated @include URLs.";

var checkForUpdates = GM_getValue('checkForUpdates', true);
if (checkForUpdates == true) {
var lastCheck = GM_getValue('lastCheck', 0);
var d = new Date();
var currentTime = Math.round(d.getTime() / 1000); // Unix time in seconds
if (currentTime >= lastCheck + 1209600) { // (number of seconds in 2 weeks
   GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://userscripts.org/scripts/review/' + scriptID + '?format=txt',
    headers: {'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey','Accept': 'text/plain',},
    onload: function(responseDetails) {
        var script = responseDetails.responseText;
        var chooseToUpdate;
        function createNotice(noticeText) {
           var notice = document.createElement('div');
           with (notice.style) { id = 'GMscriptnotice'; position = 'fixed'; top = '0px'; left = '0px'; width = '100%'; background = '#ffeb7c'; zIndex = '1000'; textAlign = 'center'; font = '12px sans-serif'; fontWeight = 'normal'; color = '#000'; padding = '5px 3px 5px 3px'; margin = '0px'; borderTop = '0px'; borderRight = '0px'; borderBottom = '1px solid #beaf5d'; borderLeft = '0px'; }
           notice.innerHTML = noticeText;
           document.getElementsByTagName('body')[0].appendChild(notice);
           document.getElementById('upgradeLink').addEventListener('click', function(event) {
              notice.parentNode.removeChild(notice);
           }, true);
           document.getElementById('waitLink').addEventListener('click', function(event) {
              event.stopPropagation();
              event.preventDefault();
              alert('You will be notified again after two weeks.');
              notice.parentNode.removeChild(notice);
           }, true);
           document.getElementById('offLink').addEventListener('click', function(event) {
              event.stopPropagation();
              event.preventDefault();
              var confirmTurnOff = confirm('Are you sure you no longer want to be notified of updates to this script?');
              if (confirmTurnOff) {
                 alert('You will no longer be notified of updates to ' + scriptName + '. You can change this preference in about:config.');
                 GM_setValue('checkForUpdates', false);
                 notice.parentNode.removeChild(notice);
              }
           }, true);
        }
        var linkStyle = 'color: #00f; text-decoration: underline; font: 12px sans-serif';
        if (script.indexOf('var scriptVersion = ' ) > -1) {
           var foo = script.match(/var scriptVersion = [\d\.]+/i) + ''; // makes it a string
           var versionOnSite = foo.match(/[\d\.]+/);
           if (versionOnSite != scriptVersion) {
              var newScriptChanges = '';
              foo = script.match(/var scriptChanges = "[^"]+"/i) + '';
              if (foo) {
                 foo = foo.match(/"[^"]+"/) + '';
                 newScriptChanges = 'What\'s new in version ' + versionOnSite + ': ' + foo.replace(/"/g,'') + '<br />';
              }
              var noticeText = 'An update to the Greasemonkey user script "' + scriptName + '" is available. You are running version ' + scriptVersion + '.<br />' + newScriptChanges + '<a href="http://userscripts.org/scripts/source/' + scriptID + '.user.js" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">Upgrade to version ' + versionOnSite + ' now</a>, <a href="#" style="' + linkStyle + '; font-weight: normal" id="waitLink">wait until later</a>, or <a href="#" style="' + linkStyle + '; font-weight: normal" id="offLink">turn off these notifications</a>.';
              createNotice(noticeText);
           }
        }
        else { // if the new version of the script doesn't have this update mechanism
           var noticeText = 'An update to the Greasemonkey user script "' + scriptName + '" is available.<br /><a href="http://userscripts.org/scripts/source/' + scriptID + '.user.js" style="' + linkStyle + '; font-weight: bold" id="upgradeLink">Upgrade now</a>, <a href="#" style="' + linkStyle + '; font-weight: normal" id="waitLink">wait until later</a>, or <a href="#" style="' + linkStyle + '; font-weight: normal" id="offLink">turn off these notifications</a>.';
           createNotice(noticeText);
        }
    }
   });
   GM_setValue('lastCheck', currentTime);
}
}
// END OF UPDATE NOTIFIER