Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #target photoshop
- #include "json.js"
- alert("TwitchAlerts.jsx Loaded")
- //Where the Folder is
- var settingsFolder = Folder (app.path + "/Presets/Scripts/TAlerts");
- //Where the FILE for settings is
- var settingsFileLoc = File (settingsFolder + "/settings.json");
- //data from settings file
- var settings;
- getURLFromUser();
- function getURLFromUser()
- {
- settings = readSettingsFile();
- createWindow();
- writeSettingsFile();
- // var YourURL = (settings.url);
- // alert(YourURL);
- // var myframe = document.getElementById("myIFrame");
- // alert(myframe.src);
- // myframe.src = "https://www.twitch.tv/boyfruit/chat";
- // var yoururl = (settings.url);
- // alert(yoururl);
- // var myframe = document.getElementById("myIFrame");
- // alert(myframe.src)
- }
- function createWindow()
- {
- windowDesc =
- "dialog\
- {\
- orientation:'column'\
- ,textGroup:Group\
- {\
- orientation:'row'\
- ,urlStaticText:StaticText{text:'Enter Your URL Here:'}\
- ,textBox:EditText{preferredSize: [250,20]}\
- }\
- ,OkBtn:Button{text:'OK'}\
- }";
- var mainWindow = new Window(windowDesc);
- mainWindow.text = "Twitch Alerts";
- //Load previous URL
- mainWindow.textGroup.textBox.text = settings.url;
- //CallBacks
- mainWindow.OkBtn.onClick = function()
- {
- settings.url = mainWindow.textGroup.textBox.text;
- mainWindow.close();
- };
- mainWindow.center();
- mainWindow.show();
- }
- //function createWindow()
- ////{
- //// alert("window made")
- //// var link= prompt("URL","http://YourURLHERE.com","OK");
- //// alert(link);
- ////}
- //{
- // windowDesc =
- // "dialog\
- // {\
- // orientation:'column'\
- // ,textGroup:Group\
- // {\
- // orientation:'row'\
- // ,urlStaticText:StaticText{text:'Enter Your URL Here:'}\
- // ,textBox:EditText{preferredSize: [250,20]}\
- // }\
- // ,OkBtn:Button{text:'OK'}\
- // }";
- // var mainWindow = new Window(windowDesc);
- // mainWindow.text = "Twitch Alerts";
- //
- // //Load previous URL
- // mainWindow.textGroup.textBox.text = settings.url;
- //
- // //CallBacks
- // mainWindow.OkBtn.onClick = function()
- // {
- // settings.url = mainWindow.textGroup.textBox.text;
- // mainWindow.close();
- // };
- //
- // mainWindow.center();
- // mainWindow.show();
- //}
- function writeSettingsFile()
- {
- checkIfSettingsFolderExists();
- var output = JSON.stringify(settings);
- settingsFileLoc.open('w');
- settingsFileLoc.write(output);
- settingsFileLoc.close();
- }
- function readSettingsFile()
- {
- //Get the JSON file.
- //Check to see if the json save already exists, if not make a default one.
- if(!settingsFileLoc.exists)
- {
- settingsFolder.create();
- return {"url":"http://www.Google.com"};
- }
- settingsFileLoc.open('r');
- var str = "";
- str = settingsFileLoc.read();
- settingsFileLoc.close();
- if(str == "")
- {
- return validateSettingsFile(oldSettingsSetup());
- }
- var json = JSON.parse(str);
- //validate will take in the json and compare it with a default settings output to make sure it has the right # of properties
- return json;
- }
- function checkIfSettingsFolderExists()
- {
- if(!settingsFolder.exists)
- {
- var path = new File($.fileName).parent;
- settingsFolder.create();
- checkIfSettingsFolderExists();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement