Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /***********/
  23. /* UTILITY */
  24. /***********/
  25. String.prototype.hasPrefix = function (prefix) {
  26. return (this.lastIndexOf(prefix, 0) === 0);
  27. }
  28. /***********/
  29. /* HELPERS */
  30. /***********/
  31. /* This function sends a message to the background script (background.js),
  32. which then updates the page action icon (i.e., the browser toolbar icon)
  33. to reflect whether killing stickies is enabled on the current page.
  34. */
  35. function updateIcon(shouldKillSticky, tabID) {
  36. chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky, "tabID": tabID });
  37. }
  38. /* This is the code that actually does the sticky killing! It simply selects
  39. all elements whose 'position' CSS property has a computed value of either
  40. 'sticky' or 'fixed', and removes those elements.
  41. */
  42. function killSticky() {
  43. console.log("Killing all stickies!");
  44. document.querySelectorAll('body *').forEach(element => {
  45. if (getComputedStyle(element).position === 'fixed' ||
  46. getComputedStyle(element).position === 'sticky') {
  47. element.remove();
  48. }
  49. });
  50. }