diff --git a/image-saver/main.js b/image-saver/main.js index f91a64d..21e71d7 100644 --- a/image-saver/main.js +++ b/image-saver/main.js @@ -27,13 +27,54 @@ function saveImageFromUrl(info, tab) { }); } +function saveXFromUrl(info, tab) { + const url = info.srcUrl; + const data = new URLSearchParams({ + url: url + }); + + fetch("https://x.gregoryleeman.com/upload-url", { + method: "POST", + body: data, + headers: { + "Content-Type": "application/x-www-form-urlencoded" + } + }) + .then(response => { + if (!response.ok) { + console.error("Server responded with a non-OK status."); + return response.text().then(text => { + console.error("Server response:", text); + throw new Error("Server error"); + }); + } else { + console.log("X successfully uploaded."); + } + }) + .catch(error => { + console.error('Fetch error:', error.message); + }); +} + + chrome.contextMenus.create({ id: "save-image", title: "Save Image", contexts: ["image"] }); +// chrome.contextMenus.create({ +// id: "save-x", +// title: "Save X", +// contexts: ["image"] +// }); chrome.contextMenus.onClicked.addListener(function(info, tab) { - saveImageFromUrl(info, tab); + saveImageFromUrl(info, tab); + // if (info.menuItemId === "save-image") { + // saveImageFromUrl(info, tab); + // } else if (info.menuItemId === "save-x") { + // saveXFromUrl(info, tab); + // } }); + diff --git a/workflowy-helper/main.js b/workflowy-helper/main.js index 938ae61..636e76e 100644 --- a/workflowy-helper/main.js +++ b/workflowy-helper/main.js @@ -126,6 +126,47 @@ // }}} + function createImages(node, imgSrcs) { // {{{ + var inject = node.querySelector('.inject'); + if (inject === null) { + var inject = document.createElement("div"); + inject.className = 'inject'; + node.appendChild(inject); + } + var imgs = inject.querySelectorAll('img'); + if (imgs.length != imgSrcs.length) { + inject.innerHTML = ''; + imgSrcs.forEach(imgSrc => { + var img = document.createElement("img"); + img.src = imgSrc; + img.style.display = "none"; + + img.onload = function () { + const maxDimension = 100; + const aspectRatio = img.naturalWidth / img.naturalHeight; + + if (aspectRatio > 1) { + img.style.width = `${maxDimension}px`; + img.style.height = `${maxDimension / aspectRatio}px`; + } else { + img.style.height = `${maxDimension}px`; + img.style.width = `${maxDimension * aspectRatio}px`; + } + img.style.display = "block"; + }; + + img.onclick = function () { + // open link in new tab + window.open(imgSrc, '_blank'); + }; + + inject.appendChild(img); + }); + } + } + + // }}} + // }}} function updateProject(projectNode) { @@ -181,6 +222,19 @@ }); } const tags = n.querySelectorAll('.contentTag'); + if (text.startsWith("!")) { + const links = n.querySelectorAll('a.contentLink'); + const imgSrcs = []; + for (var i = 0; i < links.length; i++) { + var link = links[i]; + link.textContent = "link"; + var imgSrc = link.href; + imgSrcs.push(imgSrc); + } + if (imgSrcs.length > 0) { + createImages(n, imgSrcs); + } + } tags.forEach(tag => { var tagText = safeGetContent(tag, ".contentTagText").trim(); if (tagText !== "") { diff --git a/workflowy-helper/style.css b/workflowy-helper/style.css index 431b7b1..cdd36d0 100644 --- a/workflowy-helper/style.css +++ b/workflowy-helper/style.css @@ -397,12 +397,32 @@ body::-webkit-scrollbar { color: var(--violet) !important; } -.timed-late > .name, -.timed-late > .notes, -.timed-late > .children > .project:not(.timed) { +.timed-late:not(.tagged-TASK) > .name, +.timed-late:not(.tagged-TASK) > .notes, +.timed-late:not(.tagged-TASK) > .children > .project:not(.timed) { opacity: .5 !important; } +.inject { + display: flex; + gap: 5px; + flex-wrap: wrap; +} + +.inject > img { + border-radius: 4px; + border: 1px solid var(--dark-grey); + cursor: pointer; +} + +.inject > img:hover { + border-color: var(--white); +} + +.root > .inject { + margin-left: 0; +} + .hotspot-admin > .name .innerContentContainer::after { content: "✏️"; margin-left: 4px; diff --git a/workflowy-helper/~main.js b/workflowy-helper/~main.js index 6c8470b..2866052 100644 --- a/workflowy-helper/~main.js +++ b/workflowy-helper/~main.js @@ -86,7 +86,7 @@ // }}} - function createImages(node, imgSrcs) { // {{{ + function createImages(node, imgSrcs) { // {{{ var inject = node.querySelector('.inject'); if (inject === null) { var inject = document.createElement("div");