mozilla:textareawrap

Wrap Switcher

Das folgende User-Script schaltet den Zeichenumbruch über das Kontextmenü um.

// ==UserScript==
// @name wordwrap
// @namespace wordwrap
// @match *://*/*
// @grant none
// ==/UserScript==
 
var itemName = "LineWrap";
var onLabel = "Line wrap on";
var offLabel = "Line wrap off";
 
var origwrap = [];       
var elements = document.getElementsByTagName("textarea");
for (i = 0; i < elements.length; i++) { 
  elements[i].setAttribute("contextmenu", itemName + i); 
  if (elements[i].hasAttribute("wrap")) {
    origwrap[i] = elements[i].getAttribute("wrap");
  } else {
    origwrap[i] = "soft";
    elements[i].setAttribute("wrap", origwrap[i]); 
  }
 
  var wrapmenu = document.createElement("menu");
  wrapmenu.setAttribute("type", "context"); 
  wrapmenu.setAttribute("id", itemName + i); 
 
  var menuitemWrap = document.createElement("menuitem");
  if (origwrap[i] === 'off') {   
     menuitemWrap.setAttribute("label", onLabel); 
     origwrap[i] = "soft";
  } else {
     menuitemWrap.setAttribute("label", offLabel); 
  }
  menuitemWrap.addEventListener('click', function(ev){LineWrapToggle(ev)}, true);
  wrapmenu.appendChild(menuitemWrap);
  document.body.appendChild(wrapmenu);  
}
 
function LineWrapToggle(ev) {
    menuItem = ev.target;
    var idx  = menuItem.parentNode.getAttribute("id").substring(itemName.length);
    wrap = elements[idx].getAttribute("wrap");
    if (wrap === "off") {
      elements[idx].setAttribute("wrap", origwrap[idx]);
      menuItem.setAttribute("label", offLabel); 
    } else {
      elements[idx].setAttribute("wrap", "off");
      menuItem.setAttribute("label", onLabel); 
    }
}
mozilla/textareawrap.txt · Zuletzt geändert: 2017/06/11 01:17 von michael

Seiten-Werkzeuge