他言語版のリンクをh1の隣に持ってくるやつ。
ja,en,itという並びは適当。
// ==UserScript== | |
// @name Wikipediaで他言語版のリンクをh1の隣に持ってくる | |
// @namespace https://github.com/unarist/ | |
// @downloadURL https://gist.github.com/unarist/788550b564fd5310d12f/raw/wikipedia-lang-links.user.js | |
// @version 0.2.1 | |
// @description Add link for InterWikis into h1 tag | |
// @author unarist | |
// @license MIT License | |
// @match https://*.wikipedia.org/wiki/* | |
// @grant none | |
// @run-at document-idle | |
// @noframes | |
// ==/UserScript== | |
(function(){ | |
"use strict"; | |
const tag = (name, props = {}) => Object.assign(document.createElement(name), props) | |
const langs = 'ja,en,it'.split(','); | |
const titleFilters = { | |
ja: /^.+?: / | |
}; | |
const currentLang = window.location.host.substr(0, 2); | |
const titleFilter = titleFilters[currentLang] || / [-–] .+?$/; | |
const targetNode = document.querySelector('h1'); | |
for (const lang of langs) { | |
if (lang === currentLang) continue; | |
const node = document.querySelector(`.interwiki-${lang} a`).cloneNode() || tag('span', { title: '-' }); | |
node.textContent = `${lang}: ${node.title.replace(titleFilter, '')}`; | |
node.style = 'font-size: small; margin-left: 1em'; | |
targetNode.appendChild(node); | |
} | |
})(); |