Skip to content

Instantly share code, notes, and snippets.

@aetonsi
Last active December 27, 2023 10:26
Show Gist options
  • Save aetonsi/cfd96b3e8cf2d07a86a5a973f834df1d to your computer and use it in GitHub Desktop.
Save aetonsi/cfd96b3e8cf2d07a86a5a973f834df1d to your computer and use it in GitHub Desktop.

Revisions

  1. aetonsi revised this gist Dec 27, 2023. 1 changed file with 11 additions and 14 deletions.
    25 changes: 11 additions & 14 deletions ScrolllerRedirectwithURLCondition.user.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    // ==UserScript==
    // @name Scrolller Redirect with URL Condition
    // @name Scrolller Redirect with NO NAV
    // @namespace https://your-namespace.example.com/
    // @version 1.0
    // @description Redirects to the media URL on Scrolller.com after waiting for the element to appear (if URL does not match)
    // @description Redirects to the media URL on Scrolller.com after waiting for the element to appear (excluding URLs with ?NONAV and scrolller.com/r/*)
    // @author YourName
    // @match https://scrolller.com/*
    // @exclude https://scrolller.com/r/*
    @@ -15,22 +15,19 @@
    const intervalTime = 1000; // Interval time in milliseconds (adjust if needed)
    let intervalId;

    function qMarked(arg, page=location.href) { return page.includes('?') ? `&${arg}` : `?${arg}` }

    function redirectToMedia() {
    if (!window.location.href.includes('/r/')) {
    const mediaElement = document.querySelector('.fullscreen-view__media');
    if (mediaElement) {
    const mediaSrc = mediaElement.src;
    if (mediaSrc) {
    location.href = mediaSrc;
    clearInterval(intervalId); // Stop the interval once redirected
    }
    const mediaElement = document.querySelector('.fullscreen-view__media');
    if (mediaElement) {
    const mediaSrc = mediaElement.currentSrc;
    if (mediaSrc) {
    clearInterval(intervalId); // Stop the interval once redirected
    const m = mediaSrc + qMarked(`from=${encodeURIComponent(location.href)}`, mediaSrc); // save the previous URL in the "url" query param
    location = m; // navigate
    }
    } else {
    clearInterval(intervalId); // Stop the interval if URL matches /r/
    }
    }

    intervalId = setInterval(redirectToMedia, intervalTime);
    })();

    // thanks chatgpt!
  2. aetonsi created this gist Dec 27, 2023.
    36 changes: 36 additions & 0 deletions ScrolllerRedirectwithURLCondition.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    // ==UserScript==
    // @name Scrolller Redirect with URL Condition
    // @namespace https://your-namespace.example.com/
    // @version 1.0
    // @description Redirects to the media URL on Scrolller.com after waiting for the element to appear (if URL does not match)
    // @author YourName
    // @match https://scrolller.com/*
    // @exclude https://scrolller.com/r/*
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    const intervalTime = 1000; // Interval time in milliseconds (adjust if needed)
    let intervalId;

    function redirectToMedia() {
    if (!window.location.href.includes('/r/')) {
    const mediaElement = document.querySelector('.fullscreen-view__media');
    if (mediaElement) {
    const mediaSrc = mediaElement.src;
    if (mediaSrc) {
    location.href = mediaSrc;
    clearInterval(intervalId); // Stop the interval once redirected
    }
    }
    } else {
    clearInterval(intervalId); // Stop the interval if URL matches /r/
    }
    }

    intervalId = setInterval(redirectToMedia, intervalTime);
    })();

    // thanks chatgpt!