Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add pop-up on reference to footnote
// ==UserScript==
// -*- mode:JScript; Encoding:utf8n -*-
// @name Wikipedia.citePopup
// @namespace http://d.hatena.ne.jp/p-arai/
// @description Add pop-up on reference to footnote
// @include http://ja.wikipedia.org/wiki/*
// @grant none
//
// @author p-arai, yuuAn
// @version 2012.11.10
// ==/UserScript==
(function () {
// retrive array of cites
var cites = new Array();
var lis = document.getElementsByTagName("li");
for (var i=0; i < lis.length; i++){
var li = lis[i];
if (li.id.match(/^cite_note(?:-[\w\.]+){0,}-(\d+)$/)){
var index = RegExp.$1;
cites[index] = li;
}
}
// retrive and modify reference element
var hrefs = document.getElementsByTagName("a");
for (var i=0; i < hrefs.length; i++){
var a = hrefs[i];
if (a.href.match(/#cite_note(?:-[\w\.]+){0,}-(\d+)$/)){
var index = RegExp.$1;
if (typeof a.textContent != "undefined") {
a.title = cites[index].textContent.replace(/^[^]\s*/, "");
} else {
a.title = cites[index].innerText.replace(/^[^]\s*/, "");
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.