Disable WakeLock for Twitter

Prevent Twitter from blocking system hibernation by preventing videos from looping. (Translated by DeepL)

  1. // ==UserScript==
  2. // @name Disable WakeLock for Twitter
  3. // @namespace https://github.com/ipcjs
  4. // @version 0.1
  5. // @description Prevent Twitter from blocking system hibernation by preventing videos from looping. (Translated by DeepL)
  6. // @author ipcjs
  7. // @match https://twitter.com/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. new MutationObserver((mutations, observer) => {
  13. for (const m of mutations) {
  14. for (const node of m.addedNodes) {
  15. if (node.nodeType === Node.ELEMENT_NODE) {
  16. /** @type {HTMLVideoElement[]} */
  17. const videos = Array.from((node).querySelectorAll('video'))
  18. for (const video of videos) {
  19. // console.log('video', m.type, video)
  20. video.addEventListener('seeked', function (ev) {
  21. // console.log('seeked', ev, this.currentTime)
  22. // Twitter的自动循环播放功能, seek的位置一般在0.02以下
  23. if (this.currentTime < 0.02) {
  24. console.debug('prevent looping', this)
  25. this.pause()
  26. }
  27. })
  28. }
  29. }
  30. }
  31. }
  32. }).observe(document.documentElement, {
  33. childList: true,
  34. subtree: true,
  35. })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址