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 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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();
})();