Skip to content

Instantly share code, notes, and snippets.

@digulla
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digulla/e5a80a8e03e6adea2d38 to your computer and use it in GitHub Desktop.
Save digulla/e5a80a8e03e6adea2d38 to your computer and use it in GitHub Desktop.
Sortiert das Inhaltsverzeichnis der c't 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment