Skip to content

Instantly share code, notes, and snippets.

@asonas
Created December 20, 2023 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asonas/637bca0eef29bf8a155e4eeb6451884b to your computer and use it in GitHub Desktop.
Save asonas/637bca0eef29bf8a155e4eeb6451884b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Docbase to Things.app Improved with <a> Tag
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add Docbase memo to Things.app ToDo using an <a> tag for delayed content
// @author YourName
// @match https://*.docbase.io/posts/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function handleMutation(mutations, observer) {
for (let mutation of mutations) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
var titleElement = document.querySelector('h2');
if (titleElement) {
var title = titleElement.innerText;
var url = window.location.href;
var link = document.createElement('a');
link.href = `things:///add?title=${encodeURIComponent(title)}&notes=${encodeURIComponent(url)}&when=today&tags=read-later`;
link.style.backgroundColor = '#2473E7';
link.style.color = 'white';
link.style.fontWeight = 'bold';
link.style.border = '1px solid rgba(31, 35, 40, 0.15)';
link.style.padding = '3px 5px';
link.style.borderRadius = '3px';
link.style.cursor = 'pointer';
link.style.fontSize = '10px';
link.style.textDecoration = 'none';
link.textContent = 'Add to Things';
document.querySelector('._labels__Root-sc-ekok4y-0.fFcpBV').appendChild(link);
observer.disconnect();
break;
}
}
}
}
var observer = new MutationObserver(handleMutation);
var config = { childList: true, subtree: true };
observer.observe(document.body, config);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment