From 09d423965adc5ee5f98425139f01052a6783c68d Mon Sep 17 00:00:00 2001 From: yunxiang wei <121092793+yiwangsimple@users.noreply.github.com> Date: Wed, 14 Aug 2024 03:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=A3=9E=E6=9C=BA?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E7=9A=84=E6=98=BE=E7=A4=BA=E6=88=96=E8=80=85?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E7=9A=84=E6=8E=A7=E5=88=B6=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/github_link_node.js | 65 ++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/web/github_link_node.js b/web/github_link_node.js index c0f300c..4b5b33e 100644 --- a/web/github_link_node.js +++ b/web/github_link_node.js @@ -14,26 +14,29 @@ const drawPaperPlaneIcon = function(node, orig, restArgs) { const r = orig?.apply?.(node, restArgs); if (!node.flags.collapsed && node.constructor.title_mode != LiteGraph.NO_TITLE) { - // Draw paper plane icon - const paperPlaneIcon = '✈️'; - let fgColor = "white"; + // Check if the paper plane icon should be displayed + if (app.ui.settings.getSettingValue("Leo.NodeGithubLink.ShowIcon", true)) { + // Draw paper plane icon + const paperPlaneIcon = '✈️'; + let fgColor = "white"; - ctx.save(); - ctx.font = "16px sans-serif"; - const sz = ctx.measureText(paperPlaneIcon); - ctx.beginPath(); - ctx.fillStyle = fgColor; - const x = 4; // Left position - const y = -34; // Top position - ctx.fillText(paperPlaneIcon, x, y); - ctx.restore(); + ctx.save(); + ctx.font = "16px sans-serif"; + const sz = ctx.measureText(paperPlaneIcon); + ctx.beginPath(); + ctx.fillStyle = fgColor; + const x = 4; // Left position + const y = -34; // Top position + ctx.fillText(paperPlaneIcon, x, y); + ctx.restore(); - const boundary = node.getBounding(); - const [ x1, y1, width, height ] = boundary - cacheNodePositonMap.set(node.id, { - x: [x1 + x, x1 + x + sz.width], - y: [y1 , y1 + 18] - }) + const boundary = node.getBounding(); + const [ x1, y1, width, height ] = boundary + cacheNodePositonMap.set(node.id, { + x: [x1 + x, x1 + x + sz.width], + y: [y1 , y1 + 18] + }) + } if (node.has_errors) { ctx.save(); @@ -112,8 +115,8 @@ LGraphCanvas.prototype.processMouseDown = function(e) { if(canvasX >= iconX && canvasX <= iconX1 && canvasY >= iconY && canvasY <= iconY1) { isClickPaperPlane = true - openNodeGithubLink(node); // 阻止默认行为 - e.stopPropagation(); // 阻止事件冒泡 + openNodeGithubLink(node); + e.stopPropagation(); break } } @@ -142,6 +145,18 @@ app.registerExtension({ console.log(`URL: ${url}`); console.log('---'); }); + + // Add setting for showing/hiding the paper plane icon + app.ui.settings.addSetting({ + id: "Leo.NodeGithubLink.ShowIcon", + name: "Show GitHub Link Icon", + type: "boolean", + defaultValue: true, + onChange: (value) => { + // Trigger a redraw of all nodes when the setting changes + app.graph.setDirtyCanvas(true, true); + } + }); } catch (error) { console.error('Error loading GitHub links:', error); } @@ -167,10 +182,12 @@ app.registerExtension({ const iconX1 = nLeft + 24 const iconY1 = nTop - 12 if(canvasX >= iconX && canvasX <= iconX1 && canvasY >= iconY && canvasY <= iconY1) { - openNodeGithubLink(node); - e.preventDefault() - e.stopPropagation() - return false + if (app.ui.settings.getSettingValue("Leo.NodeGithubLink.ShowIcon", true)) { + openNodeGithubLink(node); + e.preventDefault() + e.stopPropagation() + return false + } } } }