require "import"
import "android.widget.*"
import "android.net.Uri"
import "android.content.Intent"
local text=service.getText(node)
local ret={}
local t1={"qq加好友/群","微信加好友","添加公众号"}
local t2={
{{">qq",
"?%返回&表情$50",
"快捷入口>50$50",
"加好友/群>50$500",
"搜索*$500",
"%粘贴",
"网络查找*>5","添加*>5"}},{{">微信",
"?%返回&表情$50","[更多功能]>50$50",
"添加朋友>50$50",
"com.tencent.mm:id/mes",
"%粘贴",
"[搜索*]"}},
{{">微信",
"?%返回&!通讯录$50",
"更多功能按钮>50$50",
"添加朋友>50$50",
"[公众号*]$500",
"%粘贴",
"[搜索]"}}}
function append(t,v)
if not table.find(t,v) then
table.insert(t,v)
end
end

for n in text:gmatch("%d%d%d%d%d+") do
  table.insert(ret,n)
end
for url in text:gmatch("https?://[%w%%%=#/%?%._%-%+&]+") do
append(ret,url)
  end
for url in text:gmatch("[%w%._%-:/]+%.cn[%w%%%=#/%?%._%-%+&]*") do
  append(ret,url)
  end
for url in text:gmatch("[%w%._%-:/]+%.com[%w%%%=#/%?%._%-%+&]*") do
  append(ret,url)
  end
for url in text:gmatch("[%w%._%-:/]+%.org[%w%%%=#/%?%._%-%+&]*") do
  append(ret,url)
  end
for url in text:gmatch("[%w%._%-:/]+%.net[%w%%%=#/%?%._%-%+&]*") do
  append(ret,url)
  end

if #ret==0 then
edit=loadlayout({EditText;hint="网址无需输入 http://"})
LuaDialog()
.setTitle("请输入网址或号码")
.setView(edit)
.setButton("浏览器打开",{onClick=function()service.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse("http://"..edit.text)).setFlags(0x10000000))end})
.setButton3("拨打电话",function()
service.callPhone(edit.text)
end)
.setButton2("添加好友或公众号",function()
service.copy(edit.text)
local dlg=LuaDialog()
.setItems(t1)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.click(t2[i])
end
end)
.show()
  return true
end
dlg=LuaDialog(service)
dlg.setTitle(string.format("共%d条",#ret))
dlg.setItems(String(ret))
dlg.setButton("点击链接",function()
service.execute("链接",node)
end)
dlg.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
if v.text:find("http")
service.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse(v.text)).setFlags(0x10000000))
return true
elseif v.text:find("%d%d%d%d%d")
service.callPhone(v.text)
else
return service.execute("链接",node)
end
end
dlg.onItemLongClick=function(l,v,p,i)
dlg.dismiss()
service.copy(v.text)
local dlg=LuaDialog()
.setItems(t1)
.show()
dlg.onItemClick=function(l,v,p,i)
dlg.dismiss()
service.click(t2[i])
end
end
return true