Skip to content

Instantly share code, notes, and snippets.

@yuuan
Created November 9, 2012 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuuan/4046748 to your computer and use it in GitHub Desktop.
Save yuuan/4046748 to your computer and use it in GitHub Desktop.
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