Created
September 14, 2009 15:06
-
-
Save Milly/186707 to your computer and use it in GitHub Desktop.
Add citenote tooltip to Wikipedia
This file contains hidden or 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 WikipediaCiteNoteTooltip.user.js | |
// @namespace http://d.hatena.ne.jp/MillyC/ | |
// @description Wikipedia cite-note tooltip | |
// @include http://*.wikipedia.org/wiki/* | |
// ==/UserScript== | |
(function(){ | |
GM_addStyle( | |
'a[href^="#cite_note-"]:hover {' + | |
' background-color: #ddeeff;' + | |
' text-decoration: none;' + | |
'}' + | |
'a[href^="#cite_note-"] > span {' + | |
' display: none;' + | |
'}' + | |
'a[href^="#cite_note-"]:hover > span {' + | |
' display: inline;' + | |
' position: absolute;' + | |
' z-index: 10;' + | |
' max-width: 300px;' + | |
' background-color: #ddeeff;' + | |
' border: 1px solid #808080;' + | |
' padding: 5px;' + | |
' line-height: 1.2em;' + | |
' text-align: left;' + | |
' color: black;' + | |
' font-weight: normal;' + | |
'}' | |
); | |
var cite_notes = []; | |
var cite_notes_ss = document.evaluate('//li[starts-with(@id, "cite_note-")]', | |
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0; i < cite_notes_ss.snapshotLength; ++i) { | |
var cite_note = cite_notes_ss.snapshotItem(i); | |
var index = cite_note.id.match(/\d+$/)[0]; | |
var tooltip = document.createElement('span'); | |
tooltip.innerHTML = cite_note.innerHTML | |
.replace(/\^/, '') | |
.replace(/<b>.*?<\/b>\s*/m, '') | |
.replace(/<a\s+href="#cite_ref-.*?<\/a>\s*/mg, ''); | |
cite_notes[index] = tooltip; | |
} | |
var cite_refs_ss = document.evaluate('//a[starts-with(@href, "#cite_note-")]', | |
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0; i < cite_refs_ss.snapshotLength; ++i) { | |
var cite_ref = cite_refs_ss.snapshotItem(i); | |
var index = cite_ref.href.match(/\d+$/)[0]; | |
cite_ref.appendChild( cite_notes[index].cloneNode(true) ); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment