Advertisement
FullLifeGames

Showdown Backupper

Jul 25th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Showdown Backupper
  3. // @namespace https://fulllifegames.com/Tools/ShowdownBackupper
  4. // @description This script aims to create an easy backup for your Showdown teams.
  5. // @author FullLifeGames
  6. // @include http://play.pokemonshowdown.com/
  7. // @include https://play.pokemonshowdown.com/
  8. // @include http://play.pokemonshowdown.com/*
  9. // @include https://play.pokemonshowdown.com/*
  10. // @include http://*.psim.us/
  11. // @include https://*.psim.us/
  12. // @include http://*.psim.us/*
  13. // @include https://*.psim.us/*
  14. // @version 0.0.1
  15. // @grant none
  16. // @run-at document-end
  17. // ==/UserScript==
  18.  
  19. (function() {
  20.  
  21. var identifier = "#room-teambuilder > div.teampane > p:nth-child(6)";
  22.  
  23. function getDateTime() {
  24. var today = new Date();
  25. var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
  26. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  27. return date+' '+time;
  28. }
  29.  
  30. function downloadString(text, fileType, fileName) {
  31. var blob = new Blob([text], { type: fileType });
  32.  
  33. var a = document.createElement('a');
  34. a.download = fileName;
  35. a.href = URL.createObjectURL(blob);
  36. a.dataset.downloadurl = [fileType, a.download, a.href].join(':');
  37. a.style.display = "none";
  38. document.body.appendChild(a);
  39. a.click();
  40. document.body.removeChild(a);
  41. setTimeout(function() { URL.revokeObjectURL(a.href); }, 1500);
  42. }
  43.  
  44. function clickEvent() {
  45. var teams = localStorage.getItem("showdown_teams");
  46. downloadString(teams, "text/plain;charset=utf-8;", "teamBackup" + getDateTime() + ".txt");
  47. }
  48.  
  49. function setButton() {
  50. const backupButton = $('<button/>', {
  51. id: 'backup',
  52. text: 'Backup',
  53. click: clickEvent,
  54. class: 'button big',
  55. });
  56. $(identifier + ' > button:nth-child(2)').after(backupButton);
  57. }
  58.  
  59. function bootstrap() {
  60. if ($(identifier + " > #backup").length === 0) {
  61. setButton();
  62. }
  63. setTimeout(bootstrap, 1000);
  64. }
  65.  
  66. bootstrap();
  67. })();
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement