Placeholder to Value

Setzt den Placeholder als Value für das aktuelle Eingabefeld oder Textarea bei Drücken von Alt+P

  1. // ==UserScript==
  2. // @name Placeholder to Value
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Setzt den Placeholder als Value für das aktuelle Eingabefeld oder Textarea bei Drücken von Alt+P
  6. // @match *://*/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function setPlaceholderAsValue() {
  15. const activeElement = document.activeElement;
  16. if ((activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') && activeElement.placeholder) {
  17. activeElement.value = activeElement.placeholder;
  18. }
  19. }
  20.  
  21. document.addEventListener('keydown', function(event) {
  22. // Überprüft, ob Alt+P gedrückt wurde
  23. if (event.altKey && event.keyCode === 80) {
  24. setPlaceholderAsValue();
  25. event.preventDefault();
  26. }
  27. });
  28. })();