Advertisement
julio_hb

Get icons from websites

Jan 8th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var AllIcons = "https://i.olsh.me/allicons.json";
  2. var resize = "https://images.weserv.nl/?w=96&h=96&page=-1&url=";
  3.  
  4.  
  5. import axios from 'axios';
  6.  
  7. export default LoadIcon;
  8.  
  9. function LoadIcon(url,callback)
  10. {
  11.     const axios = require("axios");
  12.  
  13.     axios({
  14.         "method":"GET",
  15.         "url":AllIcons,
  16.         "params":{
  17.             "url":url
  18.         }
  19.     })
  20.     .then((response)=>{
  21.         if(response.data.icons.length > 0)
  22.         {
  23.             var iconUrl = resize + response.data.icons[0].url;
  24.             callback(iconUrl);
  25.         }
  26.         else
  27.         {
  28.             console.log("No icons found for " + url);
  29.         }
  30.  
  31.     })
  32.     .catch((error)=>{
  33.         console.log("icon api error: " + error + " icon = " + url);
  34.     })
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement