Tab Title Editor

Edit tab name easily with text bar & enter button, no refresh required.

目前为 2024-05-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Tab Title Editor
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Edit tab name easily with text bar & enter button, no refresh required.
  6. // @author Emree.el on Instagram
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create the container div
  16. var container = document.createElement('div');
  17. container.style.position = 'fixed';
  18. container.style.top = '10px';
  19. container.style.right = '10px';
  20. container.style.zIndex = '9999';
  21. container.style.backgroundColor = 'black';
  22. container.style.padding = '10px';
  23. container.style.border = '1px solid black';
  24. container.style.borderRadius = '5px';
  25. container.style.display = 'flex';
  26. container.style.alignItems = 'center';
  27. document.body.appendChild(container);
  28.  
  29. // Create the checkbox
  30. var checkbox = document.createElement('input');
  31. checkbox.type = 'checkbox';
  32. checkbox.style.marginRight = '10px';
  33. container.appendChild(checkbox);
  34.  
  35. // Create the text input
  36. var textInput = document.createElement('input');
  37. textInput.type = 'text';
  38. textInput.style.marginRight = '10px';
  39. textInput.style.display = 'none';
  40. textInput.style.backgroundColor = 'black';
  41. textInput.style.color = 'white';
  42. textInput.style.border = '1px solid white';
  43. container.appendChild(textInput);
  44.  
  45. // Create the button
  46. var button = document.createElement('button');
  47. button.textContent = 'Enter';
  48. button.style.display = 'none';
  49. button.style.backgroundColor = 'black';
  50. button.style.color = 'white';
  51. button.style.border = '1px solid black';
  52. container.appendChild(button);
  53.  
  54. // Show/hide text input and button when checkbox is toggled
  55. checkbox.addEventListener('change', function() {
  56. if (checkbox.checked) {
  57. textInput.style.display = 'inline';
  58. button.style.display = 'inline';
  59. } else {
  60. textInput.style.display = 'none';
  61. button.style.display = 'none';
  62. }
  63. });
  64.  
  65. // Change tab title when button is clicked
  66. button.addEventListener('click', function() {
  67. if (textInput.value.trim() !== '') {
  68. document.title = textInput.value;
  69. }
  70. });
  71. })();
  72.