Paper Clip (Save pages as XHTML/Markdown/Text)

Edit and save selection as clean XHTML, Markdown or Text file optimized for printing. Hotkey: Command + Shift + S.

旧版: v24.01.29 - 2024-01-29 - Update title and description
新版: v25.01.24 - 2025-01-24 - Add functionality to mark (i.e. highlight) text.

  • --- /tmp/diffy20250810-1347615-1z60ki 2025-08-10 12:35:52.387628324 +0000
  • +++ /tmp/diffy20250810-1347615-4jh9mt 2025-08-10 12:35:52.387628324 +0000
  • @@ -1,19 +1,19 @@
  • // ==UserScript==
  • -// @name Paper Clip (Save as HTML, Markdown and Text)
  • +// @name Paper Clip (Save as HTML, Markdown or Text)
  • // @description Edit and save selection as clean HTML, Markdown or Text file optimized for printing. Hotkey: Command + Shift + S.
  • // @author Schimon Jehudah, Adv.
  • // @namespace i2p.schimon.paperclip
  • -// @homepageURL https://gf.qytechs.cn/en/scripts/465960-paper-clip
  • -// @supportURL https://gf.qytechs.cn/en/scripts/465960-paper-clip/feedback
  • +// @homepageURL https://gf.qytechs.cn/scripts/465960-paper-clip
  • +// @supportURL https://gf.qytechs.cn/scripts/465960-paper-clip/feedback
  • // @updateURL https://gf.qytechs.cn/scripts/465960-paper-clip/code/Paper%20Clip.meta.js
  • // @downloadURL https://gf.qytechs.cn/scripts/465960-paper-clip/code/Paper%20Clip.user.js
  • -// @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  • +// @copyright 2023 - 2025, Schimon Jehudah (http://schimon.i2p)
  • // @license MIT; https://opensource.org/licenses/MIT
  • // @require https://unpkg.com/turndown/dist/turndown.js
  • // @exclude devtools://*
  • // @match file:///*
  • // @match *://*/*
  • -// @version 24.01.29
  • +// @version 25.01.24
  • // @run-at document-end
  • // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5OOPC90ZXh0Pjwvc3ZnPgo=
  • // ==/UserScript==
  • @@ -63,11 +63,13 @@
  • 4) Replace element img with attribute alt to element span
  • https://datawrapper.dwcdn.net/qBzPR/6/
  • +5) Code (pre) is realized as one line questions/72294299/multiple-top-level-packages-discovered-in-a-flat-layout
  • +
  • */
  • // Check whether HTML; otherwise, exit.
  • //if (!document.contentType == 'text/html')
  • -if (document.doctype == null) return;
  • +//if (document.doctype == null) return;
  • var
  • originalBackground, originalColor,
  • @@ -99,6 +101,7 @@
  • // TODO Move "append"s to a function
  • btn.append(actionButton('close'));
  • btn.append(actionButton('save'));
  • + btn.append(actionButton('highlight'));
  • btn.append(actionButton('edit'));
  • btn.append(actionButton('send'));
  • document.body.append(btn);
  • @@ -126,11 +129,10 @@
  • btn.id = namespace;
  • // btn.textContent = '📎'; // 🖇️ 💾
  • // set position
  • + btn.style.all = 'unset';
  • btn.style.position = 'absolute';
  • - //btn.style.left = x + 5 + 'px';
  • - //btn.style.top = y + 'px';
  • - btn.style.left = x + 'px';
  • - btn.style.top = y - 50 + 'px';
  • -
  • + btn.style.left = x + 5 + 'px';
  • + btn.style.top = y + 'px';
  • // set appearance
  • btn.style.direction = 'ltr';
  • btn.style.fontFamily = 'system-ui'; // cursive sans-serif emoji
  • @@ -184,6 +186,7 @@
  • item.parentElement.replaceChildren(
  • actionButton('close'),
  • actionButton('save'),
  • + actionButton('highlight'),
  • actionButton('edit'),
  • actionButton('send')
  • )
  • @@ -231,6 +234,12 @@
  • item.title = 'Send via Email as reference';
  • item.onclick = () => {window.location = `mailto:?subject=Content on ${location.hostname}&body=${document.title}%0D%0A%0D%0A${content}%0D%0A%0D%0A${location.hostname}${location.pathname}`};
  • break;
  • + case 'highlight':
  • + item.textContent = 'Mark';
  • + item.title = 'Highlight text';
  • + //item.onclick = () => {highlightSelection('black', 'khaki');};
  • + item.onclick = () => {drawBorder('black', 'khaki', 'unset');};
  • + break;
  • case 'irc':
  • item.textContent = 'IRC';
  • item.title = 'Send via IRC as reference';
  • @@ -252,8 +261,8 @@
  • item.onclick = () => {generateXHTML();};
  • break;
  • case 'xmpp':
  • - item.textContent = 'Jabber';
  • - item.title = 'Send via XMPP as reference';
  • + item.textContent = 'XMPP';
  • + item.title = 'Send via Jabber as reference';
  • item.onclick = () => {window.location = `xmpp:?subject=Content on ${location.hostname}&body=${document.title}%0D%0A%0D%0A${content}%0D%0A%0D%0A${location.hostname}${location.pathname}`};
  • break;
  • case 'save':
  • @@ -298,8 +307,25 @@
  • return texts;
  • }
  • +// FIXME
  • +function highlightSelection(color, background) {
  • + let sel = document.getSelection();
  • + originalColor = sel.style.color;
  • + originalBackground = sel.style.background;
  • + //sel.style.background = 'rgb(250 250 210)';
  • + sel.style.background = background;
  • + //sel.style.color = 'black'; // DarkRed
  • + sel.style.color = color;
  • +}
  • +
  • function drawBorder(color, background, outline) {
  • +//function drawBorder(color, background, outline, method) {
  • let sel = getSelectedText();
  • + //if (method == 'exactly') {
  • + // let sel = getSelectedText();
  • + //} else {
  • + // let sel = document.getSelection();
  • + //}
  • originalColor = sel.style.color;
  • originalOutline = sel.style.outline;
  • originalBackground = sel.style.background;
  • @@ -479,8 +505,7 @@
  • data = removeMultipleWhiteSpace(data);
  • savePage(
  • data,
  • - // NOTE xhtml is also valid
  • - createFilename('html'),
  • + createFilename('xhtml'),
  • "text/html"
  • );
  • }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址