Hypothesis Button on Every Page / 每個頁面上的 Hypothesis 按鈕

Add a button to enable Hypothesis on any webpage. The button will be removed after being clicked. / 在任意網頁上添加一個按鈕,以啟用 Hypothesis。點擊按鈕後,按鈕將被移除。

目前为 2023-03-30 提交的版本。查看 最新版本

// ==UserScript==
// @name            Hypothesis Button on Every Page / 每個頁面上的 Hypothesis 按鈕
// @namespace       iamfredchu
// @version         0.0.2
// @description     Add a button to enable Hypothesis on any webpage. The button will be removed after being clicked. / 在任意網頁上添加一個按鈕,以啟用 Hypothesis。點擊按鈕後,按鈕將被移除。
// @author          Fred Chu
// @match           https://*/*
// @inject-into     content
// @run-at          document-end
// @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

(function() {
    function enableHypothesis() {
        const d = document;
        const s = document.createElement('script');
        s.setAttribute('src', 'https://hypothes.is/embed.js');
        d.body.appendChild(s);
        // Remove the button after it's clicked
        hypothesisButton.remove();
    }

    function createHypothesisButton() {
        const btn = document.createElement('button');
        btn.textContent = 'Enable Hypothesis';
        btn.style.position = 'fixed';
        btn.style.bottom = '10px';
        btn.style.right = '10px';
        btn.style.zIndex = '9999';
        btn.addEventListener('click', enableHypothesis);
        document.body.appendChild(btn);
        return btn;
    }

    const hypothesisButton = createHypothesisButton();
})();