{"action":"created","issue":{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/257","repository_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot","labels_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/257/labels{/name}","comments_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/257/comments","events_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/257/events","html_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/pull/257","id":157416996,"number":257,"title":"Persistence of options between script versions","user":{"login":"MattDuffin","id":8353780,"avatar_url":"https://avatars.githubusercontent.com/u/8353780?v=3","gravatar_id":"","url":"https://api.github.com/users/MattDuffin","html_url":"https://github.com/MattDuffin","followers_url":"https://api.github.com/users/MattDuffin/followers","following_url":"https://api.github.com/users/MattDuffin/following{/other_user}","gists_url":"https://api.github.com/users/MattDuffin/gists{/gist_id}","starred_url":"https://api.github.com/users/MattDuffin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MattDuffin/subscriptions","organizations_url":"https://api.github.com/users/MattDuffin/orgs","repos_url":"https://api.github.com/users/MattDuffin/repos","events_url":"https://api.github.com/users/MattDuffin/events{/privacy}","received_events_url":"https://api.github.com/users/MattDuffin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-05-30T01:30:27Z","updated_at":"2016-05-30T19:57:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/pulls/257","html_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/pull/257","diff_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/pull/257.diff","patch_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/pull/257.patch"},"body":"<!--- Provide a general summary of your changes in the Title above -->\r\n\r\n## Motivation and Context\r\nThis PR solves the problem of custom options getting overwritten when the script updates. Auto-updating the script from inside GreaseMonkey or TamperMonkey results in the options (which are stored directly in bot.user.js) getting overwritten with the defaults in the new script.\r\n\r\nIf you're like me, you like tweaking the options to your choice, and get annoyed when they get set back to default. Sure, you can copy and paste the options block from the previous script, but that requires you have it saved somewhere, which you probably don't when the script auto-updates.\r\n\r\n## Description\r\nHow does it work?\r\n- It uses LocalStorage to store a user's preferred options (via the persistence methods already built in to window.userInterface),\r\n- window.bot.opt defined in the script now stores the **default** set of options, which are loaded only if no other options are available (i.e. this is the first time the user has used the bot at all, or the first time since this feature was included),\r\n- The first time the script is run, the values in the script are saved,\r\n- Every other time the script is run, the values are loaded, taking priority over the default options,\r\n- If the user wants to change options, they make the changes in the new customBotOptions block at the start of the script. Any changes made here are picked up and saved next time the bot runs after saving the script,\r\n- Here's the big difference: when the script is updated, it sees that there are saved options from a previous version, and they are loaded instead of the default options, thereby preserving the choices of the user from the previous version.\r\n\r\nHere's the bad things:\r\n- Users will have to learn to put any new settings they want in customBotOptions instead of window.bot.opt, otherwise they won't be saved between script versions. I've tried to make this obvious by putting customBotOptions at the top of the file, including a warning at the top of window.bot.opt and removing the explanatory comments from window.bot.opt,\r\n- If the format of the option block changes, we have to change the code in two places.\r\n\r\nI'm not saying this is the best way of doing this, just saying it's a start. If you have a better idea, please contribute! This is a stepping stone on the way to having a graphical options overlay (if we want that).\r\n\r\nAlso, this will have to be tested by a few people before it can be merged.\r\n\r\n## Screenshots (if appropriate):\r\n![Flowchart](https://cloud.githubusercontent.com/assets/8353780/15648964/c29ad4dc-2665-11e6-89b2-fb3f344fb301.png)\r\n\r\n## Types of changes\r\n<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->\r\n- [ ] Bug fix (non-breaking change which fixes an issue)\r\n- [X] New feature (non-breaking change which adds functionality)\r\n- [X] Breaking change (fix or feature that would cause existing functionality to change)\r\n\r\n## Checklist:\r\n<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [X] My code follows the code style of this project.\r\n- [ ] My change requires a change to the documentation.\r\n- [ ] I have updated the documentation accordingly."},"comment":{"url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/comments/222547395","html_url":"https://github.com/ErmiyaEskandary/Slither.io-bot/pull/257#issuecomment-222547395","issue_url":"https://api.github.com/repos/ErmiyaEskandary/Slither.io-bot/issues/257","id":222547395,"user":{"login":"ErmiyaEskandary","id":18369104,"avatar_url":"https://avatars.githubusercontent.com/u/18369104?v=3","gravatar_id":"","url":"https://api.github.com/users/ErmiyaEskandary","html_url":"https://github.com/ErmiyaEskandary","followers_url":"https://api.github.com/users/ErmiyaEskandary/followers","following_url":"https://api.github.com/users/ErmiyaEskandary/following{/other_user}","gists_url":"https://api.github.com/users/ErmiyaEskandary/gists{/gist_id}","starred_url":"https://api.github.com/users/ErmiyaEskandary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErmiyaEskandary/subscriptions","organizations_url":"https://api.github.com/users/ErmiyaEskandary/orgs","repos_url":"https://api.github.com/users/ErmiyaEskandary/repos","events_url":"https://api.github.com/users/ErmiyaEskandary/events{/privacy}","received_events_url":"https://api.github.com/users/ErmiyaEskandary/received_events","type":"User","site_admin":false},"created_at":"2016-05-30T19:57:01Z","updated_at":"2016-05-30T19:57:01Z","body":"Should be fixed ... nvm"}}
{"actor":{"display_login":"ErmiyaEskandary"}}