Forked from maripo/wikipedia_language_labels.user.js
Last active
September 20, 2015 13:24
-
-
Save vzvu3k6k/a7677d90d4427ead6cae to your computer and use it in GitHub Desktop.
Enhance links to other languages on Wikipedia
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 Wikipedia Language Labels | |
// @description Enhance interlanguage links on the sidebar (e.g. Change "Français" to "Étoile (Français)" on https://en.wikipedia.org/wiki/Star ) | |
// @match https://*.wikipedia.org/wiki/* | |
// @grant none | |
// @version 2 | |
// @noframes | |
// ==/UserScript== | |
// Original: https://gist.github.com/maripo/3925496 | |
/* | |
Customize labels by editing LABEL_STYLE. | |
"${LABEL}", "${LANG_CODE}" and "${LANG_NAME}" will be replaced. | |
e.g. | |
"${LABEL} (${LANG_NAME})" => "Étoile (Français)" | |
"[${LANG_CODE}]${LABEL}" => "[fr]Étoile" | |
*/ | |
const LABEL_STYLE = '${LABEL} (${LANG_NAME})'; | |
const links = document.querySelectorAll('#p-lang .interlanguage-link > a'); | |
for (let link of links) { | |
link.textContent = LABEL_STYLE.replace(/\${(\w+)}/g, (body, key) => { | |
switch (key) { | |
case 'LABEL': | |
return decodeURIComponent(link.pathname.substring(6)).replace(/_/g, ' '); | |
case 'LANG_CODE': | |
return link.lang; | |
case 'LANG_NAME': | |
return link.textContent; | |
default: | |
return body; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment