add community scripts

This commit is contained in:
Evgeny
2021-08-07 11:05:27 +03:00
parent b5671558d0
commit e1b96c4029
5 changed files with 100 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ First line<br/>Second line
* `system:copy_to_clipboard(string)` - копирует строку в буфер обмена;
* `system:get_from_clipboard()` - возвращает строку из буфера обмена:
* `system:share_text(string)` - открывает системный диалог "Поделиться";
* `system:get_lang()` - возвращает выбранный в системе язык;
Результат выполнения shell-команды приходит в колбек `on_shell_result(string)`.

View File

@@ -0,0 +1,36 @@
-- name = "Google Translate"
-- data_source = "https://translate.google.com"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.0"
local json = require "json"
local text_from = ""
local text_color = ui:get_secondary_text_color()
function on_alarm()
ui:show_text("<font color=\""..text_color.."\">Tap to enter text</font>")
end
function on_click()
ui:show_edit_dialog("Введите текст")
end
function on_dialog_action(text)
if text == "" then
on_alarm()
else
text_from = text
translate(text)
end
end
function translate(str)
http:get("http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto".."&tl="..system:get_lang().."&dt=t&q="..str)
end
function on_network_result(result)
local t = json.decode(result)
local text_to = t[1][1][1]
ui:show_lines({text_from}, {text_to})
end

View File

@@ -0,0 +1,57 @@
-- name = "Chuck Norris translated"
-- description = "Jokes with translation"
-- data_source = "icndb.com"
-- type = "widget"
-- author = "Alexander Ivanitsa (griva99@gmail.com)"
-- version = "1.0"
local joke = ""
local txt = ""
function urlencode(str)
if (str) then
str = string.gsub(str, "\n", "\r\n")
str = string.gsub(str, "([^%w _ %- . ~])", function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub(str, " ", "+")
end
return str
end
function urldecode(str)
str = string.gsub(str, "+", " ")
str = string.gsub(str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
return str
end
function on_alarm()
http:get("http://api.icndb.com/jokes/random")
end
function on_network_result(result)
local first_letter = string.sub(result, 1, 1)
local textColor = ui:get_secondary_text_color()
joke = ajson:get_value(result, "object object:value string:joke")
local id = ajson:get_value(result, "object object:value string:id")
txt = "<font color=\""..textColor.."\">"..tostring(id)..":</font> "..joke
ui:show_text(txt)
end
-- translate --
function on_click(idx)
local lang = system:get_lang()
local link_href="http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl="..lang.."&dt=t&q="
http:get(link_href..urlencode(joke), "translate")
end
function on_network_result_translate(result)
local js = require "json"
local tt= ""
local elem = js.decode(result)[1]
for k,v in pairs(elem) do
if type(v[1]) == "string" then
tt = tt..v[1]
end
end
ui:show_lines({txt,"---",tt})
end

3
samples/bad-script5.lua Normal file
View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_aaa()
end

3
samples/lang-sample.lua Normal file
View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_text("Phone language: "..system:get_lang())
end