您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Copy Notion Database item property values by clicking Shift + LeftMouseButton on it
当前为
- // ==UserScript==
- // @name Notion Copy Properties
- // @namespace https://www.notion.so/
- // @version 0.8
- // @description Copy Notion Database item property values by clicking Shift + LeftMouseButton on it
- // @author Maxim Kurbatov
- // @match https://www.notion.so/*
- // @grant GM_addStyle
- // @run-at document-end
- // ==/UserScript==
- var debug = false;
- GM_addStyle(`.copyable-property:hover { font-style: italic; }`);
- // create an observer instance
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- var target = false;
- if ( mutation.target.nodeName == "DIV" ) target = mutation.target;
- else target = mutation.target.parentElement;
- if ( target.getAttribute("contentEditable") == "true" ) target = target.parentElement;
- if ( ! target ) return;
- addCopyHandler(target);
- });
- });
- var config = { characterData: true, attributes: false, childList: true, subtree: true };
- var mutgt = document.body;
- observer.observe(mutgt, config);
- var lastBlock = false;
- function addCopyHandler(elm) {
- elm = elm || document;
- //if ( typeof elm.querySelectorAll !== 'function' ) return;
- //var blocks = elm.querySelectorAll("#notion-app .notion-focusable");
- const blocks = document.querySelector('.notion-page-view-discussion').parentNode.querySelector('div > div[style="margin: 0px;"]').querySelectorAll('.notion-focusable');
- blocks.forEach(function(block) {
- block.addEventListener('click', onClick);
- block.classList.add('copyable-property');
- });
- }
- function onClick(e) {
- const elem = e.currentTarget;
- console.log("Copying text: " + elem.innerText);
- if (e.shiftKey) {
- copyTextToClipboard(elem.innerText);
- const color = elem.style.color;
- elem.style.color = "red";
- setTimeout(function() { elem.style.color = color; }, 300);
- }
- }
- function fallbackCopyTextToClipboard(text) {
- var textArea = document.createElement("textarea");
- textArea.value = text;
- // Avoid scrolling to bottom
- textArea.style.top = "0";
- textArea.style.left = "0";
- textArea.style.position = "fixed";
- document.body.appendChild(textArea);
- textArea.focus();
- textArea.select();
- try {
- var successful = document.execCommand('copy');
- var msg = successful ? 'successful' : 'unsuccessful';
- console.log('Fallback: Copying text command was ' + msg);
- } catch (err) {
- console.error('Fallback: Oops, unable to copy', err);
- }
- document.body.removeChild(textArea);
- }
- function copyTextToClipboard(text) {
- if (!navigator.clipboard) {
- fallbackCopyTextToClipboard(text);
- return;
- }
- navigator.clipboard.writeText(text).then(function() {
- console.log('Async: Copying to clipboard was successful!');
- }, function(err) {
- console.error('Async: Could not copy text: ', err);
- });
- }