tools.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const config_config = require("../config/config.js");
  4. const framework_http = require("./http.js");
  5. const framework_log = require("./log.js");
  6. const _tools = class {
  7. static initPlatform() {
  8. _tools.platform = config_config.config.Platform.TOUTIAO;
  9. framework_log.log.Debug("当前运行平台:", _tools.platform);
  10. }
  11. static getCurPlatform() {
  12. return _tools.platform;
  13. }
  14. static setNavigationBar() {
  15. if (_tools.getCurPlatform() == config_config.config.Platform.TOUTIAO) {
  16. common_vendor.index.setNavigationBarTitle({
  17. title: "卿卿小屋"
  18. });
  19. }
  20. }
  21. static getChapterList(chapter_path, cb) {
  22. framework_http.http.StaticRequest(chapter_path, (err, data) => {
  23. if (err) {
  24. return;
  25. }
  26. cb(data);
  27. });
  28. }
  29. static getCurChapterTxt(base_path, chapter_id, emspWidth, cb) {
  30. let url = `${base_path}${chapter_id}.txt`;
  31. framework_http.http.getStaticText(url, (err, data) => {
  32. if (err) {
  33. framework_log.log.Error(err);
  34. return;
  35. }
  36. cb(_tools.autoParagraph(data, emspWidth));
  37. });
  38. }
  39. static getChapterReadChapterIdByData(chapter_data) {
  40. if (chapter_data.cur_read_chapter_id == void 0 || chapter_data.cur_read_chapter_id == 0 || chapter_data.cur_read_chapter_id == null) {
  41. return 1;
  42. }
  43. }
  44. static autoParagraph(text, emspWidth) {
  45. const emspStyle = `style="margin-left: ${emspWidth}px;"`;
  46. const emsp_html = `<span ${emspStyle}></span>`;
  47. const character = `<br><br>${emsp_html}`;
  48. return character + text.replace(/\n\s*/g, character);
  49. }
  50. };
  51. let tools = _tools;
  52. tools.platform = config_config.config.Platform.H5;
  53. exports.tools = tools;