/r/userscripts

Photograph via snooOG

A place for discussion of all things related to userscripts.

A place for discussion of all things related to userscripts.


RELATED:

/r/userscripts

4,802 Subscribers

2

Google Docs live word count

Is it possible to create a userscript to automatically always display the live word count? I was able to use css to force the word count bubble to always appear but I can't get it to show the text with the actual number of words. It seems like the specific element only appears after some script is run when you manually click the checkbox and ok button on the menu screen. I'm not sure if it's possible to even automate this... I've searched for various extensions online and haven't been able to find a solution yet.

https://preview.redd.it/2fviuc2th54e1.png?width=634&format=png&auto=webp&s=d1040795653d19bff5fca472fa7fcc87317fcde0

https://preview.redd.it/80nwnjxuh54e1.png?width=664&format=png&auto=webp&s=0de01a056d53ec421a16cb1e55b9861591f863c6

https://preview.redd.it/bj4p7dq0h54e1.png?width=778&format=png&auto=webp&s=811479dec3b4431d4e8fdd2b1941552676bb6b77

3 Comments
2024/12/01
02:52 UTC

2

Help with userscript to clean up subtitles

I found a userscript on greasyfork that I am trying to change to function on the Amazon Video website. The script was originally for Netflix and I just changed the class name of the subtitles and it worked for Hulu's site, but for some reason I can't get it figured out for Amazon's site. I've tried various different class names, but none seem to work. I'm pretty positive this is the correct element to target. Does anyone have any ideas on why it's not working?

https://preview.redd.it/qqmhmbtqey3e1.png?width=948&format=png&auto=webp&s=91b76b28caa79f9b178e493c1ef4c022c4fae569

// ==UserScript==
// @name        Amazon subtitle cleanup
// @namespace   Violentmonkey Scripts
// @match       https://www.amazon.com/*
// @grant       none
// @version     1.0
// @description Remove all "[inhales]", "[loud noise]" from the subtitles
// @icon        https://upload.wikimedia.org/wikipedia/commons/4/4a/Amazon_icon.svg
// ==/UserScript==

let observed_node = undefined

let kill_song_lyrics = true

const cleanup = (t) => {
  if (kill_song_lyrics && t.includes('♪')) {
    return '' // ignore song lyrics
  } else if (t.includes('[') && t.includes(']')) {
    return t.replace(/(- *)?\[[^\]]+\]/g, '') // (maybe "- ") "[" .. (not "]")+ .. "]"
  } else if (t.includes('(') && t.includes(')')) {
    return t.replace(/(- *)?\([^\)]+\)/g, '') // (maybe "- ") "(" .. (not ")")+ .. ")"
  }

  return t
}

const on_mutated = (changes) => {
  const ts = observed_node.querySelectorAll('atvwebplayersdk-captions-text')
  for (let i = 0; i < ts.length; i++) {

    const t = ts[i].innerHTML
    const nt = cleanup(t)

    if (nt !== t) {
      ts[i].innerHTML = nt
      // console.log({ original: t, filtered: nt })
    }
  }
}

const observer = new MutationObserver(on_mutated)

const reobserve = () => {
  const elems = document.getElementsByClassName('atvwebplayersdk-captions-text')
  if (elems[0] !== undefined) {
    if (observed_node !== elems[0]) {
      observed_node = elems[0]
      console.log({ observed_node })
      observer.observe(observed_node, { childList: true, subtree: true})
    }
  }
  window.setTimeout(reobserve, 100)
}


const run_tests = () => {
  // the tests are lightning fast, so just do run them quickly on every script startup
  const test_cleanup = (source, expected) => {
    console.assert(cleanup(source) === expected, { test_result: false, source, expected, actual: cleanup(source) })
  }
  test_cleanup('normal text', 'normal text')
  test_cleanup('[coughs]', '')
  test_cleanup('[coughs] yeah', ' yeah')
  test_cleanup('-[coughs]', '')
  test_cleanup('- [coughs]', '')
  test_cleanup('- (inhales)', '')
  test_cleanup('some ♪ singing', '')
  console.log('tests ok')
}


