I made this a while ago but relied on a PR to work. I thought I would share it properly now that the PR was merged in 2.3.
This is a Tamper Monkey script that works as an example for using JS to store a tiddler in the clipboard. This particular script allows you to highlight some text, right-click it, move down to the tamper monkey menu, and hit copy as tiddler.
It would be relatively easy to create a copy-and-paste tiddler plugin if the demand exists.
// ==UserScript==
// @name Copy as Tiddler
// @version 0.1
// @description Copies text to a tiddler format.
// @author You
// @match *://*/*
// @run-at context-menu
// ==/UserScript==
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
(function() {
'use strict';
const data = {
url: window.location.href,
text: getSelectionText(),
title: document.title,
};
/*
This is the way you are supposed to do it. TiddlyWiki does not support it at the time of writing this.
The way I do it is depricated.
https://developer.chrome.com/blog/web-custom-formats-for-the-async-clipboard-api/
navigator.clipboard.write([
new window.ClipboardItem({
["web URL"]: "data:text/vnd.tiddler," + encodeURIComponent(JSON.stringify(data)),
}),
]);
*/
function listener(e) {
e.clipboardData.setData("URL", "data:text/vnd.tiddler," + encodeURIComponent(JSON.stringify(data)));
e.preventDefault();
}
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
})();