User:Killer9000/common.js: Difference between revisions

From wowdev
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
   {
   {
     console.log("- " + elm.style.background);
     console.log("- " + elm.style.background);
     elm.style.background.color = "#00000000";
     elm.style.background.color = "rgb(0,0,0)";
     console.log("- " + elm.style.background);
     console.log("- " + elm.style.background);
   }
   }

Revision as of 22:35, 14 May 2022

var elms = document.querySelectorAll("*[style]");
Array.prototype.forEach.call(elms, function(elm) {
  if (elm.style.background)
  {
    console.log("- " + elm.style.background);
    elm.style.background.color = "rgb(0,0,0)";
    console.log("- " + elm.style.background);
  }
});  

var elms = document.querySelectorAll("textarea");
Array.prototype.forEach.call(elms, function(elm) {
  elm.addEventListener('keydown', function(e) {
    if (e.key == 'Tab') {
      e.preventDefault();
      var start = this.selectionStart;
      var end = this.selectionEnd;

      // set textarea value to: text before caret + tab + text after caret
      this.value = this.value.substring(0, start) +
        "\t" + this.value.substring(end);

      // put caret at right position again
      this.selectionStart =
      this.selectionEnd = start + 1;
    }
  });
});