Greasy Fork is available in English.

AndroidAPI

为轻小说文库++提供安卓API支持

Этот скрипт недоступен для установки пользователем. Он является библиотекой, которая подключается к другим скриптам мета-ключом // @require https://update.greasyfork.org/scripts/451129/1092140/AndroidAPI.js

  1. /* eslint-disable no-multi-spaces */
  2. /* eslint-disable no-implicit-globals */
  3. /* eslint-disable userscripts/no-invalid-headers */
  4. /* eslint-disable userscripts/no-invalid-grant */
  5.  
  6. // ==UserScript==
  7. // @name AndroidAPI
  8. // @displayname 安卓API支持
  9. // @namespace Wenku8++
  10. // @version 0.1
  11. // @description 为轻小说文库++提供安卓API支持
  12. // @author PY-DNG
  13. // @license GPL-v3
  14. // @regurl NONE
  15. // @require https://greasyfork.org/scripts/449412-basic-functions/code/Basic%20Functions.js?version=1085783
  16. // ==/UserScript==
  17.  
  18. (function __MAIN__() {
  19. 'use strict';
  20.  
  21. const AndAPI = new AndroidAPI();
  22. exports = AndAPI;
  23.  
  24. // Android API set
  25. function AndroidAPI() {
  26. const AA = this;
  27. const DParser = new DOMParser();
  28.  
  29. const encode = AA.encode = function(str) {
  30. return '&appver=1.13&request=' + btoa(str) + '&timetoken=' + (new Date().getTime());
  31. };
  32.  
  33. const request = AA.request = function(details) {
  34. const url = details.url;
  35. const type = details.type || 'text';
  36. const callback = details.callback || function() {};
  37. const args = details.args || [];
  38. GM_xmlhttpRequest({
  39. method: 'POST',
  40. url: 'http://app.wenku8.com/android.php',
  41. headers: {
  42. 'Content-Type': 'application/x-www-form-urlencoded',
  43. 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 7.1.2; unknown Build/NZH54D)'
  44. },
  45. data: encode(url),
  46. onload: function(e) {
  47. let result;
  48. switch (type) {
  49. case 'xml':
  50. result = DParser.parseFromString(e.responseText, 'text/xml');
  51. break;
  52. case 'text':
  53. result = e.responseText;
  54. break;
  55. }
  56. callback.apply(null, [result].concat(args));
  57. },
  58. onerror: function(e) {
  59. Err('Request error while requesting "' + url + '"');
  60. }
  61. });
  62. };
  63.  
  64. // aid, lang, callback, args
  65. AA.getNovelShortInfo = function(details) {
  66. const aid = details.aid;
  67. const lang = details.lang;
  68. const callback = details.callback || function() {};
  69. const args = details.args || [];
  70. const url = 'action=book&do=info&aid=' + aid + '&t=' + lang;
  71. request({
  72. url: url,
  73. callback: callback,
  74. args: args,
  75. type: 'xml'
  76. });
  77. }
  78.  
  79. // aid, lang, callback, args
  80. AA.getNovelIndex = function(details) {
  81. const aid = details.aid;
  82. const lang = details.lang;
  83. const callback = details.callback || function() {};
  84. const args = details.args || [];
  85. const url = 'action=book&do=list&aid=' + aid + '&t=' + lang;
  86. request({
  87. url: url,
  88. callback: callback,
  89. args: args,
  90. type: 'xml'
  91. });
  92. };
  93.  
  94. // aid, cid, lang, callback, args
  95. AA.getNovelContent = function(details) {
  96. const aid = details.aid;
  97. const cid = details.cid;
  98. const lang = details.lang;
  99. const callback = details.callback || function() {};
  100. const args = details.args || [];
  101. const url = 'action=book&do=text&aid=' + aid + '&cid=' + cid + '&t=' + lang;
  102. request({
  103. url: url,
  104. callback: callback,
  105. args: args,
  106. type: 'text'
  107. });
  108. };
  109. }
  110. })();