// ==UserScript== // @name Copy title // @name:zh-CN 便捷复制页签 title // @namespace http://tampermonkey.net/Henry // @version 1.0.1 // @description use Ctrl + q copy title; Alt + q copy title and url, create markdown // @description:zh-CN Ctrl + q 复制页签标题;Alt + q 复制页签标题及链接,生成 markdown 格式 // @author Henry // @icon https://tsz.netlify.app/img/favicon.png // @match http*://*/* // @license MIT // @resource css https://gitee.com/mirrors/jsMessage/raw/master/codebase/themes/message_solid.css // @grant GM_addStyle // @grant GM_getResourceText // @downloadURL none // ==/UserScript== (function () { 'use strict'; GM_addStyle(GM_getResourceText('css')); document.addEventListener('keydown', listener, false); function listener(event) { const { keyCode, ctrlKey, altKey } = event; if (keyCode === 81 && ctrlKey) { event.preventDefault(); event.stopPropagation(); copyTextToClipboard(document.title); return false; } if (keyCode === 81 && altKey) { event.preventDefault(); event.stopPropagation(); copyTextToClipboard(`[${document.title}](${location.href})`); return false; } } function copyTextToClipboard(text) { if (!navigator.clipboard) { fallbackCopyTextToClipboard(text); return; } navigator.clipboard.writeText(text).then( function () { wrapperMsg('Copying: ' + text); }, function (err) { wrapperMsg('Oops, unable to copy'); } ); } function wrapperMsg(input) { window.dhtmlx.message(input); } function fallbackCopyTextToClipboard(text) { let 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 ? text : ''; wrapperMsg('Copying: ' + msg); } catch (err) { wrapperMsg('Oops, unable to copy'); } document.body.removeChild(textArea); } })(); if(!window.dhtmlx) window.dhtmlx = {}; (function(){ var _dhx_msg_cfg = null; function callback(config, result){ var usercall = config.callback; modality(false); config.box.parentNode.removeChild(config.box); _dhx_msg_cfg = config.box = null; if (usercall) usercall(result); } function modal_key(e){ if (_dhx_msg_cfg){ e = e||event; var code = e.which||event.keyCode; if (dhtmlx.message.keyboard){ if (code == 13 || code == 32) callback(_dhx_msg_cfg, true); if (code == 27) callback(_dhx_msg_cfg, false); } if (e.preventDefault) e.preventDefault(); return !(e.cancelBubble = true); } } if (document.attachEvent) document.attachEvent("onkeydown", modal_key); else document.addEventListener("keydown", modal_key, true); function modality(mode){ if(!modality.cover){ modality.cover = document.createElement("DIV"); //necessary for IE only modality.cover.onkeydown = modal_key; modality.cover.className = "dhx_modal_cover"; document.body.appendChild(modality.cover); } var height = document.body.scrollHeight; modality.cover.style.display = mode?"inline-block":"none"; } function button(text, result){ return "
"+text+"
"; } function info(text){ if (!t.area){ t.area = document.createElement("DIV"); t.area.className = "dhtmlx_message_area"; t.area.style[t.position]="5px"; document.body.appendChild(t.area); } t.hide(text.id); var message = document.createElement("DIV"); message.innerHTML = "
"+text.text+"
"; message.className = "dhtmlx-info dhtmlx-" + text.type; message.onclick = function(){ t.hide(text.id); text = null; }; if (t.position == "bottom" && t.area.firstChild) t.area.insertBefore(message,t.area.firstChild); else t.area.appendChild(message); if (text.expire > 0) t.timers[text.id]=window.setTimeout(function(){ t.hide(text.id); }, text.expire); t.pull[text.id] = message; message = null; return text.id; } function _boxStructure(config, ok, cancel){ var box = document.createElement("DIV"); box.className = " dhtmlx_modal_box dhtmlx-"+config.type; box.setAttribute("dhxbox", 1); var inner = ''; if (config.width) box.style.width = config.width; if (config.height) box.style.height = config.height; if (config.title) inner+='
'+config.title+'
'; inner+='
'+(config.content?'':config.text)+'
'; if (ok) inner += button(config.ok || "OK", true); if (cancel) inner += button(config.cancel || "Cancel", false); if (config.buttons){ for (var i=0; i