1. function sleep(milliseconds) {
  2. return new Promise((resolve) => setTimeout(resolve, milliseconds));
  3. }
  4. async function jump_to_next_cursor_location(params) {
  5. let activeFile = await params.app.workspace.getActiveFile();
  6. if (!activeFile) {
  7. new Notice("Notice: No active file.");
  8. return;
  9. }
  10. let fileContent = await params.app.vault.cachedRead(activeFile);
  11. let rowCount = fileContent.split("\n").length;
  12. let lastLine = fileContent.split("\n")[rowCount - 1];
  13. let lastLineLength = lastLine.length;
  14. let columnCount = lastLineLength;
  15. let cmEditor = params.app.workspace.activeLeaf.view.editor;
  16. let newCursorLocation = {
  17. line: rowCount - 1,
  18. ch: columnCount,
  19. };
  20. await cmEditor.setCursor(newCursorLocation);
  21. // let cursorLocation = cmEditor.getCursor();
  22. // let tagspos = params.app.workspace.activeLeaf.view.data.search("tags:");
  23. // let posLine = params.app.workspace.activeLeaf.view.editor.offsetToPos(tagspos);
  24. // posLine.ch += tagspos + 1;
  25. // cmEditor.focus();
  26. // cmEditor.setCursor(posLine);
  27. }
  28. // let cmEditor = params.app.workspace.activeLeaf.view.editor;
  29. // let curCursor = cmEditor.getCursor();
  30. // cmEditor.setCursor({ line: 9999, ch: 9999 });
  31. module.exports = async (params) => {
  32. console.log(params);
  33. // 获取当前活动文件
  34. let activeFile = await params.app.workspace.getActiveFile();
  35. if (!activeFile) {
  36. new Notice("Notice: No active file.");
  37. return;
  38. }
  39. let fileContent = await params.app.vault.cachedRead(activeFile);
  40. let content = "# 公众号: 牙叔教程";
  41. let newFileContent = `${fileContent}${content}`;
  42. // 修改文件内容
  43. await params.app.vault.modify(activeFile, newFileContent);
  44. await jump_to_next_cursor_location(params);
  45. await sleep(1000);
  46. for (var i = 1; i < 11; i++) {
  47. let fileContent = await params.app.vault.cachedRead(activeFile);
  48. let content = "\n" + i;
  49. let newFileContent = `${fileContent}${content}`;
  50. // 修改文件内容
  51. await params.app.vault.modify(activeFile, newFileContent);
  52. await jump_to_next_cursor_location(params);
  53. await sleep(1000);
  54. }
  55. new Notice("Notice: printNumber Finished!");
  56. console.log("Finished!");
  57. };

名人名言

思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问
—- 牙叔教程

声明

部分内容来自网络
本教程仅用于学习, 禁止用于其他用途

bilibili

牙叔教程

微信公众号 牙叔教程

打印数字 - 图1

QQ群

747748653
打印数字 - 图2