console.log('Netflix subtitle filter userscript starting up')
run_tests()
reobserve()

4 Comments
2024/11/30
02:58 UTC

3

Need help with bookmarklet /script

I use Google keep a lot but their extension don't work anymore . So can anyone create a bookmarklet/script for me so when a user highlight a text on a webpage and click the button on bookmarklet or script . It will save the highlighted text with their respective webpage URL to google keep. I dunno coding, i asked chat gpt but all in vain

P.S. Google keep- (keep.google.com), (note.new)

2 Comments
2024/11/28
15:09 UTC

3

Why I can load function on some sites (e.g. reddit) but not others (e.g. github)? Advice on how to fix it?

So I'm trying to create a function in my userscript and make it available to be called on the dev console in Firefox. While attempting to do so on github, I was running into issues with this and since I have done it tons of times in the past on other sites, I had assumed I had mucked something up in my script. But even boiling it down to really basic snippets, I still can't get it to work. Any help?

// ==UserScript==
// @name        reddit-test
// @namespace   Violentmonkey.github-test
// @include     /https:\/\/(old|new|www)?\.?reddit.com(\/r\/userscripts)?\/?$/
// @grant       none
// @version     1.0
// @author      -
// @description add function to page and make it callable from firefox dev console
// ==/UserScript==
let myfunc = function(selector) {
  let elems = document.querySelectorAll(selector);
  return elems;
}
window.myfunc = myfunc;

And then running that on reddit, I get the following in the dev console

myfunc('#header').length
1 

Taking the same thing and making a new script for gitub (e.g. just name and include are changed)

// ==UserScript==
// @name        github-test
// @namespace   Violentmonkey.github-test
// @include     /https:\/\/github.com\/?$/
// @grant       none
// @version     1.0
// @author      -
// @description add function to page and make it callable from firefox dev console
// ==/UserScript==
let myfunc = function(selector) {
  let elems = document.querySelectorAll(selector);
  return elems;
}
window.myfunc = myfunc;

Then running on github homepage, I get the following in dev console (note: script appears on Violent Monkey icon console.log so the @include is ok and console.log statements show up and functions seem to work within the context of the userscript so I can do things like grab element text / update document title / etc but it appears to be blocked from adding the function to the window / showing up in the dev console for some unknown reason).

myfunc('.AppHeader').length
Uncaught ReferenceError: myfunc is not defined
    <anonymous> debugger eval code:1

I notice that the dev console on github has a a lot of errors about Content-Security-Policy and similar even when Violent Monkey is completely disabled. However, I am still able to manually create functions under the window object from dev console (e.g.):

>> window.myfunc = function() { console.log('success'); };
function myfunc()
 
>> myfunc()
success

I would normally assume that this is something related CORS / cross-site scripting but would that even apply for userscripts that are simply operating on the page without loading things from other domains (e.g. not importing libraries from a cdn like jQuery / etc but just plain vanilla JS, entirely self-contained in the userscript)?

I've been searching for about an hour already and I am as stumped as when I started. I used to be moderately ok with javascript once upon a time but haven't kept up with things over the last 5 or so years. Hoping someone who is more current than me can help shed some light and offer advice on how on to make my userscript functions available via the dev console.

edit: obviously, the function above is just a simple example that I am using for testing. The final function that I plan to add will be significantly more complex but want to stomp out this issue before I continue.

edit 2: even stranger, I just retested the github userscript under chromium + VM and it actually works as expected over there (no modification). So I guess I need to test if this is a) due to some other setting/addon, b) some issue with github not liking FF, b) some VM+FF specific bug or limitation... I guess at least I'm not going crazy but would have been nice if it "just worked".

9 Comments
2024/11/25
06:13 UTC

1

[Request] Redirect Gyazo image page directly to file

Is it possible to do a script to redirect Gyazo images directly to file? I'm currently using Redirector to do it, but it doesn't work if the image is jpg or webp, also I have to press f5 for the redirection to work.

2 Comments
2024/11/23
07:16 UTC

1

Need some pointers

