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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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'); |