選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

options.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*******************************/
  2. /* EVENT LISTENER MANIPULATION */
  3. /*******************************/
  4. /* Adds an event listener to a button (or other clickable element), attaching
  5. it to both "click" and "keyup" events (for use with keyboard navigation).
  6. Optionally also attaches the listener to the 'mousedown' event, making the
  7. element activate on mouse down instead of mouse up. */
  8. Element.prototype.addActivateEvent = function(func, includeMouseDown) {
  9. let ael = this.activateEventListener = (event) => { if (event.button === 0 || event.key === ' ') func(event) };
  10. if (includeMouseDown) this.addEventListener("mousedown", ael);
  11. this.addEventListener("click", ael);
  12. this.addEventListener("keyup", ael);
  13. }
  14. /* Removes event listener from a clickable element, automatically detaching it
  15. from all relevant event types. */
  16. Element.prototype.removeActivateEvent = function() {
  17. let ael = this.activateEventListener;
  18. this.removeEventListener("mousedown", ael);
  19. this.removeEventListener("click", ael);
  20. this.removeEventListener("keyup", ael);
  21. }
  22. document.querySelector("button").addActivateEvent((event) => {
  23. event.target.blur();
  24. let text = document.querySelector("textarea").value;
  25. chrome.storage.sync.set({ "patterns": text }, () => {
  26. event.target.disabled = true;
  27. });
  28. });
  29. document.querySelector("textarea").addEventListener("input", (event) => {
  30. document.querySelector("button").disabled = false;
  31. });