I want to write a script that scans links in a page and sends some of them to a url. I can do this myself but I have two questions:

  1. The url will always be foreign to the current url, so, are there cors restrictions for http requests, or can I make http requests to arbitrary urls? Should I use xhr or fetch?

  2. I need to send all links exactly once so I need to store the ones I've sent already. This must survive across browser restarts. Is there some storage, preferably k/v like localstorage that is shared among all websites?

Thanks

7 Comments
2024/11/21
19:39 UTC

3 Comments
2024/11/20
07:55 UTC

2

Request - Automatically shows more Subscriptions in the sidebar

Hi!

Can someone help me create a script that automatically expands "Show more" in the youtube sideba. I found this script but it no longer works. I tried to edit it but unfortunately I'm not good at javascript

YouTube - automatically expand subscription list

Thanks in advance for reading.

6 Comments
2024/11/10
07:58 UTC

2

Request - Override ArtStation Gallery Hover for Multi-image Icon

Recently Artstation has made a bizarre change in making a once persistent icon that shows if a gallery has multiple images to one that shows up on mouse hover.

Example gallery https://www.artstation.com/felixriano

Before Hover

After Hover (note the image preview hover is a extension)

It appears that simply changing a style from display: none to display: block lets the icon appear. But it has been many years since I've worked on this stuff and I am unsure how to apply this.

Example - Display: block;

I am not sure how to target the entire gallery in a way that the icon is persistent despite any new instances of the mouse hovering over a thumbnail. As with just changing the display from none to block is only temporary till you hover over the thumbnail.

2 Comments
2024/11/09
00:42 UTC

5

Unique colors for reddit users

This script assigns a unique background color to each username based on their name. Makes it easier to differentiate users on the page (only works in old.reddit)

// ==UserScript==
// @name         Random Colors for Users On Reddit
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://old.reddit.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// ==/UserScript==

let authorColors = new Map();

function Main() {
    let _authors = document.getElementsByClassName('author');
    for (let i = 0; i < _authors.length; i++) {
        let authorName = _authors[i].innerText;

        if (!authorColors.has(authorName)) {
            let color = stringToColour(authorName);
            authorColors.set(authorName, color);
            _authors[i].style.color = color;
        } else {
            _authors[i].style.color = authorColors.get(authorName);
        }
    }

    setTimeout(Main, 500);
}

function stringToColour(str) {
    let hash = 0;
    for (let i = 0; i < str.length; i++) {
        hash = str.charCodeAt(i) + ((hash << 5) - hash);
    }
    let colour = '#';
    for (let i = 0; i < 3; i++) {
        let value = (hash >> (i * 8)) & 0xFF;
        colour += ('00' + value.toString(16)).substr(-2);
    }
    return colour;
}

Main();
2 Comments
2024/11/06
01:00 UTC

2

Fixing YTM speed playback script

I recently found this userscript that adds a speed playback to yt music, I love it, however I have two problems, I would like to disable the pitch correction when changing the speed, I tried this but it didn't work.

(function() {
    'use strict';

    const originalPlaybackRate = HTMLMediaElement.prototype.playbackRate;

    Object.defineProperty(HTMLMediaElement.prototype, 'playbackRate', {
        set(value) {
            // Set the playback rate without pitch correction
            this.defaultPlaybackRate = value;
            this.playbackRate = value;
        },
        get() {
            return originalPlaybackRate.get.call(this);
        }
    });
})();

The second thing is that when I click to change the speed it also clicks on the player and it closes and I don't know how to fix it.

1 Comment
2024/11/04
12:53 UTC

2

My script only works when I manually reload page.

I prefer to view/read Reddit via new.reddit.com interface, but do all the moderation stuff from reddit.com (aka sh.reddit.com) version. This includes the mod queue, which I open by clicking the little shield icon and selecting 'Mod Queue' there. It opens https:///new.reddit.com/r/mod/about/modqueue and I want to use https://www.reddit.com/mod/queue, so I wrote this very basic script:

// ==UserScript==
// @name         Always New ModQueue
// @namespace    9bf36c681d35d52913b3bda74ddf6127318ed7b0
// @version      0.1
// @description  Forces opening mod queue in sh.reddit
// @author       /u/eftepede
// @match        *://new.reddit.com/r/mod/about/modqueue
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
	'use strict';
	top.location.replace("https://www.reddit.com/mod/queue");
})();

