Hi,
I've searched a bit in the forums to see if this has already been posted and I couldn't find anything. If I've missed it, sorry to add to the noise...
But anyway, I've always preferred to read sequential stories in order, and most of the time authors make it easy by adding numbers to the end of their titles (thereby making sure they are sorted correctly, because the member story page sorts by alphabet on the title). However, sometimes stories are sequels to other stories with different names and then the order is shot. As I'm not an American the format for the date makes it extra irritating to try to order the stories in my head.
Finally having had enough of all this, I decided to fix the problem myself. And as I've got it working and I though there might be more people that like their stories ordered like I do, I've decided to post the solution here.
It only works if you have firefox and greasemonkey (an add-on to firefox) installed, as the solution is to 'fix' the page with a greasemonkey script.
The script is included in this post below, all you need to do is save the text of it somewhere as a file named 'literotica.user.js' (or something similar, the end part '.user.js' is necessary for greasemonkey to recognize it as a script it can install) and then install it as a greasemonkey script (and enable it).
The easiest way to install it is to navigate to the saved script file with firefox itself: type in 'file:///' in your address bar and it will start browsing on your computer harddisk, then just navigate to the file and click it. If greasemonkey is enabled it will come up with a pop-up to ask you if you want to install the script. Click the appropriate button and your set...
Now, if you go to the story page of an author it will reorder the stories by date. Voila!
CAUTION: this script works for me, but I have not done intensive testing of it, so it could not work for you, or even mess up your firefox. I take no responsibility for any problems you might have using this script. You can read the code before installing it, so I suggest you do so before trusting it.
But to be honest this script should just work. If not, I'd really like to know. And if it does, I'd also appreciate feedback!
update 1: extended it to add table headers for sorting by title, category or date
update 2: fixed a bug (multiple pages open screwed it up)
I've searched a bit in the forums to see if this has already been posted and I couldn't find anything. If I've missed it, sorry to add to the noise...
But anyway, I've always preferred to read sequential stories in order, and most of the time authors make it easy by adding numbers to the end of their titles (thereby making sure they are sorted correctly, because the member story page sorts by alphabet on the title). However, sometimes stories are sequels to other stories with different names and then the order is shot. As I'm not an American the format for the date makes it extra irritating to try to order the stories in my head.
Finally having had enough of all this, I decided to fix the problem myself. And as I've got it working and I though there might be more people that like their stories ordered like I do, I've decided to post the solution here.
It only works if you have firefox and greasemonkey (an add-on to firefox) installed, as the solution is to 'fix' the page with a greasemonkey script.
The script is included in this post below, all you need to do is save the text of it somewhere as a file named 'literotica.user.js' (or something similar, the end part '.user.js' is necessary for greasemonkey to recognize it as a script it can install) and then install it as a greasemonkey script (and enable it).
The easiest way to install it is to navigate to the saved script file with firefox itself: type in 'file:///' in your address bar and it will start browsing on your computer harddisk, then just navigate to the file and click it. If greasemonkey is enabled it will come up with a pop-up to ask you if you want to install the script. Click the appropriate button and your set...
Now, if you go to the story page of an author it will reorder the stories by date. Voila!
CAUTION: this script works for me, but I have not done intensive testing of it, so it could not work for you, or even mess up your firefox. I take no responsibility for any problems you might have using this script. You can read the code before installing it, so I suggest you do so before trusting it.
But to be honest this script should just work. If not, I'd really like to know. And if it does, I'd also appreciate feedback!
update 1: extended it to add table headers for sorting by title, category or date
update 2: fixed a bug (multiple pages open screwed it up)
Code:
// Literotica - sort user stories by date
// version 0.3
// 2009-0516
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Literotica - Sort user stories
// @namespace http://none.com/
// @description Sorts user stories by date
// @include http://*.literotica.com*/stories/memberpage.php?uid=*&page=submissions
// ==/UserScript==
var t_body = _get_table_body();
// Reuse the first row as table sorting header
var sorting_row = t_body.removeChild(t_body.firstChild);
if (sorting_row.childNodes.length != 4) {
alert( "Not a useable row for the sorting table header!" );
}
else {
sorting_row.id = 'sorting_row';
for (var i=0;i<sorting_row.childNodes.length;i++) {
sorting_row.childNodes[i].style.backgroundColor = '#77aacc';
sorting_row.childNodes[i].style.textAlign = 'center';
}
sorting_row.childNodes[0].innerHTML = "<a href='#' class='bb sortheader' id='sort_title'>title</a>";
sorting_row.childNodes[2].innerHTML = "<a href='#' class='bb sortheader' id='sort_category'>category</a>";
sorting_row.childNodes[3].innerHTML = "<a href='#' class='bb sortheader' id='sort_date'>date</a>";
}
unsafeWindow.sorted_table = {
date: {
rows: {},
sorted: new Array(),
},
title: {
rows: {},
sorted: new Array(),
},
category: {
rows: {},
sorted: new Array(),
},
};
_initial_sort_table( t_body, sorting_row );
//
// Functions
//
function _get_table_body() {
var first_bb_a = document.evaluate( "//tbody/tr/td/a[@class='bb']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
return first_bb_a.parentNode.parentNode.parentNode;
}
function _initial_sort_table( table_body, sorting_row ) {
var i = 0;
while (table_body.childNodes.length > 0) {
var row = table_body.removeChild(table_body.firstChild);
if (row.childNodes.length == 4) {
var date = _get_date( row );
if (date != false) {
for (var j=0;j<row.childNodes.length;j++) {
row.childNodes[j].style.padding = '5px 2px';
row.childNodes[j].style.borderBottom = '1px dotted #77aacc';
}
var index = date + String( i );
unsafeWindow.sorted_table.date.sorted.push( index );
unsafeWindow.sorted_table.date.rows[index] = row;
// Also save title and category sort arrays
var title_text = document.evaluate("//a[@class='bb']", row, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var title = String( title_text.innerHTML ) + String( i );
index = String(title).toLowerCase();
index = index.replace( /\s/gi, '_' );
unsafeWindow.sorted_table.title.sorted.push( index );
unsafeWindow.sorted_table.title.rows[index] = row;
var category_text = document.evaluate("//a[@class='intext']", row, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var category = String( category_text.innerHTML ) + String( i );
index = String(category).toLowerCase();
index = index.replace( /\s/gi, '_' );
unsafeWindow.sorted_table.category.sorted.push( index );
unsafeWindow.sorted_table.category.rows[index] = row;
}
}
i++;
if (i > 1000) {
// If we pass 1000, probably something wrong...
break;
}
}
// Make sure we actually sort...
for (var key in unsafeWindow.sorted_table) {
unsafeWindow.sorted_table[key].sorted.sort();
}
// Add the sorting table row
table_body.appendChild( sorting_row );
var title_link = document.getElementById('sort_title');
title_link.addEventListener( 'click', function(event) { sort_table('sort_title'); }, false );
var category_link = document.getElementById('sort_category');
category_link.addEventListener( 'click', function(event) { sort_table('sort_category'); }, false );
var date_link = document.getElementById('sort_date');
date_link.addEventListener( 'click', function(event) { sort_table('sort_date'); }, false );
for (var i=0;i<unsafeWindow.sorted_table.date.sorted.length;i++) {
table_body.appendChild( unsafeWindow.sorted_table.date.rows[ unsafeWindow.sorted_table.date.sorted[i] ] );
}
}
function sort_table( sort_by ) {
var sort_key = sort_by.split('_')[1];
var table_body = _get_table_body();
for (var i=1;i<table_body.childNodes.length;i++) {
table_body.removeChild[i];
}
for (var i=0;i<unsafeWindow.sorted_table[sort_key].sorted.length;i++) {
table_body.appendChild( unsafeWindow.sorted_table[sort_key].rows[ unsafeWindow.sorted_table[sort_key].sorted[i] ] );
}
//alert( "resorted table using " + sort_key );
}
function _get_date( row ) {
if (row.childNodes.length != 4) {
// Spacer row
return false;
}
var date_string = row.childNodes[3].innerHTML;
var date = date_string.split('/');
if (date.length != 3) {
// Not a date?
return false;
}
var year = date[2].valueOf();
if (year > 50) {
year = '19' + year;
}
else {
year = '20' + year;
}
return String(year) + date[0] + date[1];
}
Last edited: