I was trying to set up a tampermonkey script that allowed me to drag and drop quotes from GoodReads straight to my TiddlyWiki.
I wrote this this (incomplete) js snippet to test.
quotes = Array.from(document.getElementsByClassName('quote'));
quotes.forEach((quote) => {
const data = {
created:20230112194959769,
tags: "Quotes",
author: quote.querySelector(".authorOrTitle"),
modified:20230112211530897,
title: "Quote",
source: ""
};
var a = quote.querySelector(".action");
const p = document.createElement("div");
p.setAttribute('draggable', true);
p.addEventListener('dragstart', (event) => {
event.dataTransfer.setData('application/json', data);
});
var text = document.createTextNode("Drag to TW");
p.appendChild(text);
a.appendChild(p);
})
As far as I can tell, TW just eats it and nothing happens.
If I change the event listener to:
p.addEventListener('dragstart', (event) => {
event.dataTransfer.setData('text/plain', JSON.stringify(data));
});
TW does see the import but treats it as plain text.
I don’t see any docs for the import system, so if anyone knows how to get this to work that would be great.