Ich habe mein erstes Userscript/Greasemonkey-Script mit Unterstützung durch jQuery geschrieben.
Hab gerade festgestellt, das selbiges Skript mit minimalen Änderungen und zusätzlichen Kommentaren immer noch in meinem Browser-Profil lebt.
Code
// ==UserScript==
// @name Dubhistory Forum
// @namespace http://dosamp.net/
// @version 0.4
// @description Kennzeichnet Post-IDs mit wiederholenden Endziffern im Winhistory-Forum.
// @match *://www.winhistory-forum.net/showthread.php?*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// ==/UserScript==
(function() {
'use strict';
// at the moment we're at about pid=500000, so most possible multiples are sexts at the moment
var multiples_names = ['Singles', 'Dubs', 'Trips', 'Quads', 'Quints', 'Sexts'];
var multiples_colors = ['', '000080', '400060', '800040', 'c00020', 'ff0000'];
function multiples(pid) {
// most efficient number-to-string in JavaScript
var pidstr = "" + pid;
var matches = 1;
// moved error detection for post #1111111 here, by extrapolation reached in 2026
for (var m = 2; m <= Math.min(pidstr.length, multiples_names.length - 1); m++) {
// are the m last digits equal to the last one?
if (pidstr.slice(-m) === new Array(m+1).join(pidstr.slice(-1))) {
matches = m;
} else {
break;
}
}
return matches;
}
// fuck yeah, CSS selectors
$('div[style="float: right; width: auto; vertical-align: top"] > span.smalltext > strong > a').each(function(index) {
var pidoff = $(this).attr('href').indexOf('#pid') + 4;
if (pidoff > 3) { // -1 (not found) + 4 ('#pid'.length) == 3
var pid = $(this).attr('href').substring(pidoff);
var mpls = multiples(pid);
if (mpls > 1) {
var mmpls = pid.slice(0, -mpls) + '*' + pid.slice(-mpls) + '*';
$(this).parent().before(
'<strong style="color:#' + multiples_colors[mpls-1] + '" title="' + mmpls + '">' + multiples_names[mpls-1] + '</strong> | '
);
}
}
});
})();
Alles anzeigen
