Kawiesh

Random apis

Sep 26th, 2021 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----fetch memes
  2. fetch("https://api.imgflip.com/get_memes")
  3. .then(response=> response.json())
  4. .then(data=>{
  5. let array= data.data.memes;
  6. let meme= array[Math.floor(Math.random() * array.length)];
  7. let url= meme.url;
  8. let title= meme.name;
  9. let width= meme.width;
  10. let height= meme.height;
  11. let code= `<div id="meme">
  12. <h5>${title}</h5>
  13. <img src="${url}" style= "width:${width}px; height:${height}px"/>
  14. </div>`;
  15.  
  16. select("pre").outerHTML="";
  17. select("pre").outerHTML= code;
  18. });
  19.  
  20.  
  21. //IP----
  22.  
  23. let url1= "https://api.ip2country.info/ip?",
  24. url2= "https://api.ipify.org?format=json";
  25.  
  26. let lol="";
  27.  
  28. fetch(url2)
  29. .then(response=> response.json())
  30. .then(data=> {
  31. lol= data.ip;
  32. return fetch(url1 + data.ip);
  33. })
  34. .then(response=> response.json())
  35. .then(data=> alert(data.countryName +":"+ lol ))
  36.  
  37.  
  38. //----jokes
  39.  
  40. fetch("https://v2.jokeapi.dev/joke/Any")
  41. .then(response=>response.json())
  42. .then(data=>{
  43. let joke= data.joke,
  44. joke1= data.setup,
  45. joke2= data.delivery;
  46. if(joke){
  47. alert(joke);
  48. }
  49. else{
  50. alert(joke1+"\n"+joke2);
  51. }
  52. })
  53.  
  54.  
  55.  
  56. //----dictionary
  57.  
  58.  
  59. let url= "https://api.dictionaryapi.dev/api/v2/entries/en/",
  60. word= "HOME";
  61.  
  62. fetch(url+word)
  63. .then(r=> r.json())
  64. .then(d=> {
  65. if(d.title){
  66. alert("Not found");
  67. }
  68. else{
  69. let xx= d[0].meanings[0].definitions[0].definition;
  70. let yy= d[0].meanings[1].partOfSpeech;
  71. alert(`${d[0].word} [${yy}]: ${xx}`);
  72. }
  73.  
  74. })
  75. .catch(x=> alert(x));
  76.  
  77.  
  78.  
  79. //--Always cors
  80.  
  81. let create= (x)=> document.createElement(x),
  82. select= (x,y=document)=> y.querySelector(x),
  83. selectAll= (x,y=document)=> y.querySelectorAll(x);
  84.  
  85. let url= "https://random-d.uk/api/v2/random";
  86. let proxy= "https://cors.bridged.cc/";
  87.  
  88.  
  89. fetch(url)
  90.  .then(r=> r.json())
  91.  .then(d=> {alert(JSON.stringify(d))})
  92. .catch(x=> fetch(proxy+url))
  93.  .then(r=> r.json())
  94.  .then(d=> {img(d.url)})
  95. .catch(x=> alert(x))
  96.  
  97.  
  98. function img(src){
  99. if(select("#img")) select("#img").remove();
  100. let a= create("img");
  101. a.id="img";
  102. //a.style.cssText=`width:500%; height: 350px`;
  103. a.src= src;
  104. document.body.append(a);
  105. }
  106.  
  107.  
  108. //html parse-----
  109.  
  110. let create= (x)=> document.createElement(x),
  111. select= (x,y=document)=> y.querySelector(x),
  112. selectAll= (x,y=document)=> y.querySelectorAll(x);
  113.  
  114. let url= "https://api.jokes.one";
  115. let url1= "https://krishan.ml/notepad";
  116. let proxy= "https://cors.bridged.cc/";
  117.  
  118.  
  119. fetch(url1)
  120.  .then(r=> r.text())
  121.  .then(d=> {
  122.  
  123. var parser = new DOMParser();
  124. var doc = parser.parseFromString(d, 'text/html');
  125. alert(doc.querySelector("button").outerHTML);
  126.  
  127. })
  128.  
  129.  
  130. //-----sn
  131.  
  132. let create= (x)=> document.createElement(x),
  133. select= (x,y=document)=> y.querySelector(x),
  134. selectAll= (x,y=document)=> y.querySelectorAll(x);
  135.  
  136. let url= "https://m.starnieuws.com";
  137. let proxy= "https://cors.bridged.cc/";
  138.  
  139.  
  140. fetch(proxy+url)
  141. .then(r=> r.text())
  142. .then(d=> {
  143. let a= new DOMParser();
  144. let b= a.parseFromString(d, 'text/html');
  145. sn(b);
  146. })
  147. .catch(x=> alert(x))
  148.  
  149. function sn(xo){
  150. let ul= select("ul",xo);
  151. let bx= selectAll("a",ul);
  152.  
  153. bx.forEach(i=>{
  154. let a= create("a");
  155. /*a.href= i.href;
  156. a.text= i.text;
  157. document.body.append(a);*/ document.body.append(i)
  158. });
  159. }
  160.  
  161.  
  162. //---SN Latest Item
  163.  
  164. let create= (x)=> document.createElement(x),
  165. select= (x,y=document)=> y.querySelector(x),
  166. selectAll= (x,y=document)=> y.querySelectorAll(x);
  167.  
  168. let urlz= "https://m.starnieuws.com";
  169. let proxy= "https://cors.bridged.cc/"
  170.  
  171.  
  172. fetch(proxy+urlz)
  173. .then(r=> r.text())
  174. .then(d=> {
  175. let a= new DOMParser().parseFromString(d,"text/html");
  176. let b= select("ul a",a);
  177. fetch(proxy+b.href)
  178. .then(r=> r.text())
  179. .then(d=> {
  180. let c= new DOMParser().parseFromString(d,"text/html");
  181. let x= window.open();
  182. let y= select("div[style='font-size: 25px']",c);
  183. x.document.write(y.innerHTML);
  184. })
  185. })
  186. .catch(x=> console.log(x))
  187.  
  188. //--------urban dictionary
  189. fetch("https://api.urbandictionary.com/v0/define?term=lol")
  190. .then(r=>r.json())
  191. .then(d=>alert(d.list[0].definition))
  192. .catch(x=>alert(x))
  193.  
  194.  
  195. //----kovid19
  196.  
  197. <div data-counter-value="8">8</div>
  198. <div>Overleden</div>
  199.  
  200. <div data-counter-value="366">366</div>
  201. <div>Nieuwe gevallen vandaag</div>
  202. //---------
  203. let create= (x)=> document.createElement(x),
  204. select= (x,y=document)=> y.querySelector(x),
  205. selectAll= (x,y=document)=> y.querySelectorAll(x);
  206.  
  207. let nieuw= "//div[text()='Nieuwe gevallen vandaag']";
  208. let overl= "//div[text()='Overleden']";
  209.  
  210. let Nieuw= document.evaluate(nieuw, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  211.  
  212. let Overl= document.evaluate(overl, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  213.  
  214.  
  215. nieuwNum= Nieuw.previousElementSibling.innerHTML;
  216. overlNum= Overl.previousElementSibling.innerHTML;
  217.  
  218. let message= `Overleden: ${overlNum}
  219. Nieuwe gevallen: ${nieuwNum}`;
  220.  
  221. alert(message);
  222.  
  223. //-------Covid19
  224. let create= (x)=> document.createElement(x),
  225. select= (x,y=document)=> y.querySelector(x),
  226. selectAll= (x,y=document)=> y.querySelectorAll(x);
  227.  
  228. fetch("https://cors.bridged.cc/https://covid-19.sr")
  229. .then(r=> r.text())
  230. .then(d=> {
  231. let a= new DOMParser().parseFromString(d,"text/html");
  232.  
  233. let Overl, Nieuw;
  234. selectAll("div",a).forEach(i=>{
  235. if(i.textContent== "Overleden") Overl= i;
  236. if(i.textContent== "Nieuwe gevallen vandaag") Nieuw= i;
  237. });
  238.  
  239.  
  240. let nieuwNum= Nieuw.previousElementSibling.dataset.counterValue;
  241. let overlNum= Overl.previousElementSibling.dataset.counterValue;
  242.  
  243. let message= `Overleden: ${overlNum}
  244. Nieuwe gevallen: ${nieuwNum}`;
  245. alert(message);
  246. })
  247. .catch(x=> alert(x))
  248.  
  249.  
  250. //---
  251. let y= localStorage.getItem("nieuwnum");
  252. let dat= localStorage.getItem("dat");
  253.  
  254. if(y!=nieuwNum) dat++;
  255. let message= `Overleden: ${overlNum}
  256. Nieuwe gevallen: ${nieuwNum}
  257. Datum: ${dat} oktober 2021`;
  258. alert(message);
  259. localStorage.setItem("nieuwnum", nieuwNum);
  260. localStorage.setItem("dat", dat);
  261. })
  262.  
  263.  
  264.  
  265. //---diktionary
  266.  
  267. function doit(x){
  268. let a= JSON.stringify(x);
  269. let word= x[0].word,
  270. phonetics= x[0].phonetic,
  271. origin= x[0].origin,
  272. audio= x[0].phonetics[0].audio;
  273.  
  274. let mom= x[0].meanings;
  275. let dad= mom[0].definitions;
  276. let pos= mom[0].partOfSpeech,
  277. example= dad[0].example,
  278. synonym= dad[0].synonyms,
  279. antonym= dad[0].antonyms;
  280.  
  281. alert(phonetics);
  282. }
  283.  
  284.  
  285. let options= {
  286.  
  287. };
  288.  
  289. let url="https://api.dictionaryapi.dev/api/v2/entries/en/home";
  290. let proxy= "https://cors.bridged.cc/";
  291.  
  292.  
  293.  
  294.  
  295. fetch(url,options)
  296. .then(r=> r.json())
  297. .then(d=> doit(d))/*
  298. .catch(x=> fetch(proxy+url,options))
  299. .then(r=> r.json())
  300. .then(d=> doit(d))
  301. .catch(x=> alert(x))*/
  302.  
  303.  
  304.  
  305.  
  306.  
  307. /*
  308.  
  309. "word":"hose",
  310. "phonetic":"həʊz",
  311. "phonetics":[
  312.     {"text":"həʊz",
  313.       "audio":"//ssl.gstatic.com/dictionary/static/sounds/20200429/hose--_gb_1.mp3"
  314.     }],
  315. "origin":"only to the ankle.",
  316. "meanings":[
  317.     {"partOfSpeech":"noun",
  318.      "definitions":[
  319.         {"definition":"a flexible tube ",
  320.          "example":"a sprinkler hose",
  321.          "synonyms": ["pipe","piping"],
  322.          "antonyms":[]
  323.         },
  324.         {"definition":"suse",
  325.          "example":"her hose had been laddered",
  326.          "synonyms":[],
  327.          "antonyms":[]
  328.         }
  329.         ]},
  330.  
  331.     {"partOfSpeech":"verb",
  332.      "definitions":[
  333.          {"definition":"water or spray with a hose.",
  334.           "example":"he was hosing down the driveway",
  335.           "synonyms":[],
  336.           "antonyms":[]
  337.           }]
  338.      }]
  339.  
  340. */
  341.  
  342.  
  343.  
  344.  
  345. //Dictionary
  346.  
  347.  
  348. [
  349.     {
  350.       "word": "hello",
  351.       "phonetics": [
  352.         {
  353.           "text": "/həˈloʊ/",
  354.           "audio": "https://lex-audio.useremarkable.com/mp3/hello_us_1_rr.mp3"
  355.         },
  356.         {
  357.           "text": "/hɛˈloʊ/",
  358.           "audio": "https://lex-audio.useremarkable.com/mp3/hello_us_2_rr.mp3"
  359.         }
  360.       ],
  361.       "meanings": [
  362.         {
  363.           "partOfSpeech": "exclamation",
  364.           "definitions": [
  365.             {
  366.               "definition": "Used as a greeting or to begin a phone conversation.",
  367.               "example": "hello there, Katie!"
  368.             }
  369.           ]
  370.         },
  371.         {
  372.           "partOfSpeech": "noun",
  373.           "definitions": [
  374.             {
  375.               "definition": "An utterance of “hello”; a greeting.",
  376.               "example": "she was getting polite nods and hellos from people",
  377.               "synonyms": [
  378.                 "greeting",
  379.                 "welcome",
  380.                 "salutation",
  381.                 "saluting",
  382.                 "hailing",
  383.                 "address",
  384.                 "hello",
  385.                 "hallo"
  386.               ]
  387.             }
  388.           ]
  389.         },
  390.         {
  391.           "partOfSpeech": "intransitive verb",
  392.           "definitions": [
  393.             {
  394.               "definition": "Say or shout “hello”; greet someone.",
  395.               "example": "I pressed the phone button and helloed"
  396.             }
  397.           ]
  398.         }
  399.       ]
  400.     }
  401.   ]
  402.  
  403.  
  404.  
  405.  
  406. //-------
  407.  
  408.  
  409. let word= data[0].word,
  410. phonetics= data[0].phonetics,
  411. meanings= data[0].meanings;
  412.  
  413.  
  414. //Phonetics
  415. let pron1= phonetics[0].text,
  416. audio1= phonetics[0].audio;
  417.  
  418. let pron2= phonetics[1].text,
  419. audio2= phonetics[1].audio;
  420.  
  421.  
  422. //Meanings
  423. let pos1= meanings[0].partOfSpeech;
  424. let definitions1= meanings[0].definitions;
  425. let def1= definitions1[0].definition;
  426. let ex1= definitions1[0].example;
  427.  
  428. let pos2= meanings[1].partOfSpeech;
  429. let definitions2= meanings[1].definitions;
  430. let def2= definitions1[1].definition;
  431. let ex2= definitions1[1].example;
  432. let syn= definitions1[1].synonyms; //array
  433.  
  434.  
  435. let pos3= meanings[2].partOfSpeech;
  436. let definitions3= meanings[2].definitions;
  437. let def3= definitions1[2].definition;
  438. let ex3= definitions1[2].example;
  439.  
  440.  
  441.  
  442. //-------------->>>>>>
  443.  
  444. function doit(x){
  445. let a= JSON.stringify(x);
  446. let word= x[0].word,
  447. phonetics= x[0].phonetic,
  448. origin= x[0].origin,
  449. audio= x[0].phonetics[0].audio;
  450.  
  451. let mom= x[0].meanings;
  452. let dad= mom[0].definitions;
  453. let pos= mom[0].partOfSpeech,
  454. example= dad[0].example,
  455. synonym= dad[0].synonyms,
  456. antonym= dad[0].antonyms;
  457.  
  458. alert(phonetics);
  459. }
  460.  
  461.  
  462. let options= {
  463.  
  464. };
  465.  
  466. let url="https://api.dictionaryapi.dev/api/v2/entries/en/home";
  467. let proxy= "https://cors.bridged.cc/";
  468.  
  469.  
  470.  
  471.  
  472. fetch(url,options)
  473. .then(r=> r.json())
  474. .then(d=> doit(d))/*
  475. .catch(x=> fetch(proxy+url,options))
  476. .then(r=> r.json())
  477. .then(d=> doit(d))
  478. .catch(x=> alert(x))*/
  479.  
  480.  
  481.  
  482.  
  483.  
  484. /*
  485.  
  486. "word":"hose",
  487. "phonetic":"həʊz",
  488. "phonetics":[
  489.     {"text":"həʊz",
  490.       "audio":"//ssl.gstatic.com/dictionary/static/sounds/20200429/hose--_gb_1.mp3"
  491.     }],
  492. "origin":"only to the ankle.",
  493. "meanings":[
  494.     {"partOfSpeech":"noun",
  495.      "definitions":[
  496.         {"definition":"a flexible tube ",
  497.          "example":"a sprinkler hose",
  498.          "synonyms": ["pipe","piping"],
  499.          "antonyms":[]
  500.         },
  501.         {"definition":"suse",
  502.          "example":"her hose had been laddered",
  503.          "synonyms":[],
  504.          "antonyms":[]
  505.         }
  506.         ]},
  507.  
  508.     {"partOfSpeech":"verb",
  509.      "definitions":[
  510.          {"definition":"water or spray with a hose.",
  511.           "example":"he was hosing down the driveway",
  512.           "synonyms":[],
  513.           "antonyms":[]
  514.           }]
  515.      }]
  516.  
  517. */
  518.  
  519.  
  520.  
Advertisement
Add Comment
Please, Sign In to add comment