Unfortunately, it doesn't work when I click the icon (or even right-click it and try opening in a new tab). I always get the new.reddit... page, but when I refresh it via standard Ctrl+r, the redirection works.

What am I doing wrong?

6 Comments
2024/11/03
23:34 UTC

4

Request: A userscript for Old Reddit to embed pictures in a comment for subreddits that allow to link pictures

Hi!

I'm aware that there's subreddits that allow users to upload pictures in a post directly. However, this feature seems to be restricted to the new/beta Reddit design though, which I don't really like. It's a lot more wasteful in terms of how much meaningful content is packed at any given time on screen.

So yeah, I figured I'd check over here and see if anyone could make a userscript that allows something like drag-and-dropping an image into the comment box on Old Reddit to post images directly, to avoid constantly having to go back and forth between the new and the old Reddit designs.

Thanks in advance for reading.

2 Comments
2024/11/03
18:08 UTC

7

cobalt.tools

https://preview.redd.it/6u42frgls2yd1.png?width=1000&format=png&auto=webp&s=6a7a95dbf9212fe902d921b010a377e38260f7a4

An unofficial script collection created using the cobalt.tools API.

Get the script here! or Here!

Currently available scripts:

  1. Direct YouTube Audio Downloader
  2. Direct YouTube Video Downloader
  3. YouTube Direct Downloader
  4. SoundCloud Direct Downloader
  5. YouTube Bulk Downloader
  6. YouTube Playlist Downloader

https://github.com/exyezed/cobalt-tools

0 Comments
2024/10/31
11:08 UTC

3

Fix missing keys in Google Sheets using Scandinavian keyboard layout on MacOS

When using Google Sheets on MacOS with a Scandinavian keyboard layout, it unfortunately hijacks several keyboard combinations required to type in crucial characters, such as $, { and }.

I made this workaround to allow typing in the missing characters and have been using it a while with great effect.

The workaround may work for other country-specific keyboard layouts. It’s been very thoroughly been tested with the Danish keyboard.

Note: Google Sheets use these keys for range selecting etc. and those functions are not remapped to other keyboard combinations. Not a loss at all, IMHO.

https://gist.github.com/f-steff/ace84434e1ee4e1107bcf0ba8d72ed2b

0 Comments
2024/10/29
10:38 UTC

0

youtube skipping forward thru video after video (pretty sure one of these userscripts is the culprit, but which one??)

