Popup Oeener

Ctr + Alt + P를 누르면 입력한 주소의 팝업을 열 수 있습니다.

  1. // ==UserScript==
  2. // @name Popup Oeener
  3. // @namespace Popup Oeener
  4. // @version 0.1
  5. // @description Ctr + Alt + P를 누르면 입력한 주소의 팝업을 열 수 있습니다.
  6. // @author You
  7. // @match *://*/*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let container = null; // Initialize container as null
  17.  
  18. // Function to toggle the container's display
  19. function toggleContainer() {
  20. if (!container) {
  21. createContainer();
  22. }
  23. container.style.display = container.style.display === 'none' ? 'flex' : 'none';
  24. }
  25.  
  26. // Function to create the container div
  27. function createContainer() {
  28. container = document.createElement('div');
  29. container.style.position = 'fixed';
  30. container.style.top = '50%';
  31. container.style.left = '50%';
  32. container.style.transform = 'translate(-50%, -50%)';
  33. container.style.display = 'none'; // Initially hidden
  34. container.style.flexDirection = 'column'; // Display inputs and buttons vertically
  35.  
  36. // Create the first input field for global URL
  37. const globalInput = document.createElement('input');
  38. globalInput.type = 'text';
  39. globalInput.value = GM_getValue('globalUrl', '');
  40.  
  41. // Create the OK button for global URL
  42. const globalOkButton = document.createElement('button');
  43. globalOkButton.textContent = 'OK';
  44. globalOkButton.addEventListener('click', function() {
  45. const url = globalInput.value;
  46. if (url) {
  47. GM_setValue('globalUrl', url);
  48. window.open(url, '_blank', 'width=800,height=600');
  49. container.style.display = 'none'; // Hide the container
  50. }
  51. });
  52.  
  53. // Create the second input field for site-specific URL
  54. const siteInput = document.createElement('input');
  55. siteInput.type = 'text';
  56. siteInput.value = GM_getValue(window.location.hostname, '');
  57.  
  58. // Create the OK button for site-specific URL
  59. const siteOkButton = document.createElement('button');
  60. siteOkButton.textContent = 'OK';
  61. siteOkButton.addEventListener('click', function() {
  62. const url = siteInput.value;
  63. if (url) {
  64. GM_setValue(window.location.hostname, url);
  65. window.open(url, '_blank', 'width=800,height=600');
  66. container.style.display = 'none'; // Hide the container
  67. }
  68. });
  69.  
  70. // Append input fields and buttons to the container
  71. container.appendChild(globalInput);
  72. container.appendChild(globalOkButton);
  73. container.appendChild(siteInput);
  74. container.appendChild(siteOkButton);
  75.  
  76. // Append the container to the document body
  77. document.body.appendChild(container);
  78. }
  79.  
  80. // Listen for the Ctrl + Alt + P shortcut
  81. window.addEventListener('keydown', function(event) {
  82. if (event.ctrlKey && event.altKey && event.key === 'p') {
  83. toggleContainer(); // Toggle the container's display
  84. }
  85. });
  86. })();