Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- yourworldoftext.com/applescript
  2. -- Instructions: Run script. After the beep, the clipboard has specially formatted javascript.
  3. -- paste the contents of the clipboard into a javascript console and run.
  4.  
  5. set epoch_time to do shell script ("date +%s") as number 20
  6. set output_array to ""
  7. set number_of_slices to 0
  8. set cell_x_width to 7
  9. set cell_y_width to 15
  10.  
  11. set slice_partition to 128 * 1
  12. set skip_number to 0
  13.  
  14. property big_x_start : 0
  15. property small_x_start : 0
  16. property big_y_start : 0
  17. property small_y_start : 0
  18.  
  19. set big_x to big_x_start
  20. set small_x to small_x_start
  21. set big_y to big_y_start
  22. set small_y to small_y_start
  23.  
  24. set page to "" as string
  25.  
  26.  
  27. set theFile to choose file with prompt "Select a text file:"
  28. set theFileReference to open for access theFile
  29. set theFileContents to read theFileReference
  30. close access theFileReference
  31.  
  32. set total_length to length of theFileContents
  33.  
  34. display dialog ("Length of text: " & total_length & " characters" & "
  35. " & theFileContents)
  36.  
  37. display dialog "X tile" default answer big_x_start
  38. set big_x_start to text returned of result
  39.  
  40. display dialog "Y tile" default answer big_y_start
  41. set big_y_start to text returned of result
  42.  
  43. set big_x to big_x_start
  44. set big_y to big_y_start
  45.  
  46. set output_array to output_array & "arr = ["
  47. repeat with i from 1 to total_length
  48.     set char to character i of theFileContents
  49.     if char = "
  50. " then
  51.         set big_x to big_x_start
  52.         set small_x to small_x_start
  53.         if small_y = 7 then
  54.             set big_y to big_y + 1
  55.             set small_y to 0
  56.         else
  57.             set small_y to small_y + 1
  58.         end if
  59.     else
  60.         if char = "\\" then
  61.             set char to "\\\\"
  62.         end if
  63.         if char = "\"" then
  64.             set char to "\\\""
  65.         end if
  66.         set output_array to output_array & translate_character(big_x, big_y, small_x, small_y, epoch_time, char)
  67.         if small_x = 15 then
  68.             set big_x to big_x + 1
  69.             set small_x to 0
  70.         else
  71.             set small_x to small_x + 1
  72.         end if
  73.     end if
  74. end repeat
  75. set output_array to output_array & "];"
  76. set output_array to output_array & "
  77. "
  78.  
  79. set number_of_edits to round total_length / slice_partition rounding up
  80.  
  81. repeat with i from 1 to number_of_edits
  82.     set start_slice to 0 + slice_partition * (i - 1)
  83.     set end_slice to slice_partition + slice_partition * (i - 1)
  84.     set output_array to output_array & specifiy_edits(start_slice, end_slice, page)
  85. end repeat
  86.  
  87.  
  88. set the clipboard to output_array
  89. beep
  90.  
  91. to specifiy_edits(start_slice, end_slice, page)
  92.     return "setTimeout(function() { jQuery.post(window.location.pathname, {edits: arr.slice(" & start_slice & ", " & end_slice & ")}, YourWorld.editsDone, 'json') }, 10*" & start_slice & ");
  93. "
  94. end specifiy_edits
  95.  
  96. to translate_character(big_x, big_y, small_x, small_y, time, next_character)
  97.     return "[" & big_y & ", " & big_x & ", " & small_y & ", " & small_x & ", " & time & "000" & ", " & "\"" & next_character & "\"" & "], "
  98. end translate_character
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement