Better XVideos.com

Always expand video to large size, scroll down to video, use Q W E S to rotate video, allow seeking to 0:00, allow clicking anywhere to start video - 2022-05-16, 19:35:39

  1. // ==UserScript==
  2. // @name Better XVideos.com
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.xvideos.com/video*
  5. // @grant none
  6. // @version 2.4
  7. // @author -
  8. // @description Always expand video to large size, scroll down to video, use Q W E S to rotate video, allow seeking to 0:00, allow clicking anywhere to start video - 2022-05-16, 19:35:39
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. this.$ = jQuery.noConflict(true)
  13.  
  14.  
  15. $("div#video-player-bg").ready(function () {
  16. //
  17. // player = $("div#player-container")
  18. // $("img[title='Double player size']").trigger("click") // only if it's not enlarged already
  19. setTimeout(function () {
  20. if (window.xvideos.player.isEnlarged() === true) { // isEnlarged() is true if it's not enlarged ... well done, xvideos
  21. window.xvideos.player.toggleSize(1)
  22. }
  23. $("div#video-player-bg")[0].scrollIntoView(true)
  24. }, 1000)
  25. })
  26.  
  27. // Somehow, the below didn't work - the button got added, but when clicking it,
  28. // it showed the menu for the next button to the right (originally from xvideos),
  29. // and that button showed the menu for the next one, etc.
  30. //
  31. //$("button#v-actions-overflow-menu").ready(function () {
  32. // var rotation_buttons = `<button class="tab-button rotate-video-right"><span>Rotate video right (E)</span></button>`
  33. // $(rotation_buttons).insertAfter("button#v-actions-overflow-menu")
  34. //})
  35.  
  36. video = $("div#video-player-bg video")[0]
  37.  
  38. //keyboard handler for various things
  39. $("html").ready(function () {
  40. // make whole player clickable to start playing
  41. $("div.video-pic").click(function () { $("div.big-button.play > img").trigger("click") })
  42. // define our keyboard handler
  43. function extra_keyboard_handler(event) {
  44. if (83 == event.keyCode) { // s - turn upside down
  45. $("div.video-bg-pic > video").css("transform", "scaleX(-1) scaleY(-1)")
  46. event.stopImmediatePropagation() // hack to stop the event from being processed by xvideos' original handler
  47. return true
  48. }
  49. if (87 == event.keyCode) { // w - restore upright rotation (no rotation)
  50. $("div.video-bg-pic > video").css("transform", "")
  51. event.stopImmediatePropagation() // hack to stop the event from being processed by xvideos' original handler
  52. return true
  53. }
  54. if (81 == event.keyCode) { // q - rotate 90 degrees to the left - currently BROKEN - also triggers original q binding, i.e. jump 10 seconds to the left
  55. rotation = 270
  56. video = $("div.video-bg-pic > video")[0]
  57. fit_scale = Math.min(video.videoWidth / video.videoHeight, video.videoHeight / video.videoWidth)
  58. transform = `rotate(${rotation}deg) scale(${fit_scale})`
  59. $("div.video-bg-pic > video").css("transform", transform)
  60. event.stopImmediatePropagation() // hack to stop the event from being processed by xvideos' original handler
  61. return true
  62. }
  63. if (69 == event.keyCode) { // e - rotate 90 degrees to the right
  64. rotation = 90
  65. video = $("div.video-bg-pic > video")[0]
  66. fit_scale = Math.min(video.videoWidth / video.videoHeight, video.videoHeight / video.videoWidth)
  67. transform = `rotate(${rotation}deg) scale(${fit_scale})`
  68. $("div.video-bg-pic > video").css("transform", transform)
  69. event.stopImmediatePropagation() // hack to stop the event from being processed by xvideos' original handler
  70. return true
  71. }
  72. if (65 == event.keyCode) { // a - seek left
  73. if (video.currentTime < 10) {
  74. // allow seeking to start
  75. video.currentTime = 0
  76. }
  77. return true
  78. }
  79. if (37 == event.keyCode) { // left arrow - seek left
  80. if (video.currentTime < 10) {
  81. // allow seeking to start
  82. video.currentTime = 0
  83. }
  84. return true
  85. }
  86. return false
  87. }
  88. // attach our keyboard handler - step 1: find old keyboard handler
  89. var xv_keyboard_handler = null
  90. $.each($._data($("html")[0], "events"), function(i, event) {
  91. // i is the event type, like "click"
  92. if (i != "keydown") return
  93. $.each(event, function(j, h) {
  94. // h.handler is the function being called
  95. xv_keyboard_handler = h.handler
  96. })
  97. })
  98. // attach our keyboard handler - step 2: override keyboard handler with our pass-through
  99. $("html").off("keydown", "**") // BROKEN - currently doesn't detach the original listener
  100. $("html").keydown(function(event) {
  101. if((extra_keyboard_handler(event) === false) && (xv_keyboard_handler !== null)) {
  102. xv_keyboard_handler(event) // BROKEN - the original listener fires no matter what
  103. }
  104. })
  105. })