Last active
August 29, 2015 14:12
-
-
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
This file contains hidden or 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment