Google Books Allow copy

-

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:ko         구글북스 복사 활성화
// @name            Google Books Allow copy
// @namespace       https://ndaesik.tistory.com/
// @version         1
// @description:ko  -
// @description     -
// @match           *://play.google.com/books/*
// @match           *://books.googleusercontent.com/books/reader/frame*
// @icon            https://www.gstatic.com/images/branding/product/2x/play_books_96dp.png
// @grant           GM_setClipboard
// @run-at          document-idle
// ==/UserScript==

(function() {
    const isIframe = window.location.href.includes('books.googleusercontent.com/books/reader/frame');

    if (isIframe) {
        const style = document.createElement('style');
        style.textContent = `* {user-select: text !important} .overlay, .selection-overlay, .page-overlay {display: none !important}`;
        document.head.appendChild(style);

        document.addEventListener('copy', e => e.stopPropagation(), true);
        document.addEventListener('keydown', e => {
            if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
                e.preventDefault();
                const text = window.getSelection().toString().trim();
                if (text) window.parent.postMessage({ type: 'COPY_TEXT', text }, '*');
            }
        }, true);
    } else {
        window.addEventListener('message', e => {
            if (e.data?.type === 'COPY_TEXT' && e.data.text) {
                GM_setClipboard(e.data.text);
            }
        });
    }
})();