Created
June 8, 2014 15:11
-
-
Save hussainm/5345bbefd35e2ec31793 to your computer and use it in GitHub Desktop.
Unblock youtube in pakistan by redirecting youtube links through playit.pk This userscript can be used on all browsers using monkeyscript / tampermonkey extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Unblock youtube in Pakistan | |
// @namespace YoutubePakistan | |
// @version 0.1 | |
// @description This script rewrites all youtube links | |
// @match *://*/* | |
// @copyright 2012+, You | |
// ==/UserScript== | |
// iframes and embeds | |
var iframes = document.getElementsByTagName("iframe"); //array | |
var regex = /youtube\.com\/(embed|v|watch)\/([\d\w]+)(.*)/i; | |
for (var i=0,imax=iframes.length; i<imax; i++) { | |
iframes[i].src = iframes[i].src.replace(regex,"playit\.pk/embed\?v=$2"); | |
} | |
var embeds = document.getElementsByTagName("embed"); //array | |
for (var i=0,imax=embeds.length; i<imax; i++) { | |
embeds[i].src = embeds[i].src.replace(regex,"playit\.pk/embed\?v=$2"); | |
} | |
// Links | |
var links = document.getElementsByTagName("a"); //array | |
var regexL = /youtube\.com\/(watch|embed|v)\?v=(.+)$/i; | |
for (var i=0,imax=links.length; i<imax; i++) { | |
links[i].href = links[i].href.replace(regexL,"playit\.pk/$1\?v=$2"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment