PornHub Downloader

By miserablegit Last update Jan 6, 2009 — Installed 16,420 times. Daily Installs: 33, 40, 37, 23, 35, 15, 29, 31, 25, 36, 35, 14, 24, 28, 36, 26, 27, 32, 23, 28, 30, 35, 23, 23, 24, 31, 31, 29, 18, 28, 23, 22

There are 4 previous versions of this script.

// PHD  user script
// version 0.3
// 2008-08-31
// Copyright (c) 2008, miserablegit
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name          PornHub Downloader
// @description   Add a "download" link to PornHub pages
// @include       http://www.pornhub.com/view_video*
// @include       http://pornhub.com/view_video*
// ==/UserScript==

// find where the xml with data is
re = /(.*)mx_player_config.php(.*)\"\);/gm
plDiv = document.getElementById("MxPlayerDiv");
script = new String(plDiv.nextSibling.nextSibling.textContent);
info = re.exec(script);
var url;
url = "http://www.pornhub.com/mx_player_config.php" + decodeURIComponent(info[2]);
// get the xml fragment
GM_xmlhttpRequest({
	method: 'GET',
	url: url,
	headers: {
		'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
		'Accept': 'application/atom+xml,application/xml,text/xml',
	},
	onload: function(responseDetails) {
		// extract url
		re = /\<flv_url\>(.*)\<\/flv_url\>/gmi
		flvurl = responseDetails.responseText.match(re)[0].replace(re,"$1");
		// add link to page
		newDiv = document.createElement('div');
		newDiv.innerHTML = '<div class="video-info" style="text-align: center;"><a href="' + flvurl+ '">Download this video</a> (right-click, Save As) without signup.</div>';
		var allDivs, thisDiv;
		allDivs = document.evaluate(
			"//div[@class='sub-video-menu']",
			document,
			null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			null);
		for (var i = 0; i < allDivs.snapshotLength; i++) {
			thisDiv = allDivs.snapshotItem(i);
			thisDiv.parentNode.insertBefore(newDiv,thisDiv);
		}
	}
});