bailan_paste.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. js:
  2. addListener("onRefresh", $.toString(() => {
  3. clearVar('cate');
  4. clearVar('content');
  5. clearVar('password');
  6. clearVar('time_limit');
  7. }))
  8. let d = [];
  9. const cate = getItem('cate', '1')
  10. d.push({
  11. title: cate === '1' ? '‘‘’’<strong><font color="red">导入</font></strong>' : '导入',
  12. url: $().lazyRule(_ => {
  13. setItem('cate', '1')
  14. refreshPage(true)
  15. return "hiker://empty"
  16. }),
  17. col_type: 'scroll_button'
  18. })
  19. d.push({
  20. title: cate === '2' ? '‘‘’’<strong><font color="red">创建</font></strong>' : '创建',
  21. url: $().lazyRule(_ => {
  22. setItem('cate', '2')
  23. refreshPage(true)
  24. return "hiker://empty"
  25. }),
  26. col_type: 'scroll_button'
  27. })
  28. if (cate === '1') {
  29. d.push({
  30. title: '导入',
  31. desc: '请粘贴内容',
  32. col_type: 'input',
  33. url: $.toString(() => {
  34. const res = input.split(' ')
  35. let path, password
  36. if (res.length === 2) {
  37. path = res[0].split('/').pop()
  38. password = res[1]
  39. } else {
  40. path = res[0].split('/').pop()
  41. }
  42. const json = request("https://pasteme.tyrantg.com/api/getContent/"+path+'@'+password)
  43. const result = JSON.parse(json)
  44. if (result.return_code !== 0) {
  45. log(result)
  46. refreshPage(true)
  47. return "toast://"+result.message
  48. }
  49. result.data = decodeURIComponent(result.data)
  50. if (result.data.startsWith('海阔视界'))
  51. return result.data
  52. else
  53. return "copy://"+result.data
  54. })
  55. })
  56. } else if (cate === '2') {
  57. d.push({
  58. title: '',
  59. desc: '请输入内容',
  60. col_type: 'input',
  61. extra: {
  62. type: 'textarea',
  63. titleVisible: false,
  64. height: 3,
  65. onChange: $.toString(_ => {
  66. setItem('content', input.trim())
  67. })
  68. }
  69. })
  70. d.push({
  71. title: '',
  72. desc: '请输入自定义密码(不输入会自动生成)',
  73. col_type: 'input',
  74. extra: {
  75. titleVisible: false,
  76. onChange: $.toString(_ => {
  77. setItem('password', input.trim())
  78. })
  79. }
  80. })
  81. d.push({
  82. title: '',
  83. desc: '请输入限制时间(分钟)',
  84. col_type: 'input',
  85. extra: {
  86. titleVisible: false,
  87. onChange: $.toString(_ => {
  88. setItem('time_limit', input.trim())
  89. })
  90. }
  91. })
  92. d.push({
  93. col_type: 'line_blank'
  94. })
  95. d.push({
  96. title: '提交',
  97. col_type: 'text_center_1',
  98. url: $().lazyRule(_ => {
  99. const obj2strUrl = (obj) => {
  100. let str="";
  101. for (let key in obj) {
  102. str += key+'='+encodeURIComponent(obj[key])+'&'
  103. }
  104. str = str.substring(0, str.length-1);
  105. return str;
  106. }
  107. const param_body = {}
  108. const content = getItem('content', '')
  109. const password = getItem('password', '')
  110. const time_limit = getItem('time_limit', '')
  111. if (content === '') {
  112. refreshPage(true)
  113. return "toast://请输入内容"
  114. }
  115. param_body.content = content
  116. if (password !== '')
  117. param_body.password = password
  118. else
  119. param_body.auto_password = 1
  120. if (time_limit !== '') param_body.time_limit = time_limit
  121. const json = request("https://pasteme.tyrantg.com/api/create", {body: obj2strUrl(param_body), method:'POST'})
  122. const res = JSON.parse(json)
  123. if (res.return_code !== 0) {
  124. log(res)
  125. refreshPage(true)
  126. return "toast://"+res.message
  127. }
  128. let result = "https://pasteme.tyrantg.com/"+res.data.path
  129. if (res.data.password) result += ' '+res.data.password
  130. copy(result)
  131. refreshPage(true)
  132. return "toast://已复制到剪贴板"
  133. })
  134. })
  135. }
  136. setResult(d)