Subscribe to EdwinNameless' Fake Blog        RSS Feed
-----

My Latest GreaseMonkey Script for DIC

Icon Leave Comment
Despite all the amazing work the guys in DIC have done for the upgrade, the site is still a bit flaky. One of the most annoying snags is the fact that blog posts cannot be posted with year 2010, so they all end up down the list of posts. Another one is that code boxes are still tiny.

This GreaseMonkey script fixes these 2 issues. It is still work in progress, as I'll probably be adding extra stuff in there, but it might prove useful to other people out there:

// ==UserScript==
// @name          DreamInCodeBlogIssue
// @namespace      http://www.dreamincode.net
// @include        http://www.dreamincode.net/forums/*
// @author         EdwinNameless
// ==/UserScript==

(function() {
    var DreamInCode = {
        addCurrentYearToSelect: function() {
            var date = new Date();
            var option = document.createElement("option");
            option.setAttribute("value", date.getFullYear());
            option.setAttribute("selected", "selected");
            option.appendChild(document.createTextNode(date.getFullYear()));
            
            var select = document.evaluate(
                '//select[@name="entry_year"]',
                document,
                null,
                XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                null);
            
            for (var i = 0; i < select.snapshotLength; i++) {
                var year = select.snapshotItem(i);
                year.insertBefore(option, year.firstChild);
            }
        },
        
        isBlogPage: function(link) {
            return link.match(/^http:\/\/www\.dreamincode\.net\/[^?]*\?app=blog/i);
        },
	
	enlargeCodeBox: function() {
	    var codeBoxes = document.getElementsByClassName("prettyprint");
	    for each (codebox in codeBoxes) {
		    codebox.style.width = "auto";
	    }
	},
	
    };
    
    var currentUrl =  window.location.href;
    
    DreamInCode.enlargeCodeBox();
    if (DreamInCode.isBlogPage(currentUrl)) {
        DreamInCode.addCurrentYearToSelect();
    }
    
})();




To install it, you obviously have to have the GreaseMonkey add-on installed in Firefox. Copy-paste the script above into a file called "dreamincode.user.js", and open the file with Firefox (File > Open File...). Firefox will then ask you if you want to install the script. Accept, and you're sorted.

0 Comments On This Entry

 

About...

This is my fake blog. 'Cause I also have a real blog with real stuff in it.

December 2014

S M T W T F S
 123456
78910111213
14151617181920
212223242526 27
28293031   

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)