abcabc 发表于 2021-6-13 16:01:22

Mudlet无插件看图功能

Mudlet 4.10.1 (Deepin 20.1 Linux),没有可用插件,只能自己解决,还好很容易实现,困扰好几个月的切换浏览器打开看图的问题,终于解决。

下面贴出代码。
function hidepiclabel(current_pic_labelName, evt)
if evt == nil or evt.button == "RightButton" then
    local ln = current_pic_labelName and current_pic_labelName or getProfileName()
    hideWindow(ln)
end
end

function showpic(_, filename)

if string.ends(filename, ".html") then
    -- read the contents of the webpage in
    local f, s, webpage = io.open(filename)
    if f then webpage = f:read("*a"); io.close(f) end
    -- delete the file on disk, don't clutter
    os.remove(filename)
   
    -- parse our downloaded file for the player count
    -- src="./b2evo_captcha_tmp/b2evo_captcha_CBC7910861405F533B8858798683C6B2.jpg"
    local imgUrl = "http://fullme.pkuxkx.net/".. webpage:match([+)"]])
    current_pic_filepath = getMudletHomeDir().."/codepic/"..current_html_labelName..".jpg"
    downloadFile(current_pic_filepath, imgUrl)
   
else
    createLabel(current_html_labelName, codepic.x, codepic.y, codepic.w, codepic.h, 1)
    showWindow(current_html_labelName)
   
    setBackgroundImage(current_html_labelName, current_pic_filepath)
   
    setLabelDoubleClickCallback(current_html_labelName, "downloadpic", codepic.html, current_html_labelName)
   
    setLabelClickCallback(current_html_labelName, "hidepiclabel", current_html_labelName)
      
    cecho("\n<yellow>双击刷新图片,右键单击隐藏图片!!!")
end

end

-- 调用入口
function downloadpic(htmlUrl, labelName)
if not io.exists(getMudletHomeDir().."/codepic/") then
    os.execute("mkdir -p "..getMudletHomeDir().."/codepic/")
end
local ln = labelName or getProfileName()
--debugc("<yellow>当前labelname.."..ln)
codepic.html = htmlUrl
current_html_url = htmlUrl
current_html_labelName = ln
current_html_filepath = getMudletHomeDir().."/codepic/"..ln..".html"
--debugc("<yellow>图片下载路径1"..current_html_filepath)
downloadFile(current_html_filepath, htmlUrl)
end


function showpicfail(evt, errorFound)
cecho("\n<red>下载图片失败,尝试用浏览器打开!")
openUrl(current_html_url)
end


registerAnonymousEventHandler("sysDownloadDone", "showpic")
--registerAnonymousEventHandler("sysDownloadError", "showpicfail")

预定义的变量:
codepic = {
fullme_xkx = {x = 1000, y = 500, w = 900, h = 110, html = ""},
xkx = {x = 400, y = 350, w = 1500, h = 110, html = ""}
}

abcabc 发表于 2021-6-13 16:13:27

论坛搞截图好麻烦,附件是演示截图。

abcabc 发表于 2021-6-13 16:17:49

上一个是fullme图片,这个是其他图片码
页: [1]
查看完整版本: Mudlet无插件看图功能