Compare commits

...

2 Commits

Author SHA1 Message Date
Gregory Leeman ef4a02648e lazygit 1 month ago
Gregory Leeman 428c7652d4 lazygit 1 month ago
  1. 43
      image-saver/main.js
  2. 54
      workflowy-helper/main.js
  3. 26
      workflowy-helper/style.css
  4. 2
      workflowy-helper/~main.js

43
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);
// }
});

54
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) {
@ -176,6 +217,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 !== "") {

26
workflowy-helper/style.css

@ -402,12 +402,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;

2
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");

Loading…
Cancel
Save