c’t Inhaltsverzeichnis sortieren

Eine kleine Hilfe für alle Leser der c’t, welche einfach(er) einige Artikel archivieren wollen: Das verlinkte Script unten sortiert das Inhaltsverzeichnis im Archiv nach Seitenzahl wenn man auf “aktuell” klickt.


// ==UserScript==
// @name c't Inhaltsverzeichnis sortieren
// @namespace http://www.pdark.de/
// @version 1.0
// @description Sortiert das Inhaltsverzeichnis der c't nach Seitenzahl, wenn man auf "aktuell" klickt
// @match https://www.heise.de/artikel-archiv/ct/*
// @copyright 2014+, Aaron Digulla
// @grant unsafeWindow
// ==/UserScript==
var $ = unsafeWindow.jQuery;
var jQuery = unsafeWindow.jQuery;
var console = unsafeWindow.console;
function sortBySeitenzahl() {
var rows = $('td.seitenzahl').parent();
var bySeitenzahl = function(a,b) {
var keyA = $('td.seitenzahl', a).text();
var keyB = $('td.seitenzahl', b).text();
return parseInt(keyA) parseInt(keyB);
}
rows.sort(bySeitenzahl);
var table = $($(rows[0]).parents('table')[0]);
$.each(rows, function (index, row) { table.append(row); });
}
function setup() {
var rows = $('td.seitenzahl').parent();
var table = $($(rows[0]).parents('table')[0]);
var th = $($('th', table)[0]);
// Ein Mal sortieren, wenn auf den Kopf der Tabelle geklickt wird
th.one('click', sortBySeitenzahl);
// Aktuelle Zeile in der Tabelle besser hervorheben
table.addClass('toc');
$('<style>').attr('style', 'text/css').text('.toc tr:hover { background-color: #ffff99 }').appendTo($('head'));
// Deutlich machen, wie man das Script aktiviert
th.css({'color': 'blue', 'text-decoration': 'underline', 'cursor': 's-resize'});
}
setup();
console.log('Auf "aktuell" klicken, um das Inhaltsverzeichnis zu sortieren');

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: