Sex.com Autoplay Videos

Autoplays videos on sex.com/videos, similar to scrolller.com. Features: Autoscroll, Toggle Mute All, Play Audio on Visible Videos only, Set Scroll Speed.

  1. // ==UserScript==
  2. // @name Sex.com Autoplay Videos
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-08-26
  5. // @description Autoplays videos on sex.com/videos, similar to scrolller.com. Features: Autoscroll, Toggle Mute All, Play Audio on Visible Videos only, Set Scroll Speed.
  6. // @match https://www.sex.com/videos/*
  7. // @author You
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=sex.com
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. //match:
  19.  
  20. // Append the button to the buttonContainer container
  21.  
  22. // Default settings
  23. const defaultSettings = {
  24. scroll: false,
  25. scrollSpeed: 0.1,
  26. muteAll: true,
  27. audioOnVisible:false
  28. };
  29.  
  30. // Load settings or use defaults
  31. const settings = {
  32. muteAll: GM_getValue('muteAll', defaultSettings.muteAll),
  33. scroll: GM_getValue('scroll', defaultSettings.scroll),
  34. scrollSpeed: GM_getValue('scrollSpeed', defaultSettings.scrollSpeed),
  35. audioOnVisible: GM_getValue('audioOnVisible', defaultSettings.audioOnVisible)
  36. };
  37.  
  38. // Function to update and save settings
  39. function updateSettings(key, value) {
  40. GM_setValue(key, value);
  41. settings[key] = value;
  42. //alert(`${key} is now set to ${value}`);
  43. }
  44.  
  45. // Function to navigate to a new page and run code after it loads
  46. function navigateAndRun(url, callback) {
  47. // Navigate to the new URL
  48. window.location.href = url;
  49.  
  50. // Wait until the new page has fully loaded
  51. window.onload = function() {
  52. // Code to run after the page has loaded
  53. callback();
  54. };
  55. }
  56.  
  57.  
  58.  
  59.  
  60. function toggleMute(){
  61. console.log(GM_getValue('muteAll'));
  62.  
  63.  
  64. const videos = document.querySelectorAll('video');
  65. videos.forEach(video => {
  66. video.muted = settings.muteAll;
  67. video.play();
  68. });
  69. }
  70.  
  71. // Function to unmute only visible videos
  72. function unmuteVisibleVideos() {
  73. const videos = document.querySelectorAll('video');
  74.  
  75. // Create an IntersectionObserver to detect visible videos
  76. const observer = new IntersectionObserver((entries) => {
  77. entries.forEach(entry => {
  78. if (entry.isIntersecting) {
  79. // Video is visible, unmute it
  80. entry.target.muted = false;
  81. } else {
  82. // Video is not visible, mute it (optional)
  83. entry.target.muted = true;
  84. }
  85.  
  86. if(settings.audioOnVisible === false){
  87. observer.disconnect();
  88. entry.target.muted = true;
  89. }
  90. });
  91. }, { threshold: 0.5 }); // Adjust threshold as needed
  92.  
  93. // Observe each video
  94. videos.forEach(video => {
  95. observer.observe(video);
  96. });
  97.  
  98.  
  99. }
  100.  
  101. function unmuteVisibleVideosGPT(){
  102. let cooldown = 0;
  103. let muted = false;
  104.  
  105. document.body.onscroll = function () {
  106. if (muted) {
  107. return;
  108. }
  109.  
  110. if (Date.now() - cooldown < 250) {
  111. return;
  112. }
  113. cooldown = Date.now();
  114.  
  115. let diffMin = Infinity;
  116. let nearest;
  117. let middle = window.innerHeight / 2;
  118.  
  119. document.querySelectorAll("video").forEach(video => {
  120. // Mute all videos by default
  121. video.muted = true;
  122.  
  123. // Calculate the difference between the video's center and the viewport's middle
  124. const rect = video.getBoundingClientRect();
  125. const elemMiddle = rect.y + (rect.height / 2);
  126. const diff = Math.abs(middle - elemMiddle);
  127.  
  128. // Find the video closest to the middle of the viewport
  129. if (diff < diffMin) {
  130. diffMin = diff;
  131. nearest = video;
  132. }
  133. });
  134.  
  135. // If the closest video is within the viewport, unmute it
  136. if (nearest && diffMin <= middle) {
  137. nearest.muted = false;
  138. }
  139. };
  140.  
  141. // Optional: To automatically trigger this check periodically, not just on scroll
  142. let interval = window.setInterval(() => {
  143. document.body.onscroll();
  144. }, 500); // Check every 500ms
  145.  
  146. }
  147.  
  148. // Function to automatically scroll down the screen
  149. function autoScroll(scrollSpeed) {
  150.  
  151. // Convert scrollSpeed to an appropriate pixel value per interval
  152. const speed = scrollSpeed * 10; // Adjust multiplier as needed for desired speed
  153. console.log(speed);
  154.  
  155. // Start scrolling at the defined speed
  156.  
  157. if(settings.scroll === true){
  158. const scrollInterval = setInterval(() => {
  159. // Scroll down by the calculated speed
  160. window.scrollBy(0, speed);
  161.  
  162. // Optional: Stop scrolling when reaching the bottom of the page
  163. if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight || settings.scroll === false) {
  164. clearInterval(scrollInterval);
  165. }
  166.  
  167. if((window.innerHeight + window.scrollY) >= document.body.scrollHeight){
  168. console.log("bottom of screen")
  169. switchNextPage();
  170. }
  171. }, 10); // Interval in milliseconds (100ms is a common choice)
  172.  
  173. }
  174.  
  175. }
  176.  
  177. function switchNextPageOld(){
  178. console.log("inside switch next page");
  179. const url = window.location.href;
  180. console.log(url);
  181. const match = url.match(/www\.\w+\.com\/videos\/\?page=(\d+)/);
  182.  
  183.  
  184. let nextPageNumber = 1;
  185. if(url === "https://www.sex.com/videos/"){
  186. nextPageNumber = 2;
  187. }else if(match){
  188. const pageNumber = parseInt(match[1]);
  189. console.log(pageNumber); // Outputs: 123
  190. nextPageNumber = pageNumber+1;
  191. console.log(nextPageNumber);
  192. }
  193.  
  194. navigateAndRun(`http://www.sex.com/videos/?page=${nextPageNumber}`, function() {
  195. console.log('The new page has loaded!');
  196. });
  197. }
  198.  
  199. function switchNextPage() {
  200. console.log("inside switch next page");
  201. const url = window.location.href;
  202. console.log(url);
  203.  
  204. function getNextPageUrl(url) {
  205. // Match the current page number, if it exists
  206. const match = url.match(/(\?|&)page=(\d+)/);
  207.  
  208. let nextPageNumber = 2; // Default to page 2 if no page number is found
  209.  
  210. if (match) {
  211. const currentPageNumber = parseInt(match[2]);
  212. nextPageNumber = currentPageNumber + 1;
  213.  
  214. // Replace the existing page number with the next page number
  215. return url.replace(/(\?|&)page=\d+/, `$1page=${nextPageNumber}`);
  216. } else {
  217. // If no page number exists, append ?page=2 or &page=2 based on the presence of other parameters
  218. return url.includes('?') ? `${url}&page=2` : `${url}?page=2`;
  219. }
  220. }
  221.  
  222. const newUrl = getNextPageUrl(url);
  223.  
  224. navigateAndRun(newUrl, function() {
  225. console.log('The new page has loaded!');
  226. });
  227. }
  228.  
  229.  
  230.  
  231.  
  232.  
  233. function startupSettings(){
  234. if(settings.scroll === true){
  235. autoScroll(settings.scrollSpeed);
  236. }
  237.  
  238. if(settings.muteAll === false){
  239. toggleMute();
  240. }
  241.  
  242. if(settings.audioOnVisible === true){
  243. unmuteVisibleVideos();
  244. }
  245.  
  246. }
  247.  
  248.  
  249.  
  250. // Register menu commands
  251. GM_registerMenuCommand(`Toggle Mute All`, ()=>{updateSettings('muteAll', !settings.muteAll); toggleMute();});
  252.  
  253. GM_registerMenuCommand(`Toggle Auto Scroll`, ()=>{
  254. updateSettings('scroll', !settings.scroll);
  255. autoScroll(settings.scrollSpeed);
  256. });
  257.  
  258. GM_registerMenuCommand(`Set Scroll Speed`, () => {
  259. const newVolume = prompt('Set scroll speed (0.0 to 1.0):', settings.scrollSpeed);
  260. if (newVolume !== null && newVolume >= 0 && newVolume <= 1) {
  261. updateSettings('scrollSpeed', parseFloat(newVolume));
  262. settings.scroll = false;
  263. autoScroll(settings.scrollSpeed);
  264. } else {
  265. alert('Invalid speed value!');
  266. }
  267. });
  268.  
  269. GM_registerMenuCommand(`Toggle Play Audio in Viewport`, ()=>{
  270. updateSettings('audioOnVisible',!settings.audioOnVisible);
  271. //settings.muteAll = true;
  272. //toggleMute();
  273. unmuteVisibleVideos();});
  274.  
  275. console.log("hello world!");
  276.  
  277. function replacePreviewsWithVideos() {
  278.  
  279. console.log("inside replacePreviewsWithVideos");
  280.  
  281. // Replace '.preview' with the actual selector that identifies preview elements
  282. const previewElements = document.querySelectorAll(".image_wrapper");
  283. //console.log(previewElements);
  284.  
  285. previewElements.forEach((preview) => {
  286. // Extract the video page URL from the preview element
  287. const videoPageURL = preview.getAttribute("href"); // Replace this with the actual way to get the URL
  288.  
  289. //console.log(videoPageURL);
  290.  
  291. if (videoPageURL) {
  292. fetch(videoPageURL)
  293. .then((response) => response.text())
  294. .then((data) => {
  295. //console.log(data);
  296. const urlMatch = data.match(/src:\s*'(https:\/\/[^']+\.mp4)'/);
  297. let url = "";
  298. if (urlMatch) {
  299. url = urlMatch[1]; // This contains just the URL
  300. //console.log(url); // Output: "https://example.com/video.mp4"
  301. }
  302.  
  303. const videoElement = document.createElement("video");
  304. if (videoElement) {
  305.  
  306. videoElement.src = url;
  307. videoElement.autoplay = true;
  308. videoElement.controls = true;
  309. videoElement.muted = true;
  310. videoElement.loop = true;
  311. videoElement.style.width = "100%";
  312.  
  313. preview.innerHTML = "";
  314. preview.appendChild(videoElement);
  315. preview.removeAttribute("href");
  316. }
  317. else {
  318. console.log(
  319. "Video source not found on video page:"
  320. );
  321. }
  322. })
  323. .catch((error) => console.log("Error fetching video page:", error));
  324. }
  325. });
  326.  
  327. startupSettings();
  328. }
  329.  
  330. // Run the function after the page has loaded
  331. window.addEventListener("load", replacePreviewsWithVideos);
  332.  
  333. })();