User:Killer9000/common.js: Difference between revisions

From wowdev
Jump to navigation Jump to search
No edit summary
No edit summary
 
(15 intermediate revisions by the same user not shown)
Line 2: Line 2:
var elms = document.querySelectorAll("*[style]");
var elms = document.querySelectorAll("*[style]");
Array.prototype.forEach.call(elms, function(elm) {
Array.prototype.forEach.call(elms, function(elm) {
   // Get the color value
   if (elm.style.background)
  var clr = elm.style.background|| "";
  console.log(clr);
  // Remove all whitespace, make it all lower case
  clr = clr.replace(/\s/g, "").toLowerCase();
  // Switch on the possible values we know of
  switch (clr)
   {
   {
  case "#eee":
    console.log("- " + elm.style.background);
     elm.style.color = "#000000";
     elm.style.background = "rgba(0,0,0,0)";
     break;
     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;
    }
  });
});
});

Latest 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 = "rgba(0,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;
    }
  });
});