1、js依赖

/**
* 今日诗词V2 JS-SDK 1.2.2
* 今日诗词API 是一个可以免费调用的诗词接口:https://www.jinrishici.com
*/
!function(e){var n,t={},o="jinrishici-Token";function i(){return document.getElementById("jinrishici-sentence")||0!=document.getElementsByClassName("jinrishici-sentence").length}function c(){t.load(function(e){var n=document.getElementById("jinrishici-sentence"),t=document.getElementsByClassName("jinrishici-sentence");if(n&&(n.innerText=e.data.content),0!==t.length)for(var o=0;o<t.length;o++)t[o].innerText=e.data.content})}function r(e,n){var t=new XMLHttpRequest;t.open("get",n),t.withCredentials=!0,t.send(),t.onreadystatechange=function(n){if(4===t.readyState){var o=JSON.parse(t.responseText);"success"===o.status?e(o):console.error("今日诗词API加载失败,错误原因:"+o.errMessage)}}}t.load=function(n){return e.localStorage&&e.localStorage.getItem(o)?function(e,n){return r(e,"https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token="+encodeURIComponent(n))}(n,e.localStorage.getItem(o)):function(n){return r(function(t){e.localStorage.setItem(o,t.token),n(t)},"https://v2.jinrishici.com/one.json?client=browser-sdk/1.2")}(n)},e.jinrishici=t,i()?c():(n=function(){i()&&c()},"loading"!=document.readyState?n():document.addEventListener?document.addEventListener("DOMContentLoaded",n):document.attachEvent("onreadystatechange",function(){"complete"==document.readyState&&n()}))}(window);

2、调用示例

// 方式1
jinrishici.load(function(rs) {
console.log(rs.data.content);
}); // 方式2
jinrishici.load(test); function test(rs) {
console.log(rs.data.content);
}

官网:今日诗词

最新文章

  1. jmeter 运行多个sql
  2. bdb log file 预设长度的性能优化
  3. Python2.6下基于rsa的加密解密
  4. eclipse推荐的插件
  5. 使用J2SE API读取Properties文件的六种方法
  6. c# dynamic动态类型和匿名类
  7. SSD(固态硬盘)简介
  8. jquery easyui datebox 的使用
  9. 技巧集:nginx作代理时,查看请求被转发到哪台服务器
  10. Maven中Spring-Data-Redis存储对象(redisTemplate) (转)
  11. 背包问题matlab程序
  12. 博弈论最简单例子TacTicToe
  13. Oracle COMMIT语句的处理顺序
  14. SQL Server 表的管理_关于事务的处理的详解(案例代码)
  15. Java核心基础学习(一)--- 2019年1月
  16. Python的命名空间及作用域
  17. grep配置颜色显示
  18. CSS 让 fontawesome 图标字体变细
  19. 峰Spring4学习(4)spring自动装配
  20. SpringMVC读取配置文件

热门文章

  1. 【翻译】Raft 共识算法:集群成员变更
  2. PHP配置负载均衡
  3. Windows10 + Eclipse C/C++开发环境配置极简教程
  4. eDP接口简介
  5. Windows 环境搭建 PostgreSQL 逻辑复制高可用架构数据库服务
  6. 测试架构师CAP原理(最简单)
  7. JWT中token的理解
  8. Dockerfile 使用 SSH docker build
  9. Go语言核心36讲37
  10. Java 中九种 Map 的遍历方式,你一般用的是哪种呢?