Advertisement
Guest User

TwitchAlerts.jsx

a guest
Oct 26th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #target photoshop
  2.  
  3. #include "json.js"
  4.  
  5. alert("TwitchAlerts.jsx Loaded")
  6.  
  7. //Where the Folder is
  8. var settingsFolder = Folder (app.path + "/Presets/Scripts/TAlerts");
  9. //Where the FILE for settings is
  10. var settingsFileLoc = File (settingsFolder + "/settings.json");
  11. //data from settings file
  12. var settings;
  13.  
  14. getURLFromUser();
  15.  
  16. function getURLFromUser()
  17. {
  18. settings = readSettingsFile();
  19. createWindow();
  20. writeSettingsFile();
  21. // var YourURL = (settings.url);
  22. // alert(YourURL);
  23.  
  24. // var myframe = document.getElementById("myIFrame");
  25. // alert(myframe.src);
  26. // myframe.src = "https://www.twitch.tv/boyfruit/chat";
  27. // var yoururl = (settings.url);
  28. // alert(yoururl);
  29. // var myframe = document.getElementById("myIFrame");
  30. // alert(myframe.src)
  31.  
  32. }
  33.  
  34. function createWindow()
  35. {
  36. windowDesc =
  37. "dialog\
  38. {\
  39. orientation:'column'\
  40. ,textGroup:Group\
  41. {\
  42. orientation:'row'\
  43. ,urlStaticText:StaticText{text:'Enter Your URL Here:'}\
  44. ,textBox:EditText{preferredSize: [250,20]}\
  45. }\
  46. ,OkBtn:Button{text:'OK'}\
  47. }";
  48. var mainWindow = new Window(windowDesc);
  49. mainWindow.text = "Twitch Alerts";
  50.  
  51. //Load previous URL
  52. mainWindow.textGroup.textBox.text = settings.url;
  53.  
  54. //CallBacks
  55. mainWindow.OkBtn.onClick = function()
  56. {
  57. settings.url = mainWindow.textGroup.textBox.text;
  58. mainWindow.close();
  59. };
  60.  
  61. mainWindow.center();
  62. mainWindow.show();
  63. }
  64.  
  65. //function createWindow()
  66. ////{
  67. //// alert("window made")
  68. //// var link= prompt("URL","http://YourURLHERE.com","OK");
  69. //// alert(link);
  70. ////}
  71. //{
  72. // windowDesc =
  73. // "dialog\
  74. // {\
  75. // orientation:'column'\
  76. // ,textGroup:Group\
  77. // {\
  78. // orientation:'row'\
  79. // ,urlStaticText:StaticText{text:'Enter Your URL Here:'}\
  80. // ,textBox:EditText{preferredSize: [250,20]}\
  81. // }\
  82. // ,OkBtn:Button{text:'OK'}\
  83. // }";
  84. // var mainWindow = new Window(windowDesc);
  85. // mainWindow.text = "Twitch Alerts";
  86. //
  87. // //Load previous URL
  88. // mainWindow.textGroup.textBox.text = settings.url;
  89. //
  90. // //CallBacks
  91. // mainWindow.OkBtn.onClick = function()
  92. // {
  93. // settings.url = mainWindow.textGroup.textBox.text;
  94. // mainWindow.close();
  95. // };
  96. //
  97. // mainWindow.center();
  98. // mainWindow.show();
  99. //}
  100.  
  101.  
  102. function writeSettingsFile()
  103. {
  104. checkIfSettingsFolderExists();
  105. var output = JSON.stringify(settings);
  106. settingsFileLoc.open('w');
  107. settingsFileLoc.write(output);
  108. settingsFileLoc.close();
  109. }
  110.  
  111. function readSettingsFile()
  112. {
  113. //Get the JSON file.
  114. //Check to see if the json save already exists, if not make a default one.
  115. if(!settingsFileLoc.exists)
  116. {
  117. settingsFolder.create();
  118. return {"url":"http://www.Google.com"};
  119. }
  120. settingsFileLoc.open('r');
  121. var str = "";
  122. str = settingsFileLoc.read();
  123. settingsFileLoc.close();
  124. if(str == "")
  125. {
  126. return validateSettingsFile(oldSettingsSetup());
  127. }
  128. var json = JSON.parse(str);
  129.  
  130. //validate will take in the json and compare it with a default settings output to make sure it has the right # of properties
  131. return json;
  132.  
  133. }
  134.  
  135. function checkIfSettingsFolderExists()
  136. {
  137. if(!settingsFolder.exists)
  138. {
  139. var path = new File($.fileName).parent;
  140. settingsFolder.create();
  141. checkIfSettingsFolderExists();
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement