Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
christinna9031 committed Feb 2, 2021
1 parent 5e81ad6 commit 69ba856
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# LB Web Request
Simple Web Request extension for LioranBoard.
Simple Web Request extension for LioranBoard.
140 changes: 140 additions & 0 deletions web request.lbe
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[extension_name]
Web Request
[insert_external]
<div><p>Web request is installed. </p></div>
<!--
* @name:Web Request, @version: 1.0, @author: Christinna#9031
* -->
[insert_command]
lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"Web Request","boxcount":5,"boxname1":"variable","boxtype1":"string","boxname2":"save_in_variable|yes|no|","boxtype2":"string","boxname3":"method|GET|POST|PUT|DELETE|","boxtype3":"string","boxname4":"proxy|yes|no|","boxtype4":"string","boxname5":"url","boxtype5":"string"}');
[insert_hook]
case "WebRequest":{
LBWebRequest(LioranBoardJSON.variable,LioranBoardJSON.url,LioranBoardJSON.save_in_variable,LioranBoardJSON.method,LioranBoardJSON.proxy)
}break
[insert_script]
async function LBWebRequest(variable,url,save,method,proxy){

async function fetchURL (){
if (proxy=="yes"){
url="https://cors-anywhere.herokuapp.com/"+url
}
const response = await fetch (url, {
"method": method,
'Accept': 'application/json'
}
)

let content = await response.text()
if (!response.ok){
try {
content = JSON.parse(content)}
catch (e){}
let error = content.message || content.error || "Something went wrong."
throw new Error(error)
} else {
try {
content = JSON.parse(content)}
catch (e){}
}
return content;
}

await fetchURL ()
.then (data => {
lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request successful!"}')
if (save=="yes"){
lioranboardclient.send('{"type":"MESSAGE","topic":"SetValue","valuename":"' + variable + '","value":"' + ReplaceSymbols(data) + '","real":false}')}})
.catch (e =>{
lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request failed! '+ReplaceSymbols(e)+'"}')})

function ReplaceSymbols(tw) {
tw = JSON.stringify(tw)
tw = tw.replace(/(?:\r\n|\r|\n)/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
tw = tw.replace(/"/g, "'").replace(/\//g, '/').replace(/\\/g, "\\\\")
return tw
}}
[insert_over]
[buttons_0x0]
activepress="0.000000"
border_size="0.000000"
combine="0.000000"
type="websocketaction+"
picture=""
text="web request"
color="12632256.000000"
button_id="4445.000000"
websocketdelay6="0.000000"
websocketvalue8_6=""
websocketvalue7_6=""
websocketvalue6_6=""
websocketvalue5_6=""
websocketvalue4_6=""
websocketvalue3_6=""
websocketvalue2_6=""
websocketvalue1_6="/$latest_news$/"
websocketaction6="36.000000"
websocketdelay5="0.000000"
websocketvalue8_5=""
websocketvalue7_5=""
websocketvalue6_5="https://decapi.me/twitter/latest/nytimes"
websocketvalue5_5="no"
websocketvalue4_5="GET"
websocketvalue3_5="yes"
websocketvalue2_5="latest_news"
websocketvalue1_5="Web Request"
websocketaction5="71.000000"
websocketdelay4="0.000000"
websocketvalue8_4=""
websocketvalue7_4=""
websocketvalue6_4=""
websocketvalue5_4=""
websocketvalue4_4=""
websocketvalue3_4=""
websocketvalue2_4=""
websocketvalue1_4="The extension doesn't support cutom headers or passing parameters (except for query string)"
websocketaction4="92.000000"
websocketdelay3="0.000000"
websocketvalue8_3=""
websocketvalue7_3=""
websocketvalue6_3=""
websocketvalue5_3=""
websocketvalue4_3=""
websocketvalue3_3=""
websocketvalue2_3=""
websocketvalue1_3="you can check for CORS errors by opening Transmitter in your browser and pressing F12 to see the log"
websocketaction3="92.000000"
websocketdelay2="0.000000"
websocketvalue8_2=""
websocketvalue7_2=""
websocketvalue6_2=""
websocketvalue5_2=""
websocketvalue4_2=""
websocketvalue3_2=""
websocketvalue2_2=""
websocketvalue1_2="Use proxy if your requests are failing due to CORS errors"
websocketaction2="92.000000"
websocketdelay1="0.000000"
websocketvalue8_1=""
websocketvalue7_1=""
websocketvalue6_1=""
websocketvalue5_1=""
websocketvalue4_1=""
websocketvalue3_1=""
websocketvalue2_1=""
websocketvalue1_1="Decide whether you want to save the response in a variable or not "
websocketaction1="92.000000"
websocketdelay0="0.000000"
websocketvalue8_0=""
websocketvalue7_0=""
websocketvalue6_0=""
websocketvalue5_0=""
websocketvalue4_0=""
websocketvalue3_0=""
websocketvalue2_0=""
websocketvalue1_0="Make a simple web request. Choose a method (GET is most likely what you want) "
websocketaction0="92.000000"
[configs]
name="Web Request Example"
background_color="8947848.000000"
grid_height="2.000000"
grid_width="2.000000"

0 comments on commit 69ba856

Please sign in to comment.