I have created a script (mediawiki gadget), which iterates over every redlink in a rendered wiki-page (that is, over every href with class new
, signifying an internal link to an article that does not exist), and checks if the title exists in a set of known pages. If it does, a few attributes are changed. The execution is extremely simple, but I need it to be as fast as possible.
The set of known pages contains nearly 20K strings, here omitted:
const rawPages=new Set([...])
$("#mw-content-text a.new").each(function() {
var b=$(this),a=b.attr("title");
!a||
a.startsWith("קאַטעגאָריע:") ||
a.startsWith("טעקע:") ||
a.startsWith("שמועס:") ||
a.startsWith("באניצער:") ||
a.startsWith("המכלול:") ||
a.startsWith("הילף:") ||
a.startsWith("מעדיעװיקי:") ||
a.startsWith("מוסטער:") ||
a.startsWith("יחידה:") ||
a.startsWith("דרעפט:") ||
a.startsWith("טעמע:") ||
(a=a.replace(" (בלאַט עקזיסטירט נאכנישט)", ""),
rawPages.has(a)&&
b.attr({
"class": "raw",
"title": a + " (רוי)",
"href": "/"+encodeURIComponent("רוי")+":"+encodeURIComponent(a)
}))});
At first, the script checks if the title begins with some prefixes, in which case we are not interested in modifying the link. But the rawPages
set does not contain any such title anyway; would it be faster to check directly for membership, instead of trying to short-circuit with multiple startsWith
calls?
Anything else I can do, to speed it up?
Thanks!