ok, i'm pretty sure that you guys are going to pile on and eviscerate me for asking this, but I've got a number of userscripts running for youtube - normally everything is fine/great. All of a sudden (translation: no idea why; didn't change anything) it is playing 5 seconds of each track and skipping to the next one in the queue or playlist - whichever you're in! SO unbelievably frustrating. I've tried disabling all the scripts and turning them on one at a time, but as soon as I get the two functions i require (working ad skip+local download) - here comes the bullshit skipping. I'm in Edge. Also tried turning on dev tools, hoping I could figure out how to get it to stack trace in realtime, but honestly, I don't know how to use this very well. All my debugging/QA experience is multi decades old. I'm hoping that after I wade through the 35 oblgatory assholes calling me every kind of stupid for asking the question, some kind person will have perhaps heard of this behavior and tell me how to get it to stop. Thanks!

2 Comments
2024/10/29
07:37 UTC

15

Spotify Enhancer

https://preview.redd.it/wltdy73j2exd1.png?width=1000&format=png&auto=webp&s=ab4d0e7c5d0025d024c1897ebda06db28204616d

Spotify Enhancer is a set of userscripts that enhance the Spotify Web Player.

Get the script here! or Here!

Currently available scripts:

  1. Full-Sized Cover Art Downloader
  2. Copy Track Info, ID & Link
  3. Cover Art Bulk Downloader

https://github.com/exyezed/spotify-enhancer

0 Comments
2024/10/28
00:07 UTC

2

Ad maven bypasser script

I'm using voilent monkey in kiwi browser (android), i want to bypass NSFW links but when i use bypasser script it bypasses but redirects to a scam video page and not the actual content is there and script that works as good as bypass.city??

3 Comments
2024/10/22
13:36 UTC

16

YouTube Enhancer

https://preview.redd.it/gbt10czk1exd1.png?width=1000&format=png&auto=webp&s=0b0ea008949d352f87b958a8df33df2de89ebee6

YouTube Enhancer is a set of userscripts that enhance your YouTube experience.

Get the script here! or Here!

Currently available scripts:

  1. Reveal Channel ID
  2. Full-Sized Image Preview
  3. Shorts Thumbnail
  4. Loop & Screenshot Button
  5. Reveal Views & Upload Time
  6. Extras
  7. Reveal Video Category
  8. Channel Video Counters
  9. Secret Stats
  10. Video Secret Stats
  11. Reveal Country Flag
  12. Real-Time Subscriber Count
  13. Subtitle Downloader

https://github.com/exyezed/youtube-enhancer

3 Comments
2024/10/19
05:53 UTC

3

Trying to highlight specific words on a page

Hi all, brand new to Userscripts and terrible at code.

I am trying to find a way to highlight specific words or characters on an HTML/CSS/JS page in Safari. Has to be Safari due to company requirements.

A good example of what I want to do it like the find command. I found Multi Find for other browsers and that’s almost perfect but doesn’t work in Safari

I’m trying to highlight things like “.co” “app.” Or “+44” these are often mid line so only wanting to highlight parts of elements.

Unfortunately I can’t upload an example of the page for privacy reasons, but would really appreciate and guidance, dumbed way down if possible.

Is Userscripts the right tool to even be looking at?

4 Comments
2024/10/14
06:54 UTC

2

Seeking support in porting TeXMail-Gmail to work with Outlook.

I've recently been directing the development of TeXSend, which is intended to eventually be a suite of userscripts for adding LaTeX compiling to popular email services. Right now, TeXSend-Gmail is in a good place, and I'd like to port this over to work with Outlook.

The programmer who I've relied on for the majority of the coding for TeXSend-Gmail has some other responsibilities that they need to attend to for a while, and so will be unavailable to continue working on this. I'm hoping to find someone who is able to work on this port. I'm able to do testing and minor JS adjustments, but I'm far from a skilled JS programmer myself.

I need to clarify, this is non-profit work being distributed under an MIT license. As such, I cannot offer any compensation other than credit as a contributor. This is a suite that will hopefully prove beneficial to many people in STEM (academia in particular), and I hope that alone is sufficient encouragement for someone to volunteer.

Thank you.

Note: Title should have said "TeXSend". "TeXMail" was a working title.

2 Comments
2024/10/01
01:03 UTC

5

Google Maps Reviews Scraper & Exporter

Google Maps Reviews Scraper & Exporter

This user script adds a floating panel to Google Maps place pages, allowing you to scrape and export reviews easily.

URL: https://greasyfork.org/en/scripts/510952-google-maps-reviews-scraper-exporter

Screenshot

Features

  • Floating panel for easy access
  • Auto-scrolling to load all reviews
  • Expansion of truncated reviews
  • JSON export of scraped data
  • Clipboard integration for quick copying

Usage

  1. Navigate to a Google Maps place page
  2. Click "Scrape Reviews" to gather all visible reviews
  3. Click "Copy to Clipboard" to export the data as JSON

Screenshot

Google Maps Reviews Scraper & Exporter in Action

Data Collected

For each review, the script collects:

  • Reviewer name
  • Profile Image URL
  • Review date
  • Star rating
  • Review URL
  • Full review content

Notes

  • This script is for educational purposes only
  • Be respectful of website terms of service and use responsibly
  • Large numbers of requests may be rate-limited by Google

Enjoy more accessible access to Google Maps review data with this handy user script!

3 Comments
2024/09/30
20:09 UTC

1

Please help sending keystroke and a click in a loop

I have a very specific use case for a tampermonkey userscript. I need an inactive tab on my firefox browser to get a looping key presses and mouse clicks at a specific coordinate while I browse the net on another tab. Is this possible?

Obviously, this is for some idle game that I am running in a background tab while I do something else. Idle Wizard on kongregate is what I'm playing.

More specifically, the parameters I need are something like this.

Every 5 seconds:

  1. Sends a mouse clicks on coordinates 830, 750.
  2. Send keystroke arrow down.
  3. Send keystroke b.

Loop this indefinitely until i disable it.

I tried to do it on AHK which has a simplified code that a random dude like me can understand, but I'm finding that AHK cannot really distinguish a specific firefox tab that is running in the background. As for userscript code system, it's way too complicated for me to understand without any programming knowledge.

2 Comments
2024/09/30
00:08 UTC

2

Why does only this one shortcut work in a Gmail userscript?

Edit: Solved! See comments.

function addShortcuts() {
    const keyHandler = (e) => {
        if (e.shiftKey && e.code === 'KeyL') {
            toggleLatex()
        } else if (e.shiftKey && e.code === 'Slash') {
            waitForElement('body > div.wa:not(.aou) > div[role=alert]', 5).then(d => {
                const xpath = '//tr[th/text()="Formatting"]/following-sibling::tr';
                const row = document.evaluate(xpath, d, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
                const html = '<td class="wg Dn"><span class="wh">Shift</span> <span class="wb">+</span> <span class="wh">L</span> :</td><td class="we Dn">Toggle LaTeX</td>';
                row.innerHTML = html;
            });
        }
    }

    window.addEventListener('keypress', keyHandler);
}

I can make this "shift + [alphanumeric]", but nothing else actually works.

I'd particularly like like do "ctrl+alt+L".

The userscript in question: https://github.com/LoganJFisher/LaTeX-for-Gmail

11 Comments
2024/09/26
23:34 UTC

0

A custom channel remover for youtube using localStorage

https://termbin.com/o01j

If you want the buttons to look prettier you can edit the add_button function

0 Comments
2024/09/16
23:48 UTC

2

[Request] MathJax for Gmail

Edit: This has gradually evolved into this project: https://github.com/LoganJFisher/LaTeX-for-Gmail?tab=readme-ov-file


I'm looking to find a way to add LaTeX equation rendering to Gmail in Firefox. Could someone create such a userscript please?

I've tried searching for Gmail add-ons, Firefox extensions, and userscripts (using Greasemonkey and ViolentMonkey). I even tried editing the MathJax for Reddit userscript by changing its @match URL to https://mail.google.com/*, but that didn't work (the script triggers, but doesn't solve the issue).

I just need a solution that can handle equations. I don't need it to be capable of rendering whole documents right in Gmail. I need it to be for Firefox though, not Chrome.

Example: If you look at the sidebar of /r/askphysics, you'll see this. If you install the userscript "MathJax for Reddit" that they recommend, you'll then instead see this. I want the same thing for sent and received emails viewed on https://mail.Google.com

I'm getting desperate and frustrated that my attempts keep failing ad I don't understand why.

15 Comments
2024/09/16
22:40 UTC

11

FuckYou logo on YouTube

Replace the YouTube logo with a custom logo styled to resemble the original logo but with the text “FuckYou” or "Fuck YouTube".

Fuck YouTube - https://greasyfork.org/en/scripts/508890-youtube-logo

FuckYou - https://greasyfork.org/en/scripts/508696-you-logo-on-youtube

https://preview.redd.it/ebclhler9epd1.png?width=206&format=png&auto=webp&s=a66ab05a74b7cd38528c684aa20ca45d701d6308

5 Comments
2024/09/16
13:40 UTC

18

IMDB Movie - Watch any movie directly in IMDB

Tried making my first user script (i had few for personal use before), let me know if I made any mistakes or if this kind of scripts even allowed or not lol.

https://preview.redd.it/kwztmxwcoiod1.png?width=1920&format=png&auto=webp&s=4de63b8847bd0669d51541b4e036bad25294cc58

https://i.redd.it/v1m0augboiod1.gif

Link: https://greasyfork.org/en/scripts/508237-imdb-movie

10 Comments
2024/09/13
06:00 UTC

2

[Help] Instagram video control userscript.

3 Comments
2024/09/12
19:14 UTC

Back To Top