Simple PloudOS DynamicIP Copy

Adds a simple button to copy Dynamic IP address from PloudOS manage page

  1. // ==UserScript==
  2. // @name Simple PloudOS DynamicIP Copy
  3. // @namespace https://github.com/HageFX-78
  4. // @version 0.3.2
  5. // @description Adds a simple button to copy Dynamic IP address from PloudOS manage page
  6. // @author HageFX78
  7. // @license MIT
  8. // @match https://ploudos.com/manage/*/
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant GM_addStyle
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  15. // Simple Script that adds a button to ploudos.com on your server's manage page to copy dyamic IP address
  16. //
  17. // This was created out of frustration of the site's dynamic IP text background being blue, making it hard
  18. // to see when highlighted, sometimes Ctrl-C straight up doesn't work on that text.
  19. //
  20. // Button will only show up when the server is started, button will remain there if the server is stopped
  21. // it would only lose its functionality until the server is restarted again.
  22. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  23.  
  24. GM_addStyle ( `
  25.  
  26. #dyncp {
  27. padding: 10px 14px 10px 14px;
  28. border-style: none;
  29. border-radius: 2px;
  30. font-size: 14px;
  31. font-weight: bold;
  32. position: absolute;
  33. left: 70%;
  34. top: 10.4em;
  35. }
  36.  
  37. .not_copied:hover{
  38. background-color: green;
  39. }
  40. .not_copied {
  41. color: white;
  42. background-color: #32CD32;
  43. }
  44. .copied {
  45. color: white;
  46. background-color: #265730;
  47. }
  48.  
  49. ` );
  50.  
  51. window.addEventListener('load', function() {
  52. 'use strict';
  53.  
  54. function copy(str) {
  55. let temp = document.createElement('textarea');
  56. document.body.appendChild(temp);
  57. temp.value = str;
  58. temp.select();
  59. document.execCommand('copy');
  60. temp.remove();
  61. }
  62.  
  63. function addCopyBtn(ele)//Adds button after h2 element of "Status" instead of table ( with id='status') as the table would be refreshed every second by PloudOS itself
  64. {
  65.  
  66. let btn = document.createElement("button");
  67. btn.id = "dyncp";
  68. btn.className = "not_copied";
  69. btn.innerHTML = "Copy Dyn. IP";
  70. btn.onclick = () =>{
  71. btn.innerHTML = "Copied"
  72. btn.className = "copied"
  73. setTimeout(resetButton, 1000, btn);
  74. let dynmTag = document.getElementsByTagName("tr");
  75. const str = dynmTag[2].textContent.replace("Dyn. IP", '').trim();
  76. copy(str);
  77. }
  78.  
  79. ele.appendChild(btn);
  80. }
  81. function serverIsStarted()
  82. {
  83. if(document.getElementsByTagName("h2")[0].textContent != "Status") return; //Check if page is main page
  84.  
  85. let dynmTag = document.getElementsByTagName("tr"); //Table rows are used to determine if the server is started
  86.  
  87. if(typeof(dynmTag) != 'undefined' && dynmTag != null && dynmTag.length == 5) // If table rows is 5, it means server is started
  88. {
  89. obs.disconnect();
  90. let tagTopPlaceBtn = document.getElementsByTagName("h2")[0];
  91. addCopyBtn(tagTopPlaceBtn);
  92. }
  93. else
  94. {
  95. obs.observe(document.getElementById('status'),{childList: true}); //To start observing if server is started if not
  96. }
  97. }
  98. function resetButton(btn)
  99. {
  100. btn.className = "not_copied";
  101. btn.innerHTML = "Copy Dyn. IP";
  102. }
  103.  
  104. var obs = new MutationObserver(function (e) {
  105. if (e[0].removedNodes){
  106. console.log("Rechecking server start status."); //When table is refreshed, checks if server is started again
  107. serverIsStarted();
  108. };
  109. });
  110.  
  111. serverIsStarted();//init
  112. });