Reference Tooltips for NicoNicoPedia

ニコニコ大百科記事の脚注リンクに内容をポップアップ表示します

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

/* jshint esversion: 6 */
// ==UserScript==
// @name         Reference Tooltips for NicoNicoPedia
// @namespace    https://greasyfork.org/ja/users/289387-unagionunagi
// @version      0.3
// @description  ニコニコ大百科記事の脚注リンクに内容をポップアップ表示します
// @author       unagiOnUnagi
// @match        *://dic.nicovideo.jp/*
// @grant        none
// @license      GPL-2.0-or-later
// ==/UserScript==

(function() {
    'use strict';
    for (let ref of document.querySelectorAll('#article a[class="dic"][href^="#"]:not([title])')) {
        let cite;
        let href = ref.getAttribute('href');
        let refid = href.match(/#((?:%5E)?\d+)/i);
        if (refid) {
            refid = decodeURIComponent(refid[1]);
            cite = document.querySelector(`a[name="${refid}"]`);
        } else {
            cite = document.querySelector(href);
        }

        if (!cite) {
            console.log(`Reference Tooltips for NicoNicoPedia: unknown reference (${href})`);
            continue;
        }
        ref.title = cite.parentNode.innerText.trim().replace(/\s+/g, ' ');
    }
})();