From 074a86564c8d81dc802c0fcea0af02f5b8ed49ad Mon Sep 17 00:00:00 2001 From: Sergey Svistunov Date: Wed, 27 Mar 2024 15:36:58 +0300 Subject: [PATCH] Fastpic.org view full image, imagebam.com direct link #77 Add CNode and CSelection's attribute function to scripting API (there was a mistake in docs) --- Data/Scripts/fastpic.nut | 19 ++++++++++++++++--- Data/Scripts/imagebam.com.nut | 14 +++++++++++++- .../API/GumboBingings/GumboDocument.cpp | 4 +++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Data/Scripts/fastpic.nut b/Data/Scripts/fastpic.nut index f71a811ff..4fefdfbdd 100644 --- a/Data/Scripts/fastpic.nut +++ b/Data/Scripts/fastpic.nut @@ -1,3 +1,15 @@ +function _RegReplace(str, pattern, replace_with) { + local resultStr = str; + local res; + local start = 0; + + while( (res = resultStr.find(pattern,start)) != null ) { + resultStr = resultStr.slice(0,res) +replace_with+ resultStr.slice(res + pattern.len()); + start = res + replace_with.len(); + } + return resultStr; +} + function UploadFile(FileName, options) { nm.setUrl("https://fastpic.org/upload?api=1"); //nm.addQueryHeader("User-Agent","FPUploader"); @@ -20,11 +32,12 @@ function UploadFile(FileName, options) { if(statusNode.Text()=="ok"){ local imgUrlNode = root.GetChild("imagepath", false); local thumbUrlNode = root.GetChild("thumbpath", false); - local viewUrl = root.GetChild("viewurl", false); - + local viewUrl = root.GetChild("viewfullurl", false); options.setDirectUrl(imgUrlNode.Text()); options.setThumbUrl(thumbUrlNode.Text()); - options.setViewUrl(viewUrl.Text()); + local viewUrlStr = viewUrl.Text(); + viewUrlStr = _RegReplace(viewUrlStr, "fastpic.org/view/", "fastpic.org/fullview/"); + options.setViewUrl(viewUrlStr); return 1; } else { local errorNode = root.GetChild("error", false); diff --git a/Data/Scripts/imagebam.com.nut b/Data/Scripts/imagebam.com.nut index e83f041f2..a614a7054 100644 --- a/Data/Scripts/imagebam.com.nut +++ b/Data/Scripts/imagebam.com.nut @@ -78,7 +78,19 @@ function UploadFile(FileName, options) { local reg = CRegExp(BASE_URL + "view/([A-Za-z0-9]+)", "mi"); if (reg.match(nm.responseBody()) ) { - options.setViewUrl(reg.getMatch(0)); + local viewUrl = reg.getMatch(0); + if (viewUrl != "") { + options.setViewUrl(viewUrl); + nm.doGet(viewUrl); + if (nm.responseCode() == 200) { + doc = Document(nm.responseBody()); + node = doc.find(".main-image"); + if (node != null) { + options.setDirectUrl(node.attr("src")); + } + } + } + local reg2 = CRegExp("\\[IMG\\](.+?)\\[/IMG\\]", "mi"); if (reg2.match(nm.responseBody())) { options.setThumbUrl(reg2.getMatch(1)); diff --git a/Source/Core/Scripting/API/GumboBingings/GumboDocument.cpp b/Source/Core/Scripting/API/GumboBingings/GumboDocument.cpp index 394049237..28393ce2a 100644 --- a/Source/Core/Scripting/API/GumboBingings/GumboDocument.cpp +++ b/Source/Core/Scripting/API/GumboBingings/GumboDocument.cpp @@ -32,6 +32,7 @@ void RegisterGumboClasses(Sqrat::SqratVM& vm) { .Func("tagName", &CSelection::tagName) .Func("each", &CSelection::squirrelEach) .Func("attr", &CSelection::attribute) + .Func("attribute", &CSelection::attribute) ); root.Bind("Node", Class(vm.GetVM(), "Node") @@ -42,10 +43,11 @@ void RegisterGumboClasses(Sqrat::SqratVM& vm) { .Func("childAt", &CNode::childAt) .Func("childCount", &CNode::childNum) .Func("attr", &CNode::attribute) + .Func("attribute", &CNode::attribute) .Func("text", &CNode::text) .Func("ownText", &CNode::ownText) .Func("tagName", &CNode::tag) .Func("find", &CNode::find) ); } -} \ No newline at end of file +}