GoDaddy Nameserver Changer with User Input and Button

手动更改 GoDaddy 域名的 DNS 服务器,允许用户输入域名服务器并点击按钮进行填充

当前为 2024-10-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GoDaddy Nameserver Changer with User Input and Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.8
  5. // @description 手动更改 GoDaddy 域名的 DNS 服务器,允许用户输入域名服务器并点击按钮进行填充
  6. // @author hatrd
  7. // @match https://dcc.godaddy.com/control/portfolio/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 创建并添加输入区域和按钮
  16. function createUI() {
  17. const container = document.createElement('div');
  18. container.style.position = 'fixed';
  19. container.style.top = '10px';
  20. container.style.right = '10px';
  21. container.style.zIndex = '9999';
  22. container.style.backgroundColor = '#fff';
  23. container.style.border = '1px solid #ccc';
  24. container.style.padding = '10px';
  25. container.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)';
  26.  
  27. const textarea = document.createElement('textarea');
  28. textarea.rows = 4;
  29. textarea.cols = 40;
  30. textarea.placeholder = '请输入域名服务器,每行一个,最多四个';
  31.  
  32. const button = document.createElement('button');
  33. button.textContent = '填充域名服务器';
  34.  
  35. button.addEventListener('click', () => {
  36. const userInput = textarea.value;
  37. if (userInput) {
  38. // 将用户输入的内容按行分割
  39. const newNameservers = userInput.split('\n').map(ns => ns.trim()).filter(ns => ns);
  40.  
  41. // 去除末尾的点
  42. const sanitizedNameservers = newNameservers.map(ns => ns.replace(/\.$/, ''));
  43.  
  44. // 填写域名服务器输入框
  45. function fillNameservers() {
  46. let currentIndex = 0;
  47.  
  48. function fillNextNameserver() {
  49. if (currentIndex >= sanitizedNameservers.length) return;
  50.  
  51. const ns = sanitizedNameservers[currentIndex];
  52. const nsInputId = `#nameserver${currentIndex + 1}`;
  53. waitForElement(nsInputId, (nsInput) => {
  54. nsInput.focus();
  55.  
  56. // 模拟粘贴输入
  57. nsInput.value = ''; // 清空输入框内容
  58. nsInput.select();
  59. document.execCommand('insertText', false, ns); // 插入文本
  60. nsInput.dispatchEvent(new Event('input', { bubbles: true })); // 触发输入事件
  61. nsInput.dispatchEvent(new Event('change', { bubbles: true })); // 触发更改事件
  62. currentIndex++;
  63. });
  64.  
  65. // 递归调用填写下一个域名服务器
  66. if (currentIndex < sanitizedNameservers.length) {
  67. setTimeout(fillNextNameserver, 500 + Math.random() * 500); // 添加随机时间间隔
  68. }
  69. }
  70.  
  71. fillNextNameserver();
  72. }
  73.  
  74. // 等待指定元素加载完毕的函数
  75. function waitForElement(selector, callback) {
  76. const interval = setInterval(() => {
  77. const element = document.querySelector(selector);
  78. if (element) {
  79. clearInterval(interval);
  80. callback(element);
  81. }
  82. }, 100);
  83. }
  84.  
  85. // 开始填充
  86. fillNameservers();
  87. }
  88. });
  89.  
  90. container.appendChild(textarea);
  91. container.appendChild(button);
  92. document.body.appendChild(container);
  93. }
  94.  
  95. // 等待页面加载完毕后创建UI
  96. window.addEventListener('load', createUI);
  97. })();