Skip to content

Instantly share code, notes, and snippets.

@son0fhobs
Last active March 16, 2016 01:34
Show Gist options
  • Save son0fhobs/9a4a4b453a89b545900d to your computer and use it in GitHub Desktop.
Save son0fhobs/9a4a4b453a89b545900d to your computer and use it in GitHub Desktop.
Putlocker General
// include jQuery, then run the function jqueryLoaded
/*
options - run default to guess for other video sites?
Single element selector option? - make icon to click on?
X button to undo fixes
*/
if(typeof jQuery !== 'function'){
var url = '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js';
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0];
head.appendChild(script);
script.onload = jqueryLoaded;
}else{
jqueryLoaded();
}
function jqueryLoaded(){
// I made $=jquery global, which isn't the best idea, but it was convenient, and this isn't exactly a huge project
options = {
includeHeader:false
};
$=jQuery;
var url = document.location.href;
// check if episode page or season list, run code accordingly
if(~url.indexOf('episode')){
// specific episode, get rid of everything except video
episodePage();
}else{
// page with episode/season guide, search page, home page, or anything else
listPage();
}
_adr = null;
antiClickjack = null;
}
function listPage(){
console.log('list page function');
var $header = $('td.mainlogo').closest('table');
var $content = $('.content-box');
var $body = $('body');
$body.children().remove();
if(options.includeHeader){
$header.css({'position':'relative','margin':'5px auto'});
$body.append($header)
}
$body.append($content);
$content.css({'position':'relative','margin':'5px auto'});
$('[id^=MarketGidScriptRoot]').nextAll().remove();
$('[id^=MarketGidScriptRoot]').remove();
$('.abineContentPanel').remove(); // hidden, not sure
}
function episodePage(){
console.log('episode page');
var video_selector = '';
var video_selectors = ['#videoPlayer', '.video', '#video'];
var $video = '';
if(document.location.hostname == 'putlocker.is' && $('.video').length){
$video = $('.video');
console.log('is putlocker');
_adr = null;
antiClickjack = null;
}else if($(video_selector).length){
$video = $(video_selector);
remove_ads();
}else{
$video = find_common_selectors(video_selectors);
if(!$video){
$video = find_objects_iframes();
remove_ads();
}
remove_overlayed_elems();
}
if(!$video){
alert('no video selector element found');
// add prompt to add? Or force add to gist?
}else{
show_only_video($video);
}
}
// remove overlayed/fixed elems in case doesn't fix everything else
function remove_overlayed_elems(){
$('*').each(function(){
if($(this).css('position') == 'fixed'){
$(this).remove();
}
});
}
function find_common_selectors(video_selectors){
var $video = '';
for(i=0;i<video_selectors.length;i++){
if($(video_selectors[i]).length){
$video = $(video_selectors[i]);
return $video;
break;
}
}
return;
}
function find_objects_iframes(){
var $objects = '';
var $iframes = '';
if($('iframe').length){
$iframes = $('iframe');
if(typeof $iframes === 'object' && $iframes.length > 1){
$.grep($iframes, function(elem, i){
// attr not working...
if($(elem).attr('src') !== 'undefined'){
if($(elem).attr('src').indexOf('ads') || $(elem).attr('src').indexOf('facebook') || $(elem).attr('src').indexOf('addthis')){
return false;
}
}
});
}
$video = $iframes;
return $iframes;
}else if($('object').length){
$objects = $('object');
}if($('embed').length){
$objects = $('embed');
}else{
console.log('No iframes or objects found on page');
}
return $objects;
}
function show_only_video($video){
$body_children = $('body').children(); // allow to add back if necessary
$body_children.remove();
$video.appendTo('body');
$('body').css({'background':'#111', 'text-align':'center', 'margin':'100px'});
$video.css({'border':'1px solid #000','box-shadow':'2px 2px 8px #000, 1px 1px 20px #040404', 'margin':'auto'});
$('html').css({'box-shadow':'1px 1px 2px #000 inset'});
}
function remove_ads(){
var ad_selectors = ['.ads'];
$(ad_selectors).css('border', '1px solid #33e');
setTimeout(function(){
$(ad_selectors).remove();
}, 1500);
}
function add_all_elems_back($video){
$video.remove();
$('body').css({'margin':'0'});
$('html').css({'box-shadow':'none'});
$body_children.appendTo('body');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment