Super easy PornHub downloads, no 3rd party apps

I posted this as a reply to an existing thread a couple of years ago and while revisiting the topic I realized I didn’t format the code to make it easy to copy and paste so I am adding it again in its own thread. You need the TamperMonkey extension to run this. It will automatically add links to all discovered resolutions for any given video on * or * All you need to do is install the tampermonkey extension and paste this script to it. Once set up you shouldn’t need to mess with it.

With the script installed you should see links below the video title:


You right click the link and save as or click to open in a new tab (right click and save as from there). I had to whitelist it in my adblocker to get it to work.

// ==UserScript==
// @name         Pornhub Downloader
// @namespace    lancaster
// @version      0.5
// @description  try to take over the world!
// @author       theekaffe
// @match*
// @match       *://*
// @match       *://**
// @match       *://*
// @match
// @match*
// @match       *://*
// @match       *://**
// @match       *://*
// @grant        test
// @grant        GM.xmlHttpRequest
// ==/UserScript==

let [id, flashvars] = Object.entries(unsafeWindow).find(([key, value]) => /^flashvars_\d+$/.test(key)) || [null, null];

var medias = flashvars.mediaDefinitions
var videoName = flashvars.video_title

for (var key in medias) {
    var reg = new RegExp("https:\/\/([a-zA-Z0-9]+)\.pornhub(premium)?.com\/video\/get_media\?.+")
    if (reg.test(medias[key].videoUrl)) {
            method: "GET",
            url: medias[key].videoUrl,
            responseType:   "json",
            onload: function(xhr) {
                var mp4files = JSON.parse(xhr.responseText)

//Make button
var element = document.getElementsByClassName("ratingInfo")[0];

for (var key in mp4files) {
    if (mp4files[key].format == "mp4") {
    var link = document.createElement("a");
    link.setAttribute('target', '_blank');
    link.setAttribute('rel', 'noopener noreferrer');
    link.setAttribute('href', mp4files[key].videoUrl);
    link.setAttribute('download', videoName);
    link.textContent = mp4files[key].quality;
    var space = document.createElement("a");
    space.textContent = " "



lol. NO 3RD PARTY APPS…needs this 3rd party app… :stuck_out_tongue:


Technically, but it is a browser extension… you don’t need to fire up another app like jdownloader to use it.

hehe yeah i’m just playing :slight_smile:

i like it being options below the video, would be great if yt-dlp had something like this to utilise their massive database.

1 Like

This line gives me an error - // @grant test
It says “eslint: userscripts/no-invalid-grant - ‘test’ is not a valid @grant argument”

Perhaps try removing that line (although I suspect it would break the script). I didn’t write this script and I have no Tampermonkey scripting knowledge, I simply got permission from the creator to share it. I wish I could help more.

Here is the documentation about @grant but without any TM scripting/API knowledge I don’t know what to say about correcting your issue. I don’t know if anyone else is using this script. I have used it for years without any errors.