Created
December 20, 2023 02:23
-
-
Save asonas/637bca0eef29bf8a155e4eeb6451884b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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)}¬es=${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