|
// ==UserScript== |
|
// @name KissAnime Cleaner |
|
// @namespace 9001 |
|
// @description Cleans up KissAnime pages. Tested to work with Firefox and Greasemonkey. |
|
// @include https://kissanime.to/* |
|
// @include http://kissanime.to/* |
|
// @include https://kisscartoon.me/* |
|
// @include http://kisscartoon.me/* |
|
// @include https://kissasian.com/* |
|
// @include http://kissasian.com/* |
|
// @version 3.3.15 |
|
// @downloadURL https://gist.github.com/crapier/91926a6353207f4524cc/raw/kissanime_cleaner.user.js |
|
// @grant GM_getValue |
|
// @grant GM_setValue |
|
// @grant GM_registerMenuCommand |
|
// @grant unsafeWindow |
|
// ==/UserScript== |
|
|
|
// Prevent script from running in frames and iframes |
|
if (window.top != window.self) { |
|
return; |
|
} |
|
|
|
// Get the pages jQuery |
|
var $ = unsafeWindow.jQuery; |
|
|
|
// Option constants |
|
var PLAYER_FLASH = 0; |
|
var PLAYER_HTML5 = 1; |
|
|
|
// Option variables |
|
var pause_option = GM_getValue("pause", true); |
|
var quality_option = GM_getValue("quality", '1080'); |
|
var autoplay_option = GM_getValue("auto", true); |
|
var autoplay_count = GM_getValue("auto_count", -1) |
|
var autoscroll_option = GM_getValue("scroll", true); |
|
var player_option = GM_getValue("player", PLAYER_FLASH); |
|
var resize_option = GM_getValue("resize", true); |
|
var arrow_key_navagation = GM_getValue("arrow_nav", true); |
|
var speed_control = GM_getValue("speed_control", true); |
|
var volume_control = GM_getValue("volume_control", 100); |
|
var remove_login = GM_getValue("remove_login", true); |
|
var remove_comments = GM_getValue("remove_comments", true); |
|
var fake_fullscreen = GM_getValue("fake_fullscreen", false); |
|
|
|
// Current page url |
|
var url = document.location.href; |
|
// Regular Expressions to check against for determining what type page currently on and what to clean |
|
var home = /http:\/\/kissanime\.to\/$|https:\/\/kissanime\.to\/$|http:\/\/kisscartoon\.me\/$|https:\/\/kisscartoon\.me\/$|http:\/\/kissasian\.com\/$|https:\/\/kissasian\.com\/$/; |
|
var anime_list = /http:\/\/kissanime\.to\/(AnimeList|Genre|Status|Search|UpcomingAnime)|https:\/\/kissanime\.to\/(AnimeList|Genre|Status|Search|UpcomingAnime)|http:\/\/kisscartoon\.me\/(CartoonList|Status|Genre|Search)|https:\/\/kisscartoon\.me\/(CartoonList|Status|Genre|Search)|http:\/\/kissasian\.com\/(DramaList|Status|Country|Genre|Search)|https:\/\/kissasian\.com\/(DramaList|Status|Country|Genre|Search)/; |
|
var anime_page = /http:\/\/kissanime\.to\/Anime\/[^\/]*$|https:\/\/kissanime\.to\/Anime\/[^\/]*$|http:\/\/kisscartoon\.me\/Cartoon\/[^\/]*$|https:\/\/kisscartoon\.me\/Cartoon\/[^\/]*$|http:\/\/kissasian\.com\/Drama\/[^\/]*$|https:\/\/kissasian\.com\/Drama\/[^\/]*$/; |
|
var video_page = /http:\/\/kissanime\.to\/Anime\/[^\/]*\/[^\/]*\?id=\n*|https:\/\/kissanime\.to\/Anime\/[^\/]*\/[^\/]*\?id=\n*|http:\/\/kisscartoon\.me\/Cartoon\/[^\/]*\/[^\/]*\?id=\n*|https:\/\/kisscartoon\.me\/Cartoon\/[^\/]*\/[^\/]*\?id=\n*|http:\/\/kissasian\.com\/Drama\/[^\/]*\/[^\/]*\?id=\n*|https:\/\/kissasian\.com\/Drama\/[^\/]*\/[^\/]*\?id=\n*/; |
|
|
|
//--------------------------------------------------------------------------------------------------------------- |
|
// Clean Home page |
|
//--------------------------------------------------------------------------------------------------------------- |
|
if (home.test(url)) { |
|
console.log('Performing Cleaning for Home Page'); |
|
|
|
// Remove Sections from the right side of the page |
|
//Get the rightside from the document |
|
var rightside = document.getElementById('rightside'); |
|
// Check if the rightside exist and proceed if it does |
|
if (rightside) { |
|
// Loop through all righside elements |
|
for (var i = 0; i < rightside.childElementCount; i++) { |
|
// Check to make sure element has children |
|
if (rightside.children[i].childElementCount > 0) { |
|
// Check for children that to be removed |
|
if (rightside.children[i].children[0].textContent.search('Remove ads') > 0 || |
|
rightside.children[i].children[0].textContent.search('Like me please') > 0 || |
|
rightside.children[i].children[0].textContent.search('omments') > 0) { |
|
// Remove Child if it matches, decrement index to account for removing the child |
|
rightside.removeChild(rightside.children[i--]); |
|
// Check if the next element is a clear2 div and remove it if it is |
|
if (i + 1 > -1 && i + 1 < rightside.childElementCount) { |
|
if (rightside.children[i + 1].className == 'clear2') { |
|
rightside.removeChild(rightside.children[i + 1]); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
// Remove Register link in nav sub bar |
|
var navsub = document.getElementById('navsubbar'); |
|
if (navsub) { |
|
navsub.children[0].children[0].remove(); |
|
navsub.children[0].childNodes[1].remove(); |
|
} |
|
|
|
//Remove ads |
|
var leftad = document.getElementById('divFloatLeft'); |
|
if (leftad) { |
|
leftad.remove(); |
|
} |
|
var rightad = document.getElementById('divFloatRight'); |
|
if (rightad) { |
|
rightad.remove(); |
|
} |
|
var middlead2 = document.getElementById('divAds2'); |
|
if (middlead2) { |
|
middlead2.remove(); |
|
} |
|
var middlead = document.getElementById('divAds'); |
|
if (middlead) { |
|
middlead.remove(); |
|
} |
|
// Removes adspaces |
|
var adspace1 = document.getElementById('adsIfrme1'); |
|
if (adspace1) { |
|
adspace1.remove(); |
|
} |
|
|
|
// Remove or hide stubborn ads |
|
var adcheck_count = 0; |
|
var adremover = setInterval(function() { |
|
adcheck_count++; |
|
var body = document.body; |
|
if (body.childElementCount > 1) { |
|
var inital_count = body.childElementCount; |
|
for (var i = inital_count - 1; i > 0 ; i--) { |
|
body.children[i].remove(); |
|
} |
|
} |
|
var container = document.getElementById('containerRoot'); |
|
var total_elements = container.childElementCount; |
|
for (var i = total_elements - 1; container.children[i].id != 'container' ; i--) { |
|
container.children[i].style.visibility = 'hidden'; |
|
container.children[i].style.height = '0px'; |
|
container.children[i].style.width = '0px'; |
|
} |
|
|
|
if (adcheck_count == 50) { |
|
clearInterval(adremover); |
|
} |
|
}, 100); |
|
|
|
console.log('Done!'); |
|
} |
|
|
|
//--------------------------------------------------------------------------------------------------------------- |
|
// Clean Anime List Pages |
|
//--------------------------------------------------------------------------------------------------------------- |
|
if (anime_list.test(url)) { |
|
console.log('Performing Cleaning for Anime List Pages'); |
|
|
|
// Remove large spaces left by empty adspace |
|
// Get the ads frame |
|
var adspace = document.getElementById('adsIfrme1'); |
|
// If the ad frame was gotten proceed |
|
if (adspace) { |
|
// Check and remove the clear before the adspace |
|
if (adspace.parentElement.previousElementSibling && adspace.parentElement.previousElementSibling.className == 'clear') { |
|
adspace.parentElement.previousElementSibling.remove(); |
|
} |
|
// Check and remove the clear a bit after the adspace |
|
if (adspace.parentElement.nextElementSibling && adspace.parentElement.nextElementSibling.nextElementSibling && |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling && |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling.className == 'clear') { |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling.remove(); |
|
} |
|
// Remove the adspace's parent (and thus it) |
|
adspace.parentElement.remove(); |
|
} |
|
|
|
//Remove other ads |
|
var leftad = document.getElementById('divFloatLeft'); |
|
if (leftad) { |
|
leftad.remove(); |
|
} |
|
var rightad = document.getElementById('divFloatRight'); |
|
if (rightad) { |
|
rightad.remove(); |
|
} |
|
var adspace2 = document.getElementById('adsIfrme2'); |
|
if (adspace2) { |
|
adspace2.remove(); |
|
} |
|
|
|
// Remove or hide stubborn ads |
|
var adcheck_count = 0; |
|
var adremover = setInterval(function() { |
|
adcheck_count++; |
|
var body = document.body; |
|
if (body.childElementCount > 1) { |
|
var inital_count = body.childElementCount; |
|
for (var i = inital_count - 1; i > 0 ; i--) { |
|
body.children[i].remove(); |
|
} |
|
} |
|
var container = document.getElementById('containerRoot'); |
|
var total_elements = container.childElementCount; |
|
for (var i = total_elements - 1; container.children[i].id != 'container' ; i--) { |
|
container.children[i].style.visibility = 'hidden'; |
|
container.children[i].style.height = '0px'; |
|
container.children[i].style.width = '0px'; |
|
} |
|
|
|
if (adcheck_count == 50) { |
|
clearInterval(adremover); |
|
} |
|
}, 100); |
|
|
|
console.log('Done!'); |
|
} |
|
|
|
//--------------------------------------------------------------------------------------------------------------- |
|
// Clean Episode List Pages |
|
//--------------------------------------------------------------------------------------------------------------- |
|
if (anime_page.test(url)) { |
|
console.log('Performing Cleaning for Episode List Pages'); |
|
|
|
// Remove large spaces left by empty adspace |
|
// Get the ads frame |
|
var adspace = document.getElementById('adsIfrme1'); |
|
// If the ad frame was gotten proceed |
|
if (adspace) { |
|
// Check and remove the clear before the adspace |
|
if (adspace.parentElement.previousElementSibling && adspace.parentElement.previousElementSibling.className == 'clear') { |
|
adspace.parentElement.previousElementSibling.remove(); |
|
} |
|
// Check and remove the clear a bit after the adspace |
|
if (adspace.parentElement.nextElementSibling && adspace.parentElement.nextElementSibling.nextElementSibling && |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling && |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling.className == 'clear') { |
|
adspace.parentElement.nextElementSibling.nextElementSibling.nextElementSibling.remove(); |
|
} |
|
// Remove the adspace's parent (and thus it) |
|
adspace.parentElement.remove(); |
|
} |
|
|
|
//Remove other ads |
|
var leftad = document.getElementById('divFloatLeft'); |
|
if (leftad) { |
|
leftad.remove(); |
|
} |
|
var rightad = document.getElementById('divFloatRight'); |
|
if (rightad) { |
|
rightad.remove(); |
|
} |
|
var middlead = document.getElementById('divAds'); |
|
if (middlead) { |
|
middlead.remove(); |
|
} |
|
|
|
// Remove share stuff from episode list pages |
|
var eplist = $('div.barContent.episodeList')[0].children[1]; |
|
if (eplist) { |
|
// Page has episodes |
|
if (eplist.childElementCount > 3) { |
|
// delete all elements before the listings |
|
eplist.children[0].remove(); |
|
eplist.children[0].remove(); |
|
eplist.children[0].remove(); |
|
eplist.children[0].remove(); |
|
} |
|
// Page has no episdoes (not aired) |
|
else { |
|
eplist.children[0].remove(); |
|
eplist.children[0].remove(); |
|
eplist.children[0].remove(); |
|
} |
|
} |
|
|
|
if (remove_comments) { |
|
// Remove comments |
|
var comment_location = 2; |
|
if (/kissasian/.test(url)) { |
|
comment_location = 3; |
|
} |
|
var comments = $('div.bigBarContainer')[comment_location]; |
|
if (comments) { |
|
comments.remove(); |
|
} |
|
} |
|
|
|
var bookmark_link = document.getElementById('spanBookmark'); |
|
if (bookmark_link) { |
|
bookmark_link.remove(); |
|
} |
|
|
|
// Remove or hide stubborn ads |
|
var adcheck_count = 0; |
|
var adremover = setInterval(function() { |
|
adcheck_count++; |
|
var body = document.body; |
|
if (body.childElementCount > 1) { |
|
var inital_count = body.childElementCount; |
|
for (var i = inital_count - 1; i > 0 ; i--) { |
|
body.children[i].remove(); |
|
} |
|
} |
|
var container = document.getElementById('containerRoot'); |
|
var total_elements = container.childElementCount; |
|
for (var i = total_elements - 1; container.children[i].id != 'container' ; i--) { |
|
container.children[i].style.visibility = 'hidden'; |
|
container.children[i].style.height = '0px'; |
|
container.children[i].style.width = '0px'; |
|
} |
|
|
|
var rightside = document.getElementById('rightside'); |
|
total_elements = rightside.childElementCount; |
|
for (var i = total_elements - 1; rightside.children[i].className != 'rightBox' ; i--) { |
|
rightside.children[i].style.visibility = 'hidden'; |
|
rightside.children[i].style.height = '0px'; |
|
rightside.children[i].style.width = '0px'; |
|
} |
|
|
|
if (adcheck_count == 50) { |
|
clearInterval(adremover); |
|
} |
|
}, 100); |
|
|
|
console.log('Done!'); |
|
} |
|
|
|
//--------------------------------------------------------------------------------------------------------------- |
|
// Clean Video Page |
|
//--------------------------------------------------------------------------------------------------------------- |
|
if (video_page.test(url)) { |
|
console.log('Performing Cleaning for Video Page'); |
|
|
|
// Override functions so they wont be do anything when called by the pages code |
|
// Function to inject into page |
|
var override = function() { |
|
DoDetect2 = function() {} |
|
CheckAdImage = function() {} |
|
} |
|
// Create script to inject |
|
var script1 = document.createElement('script'); |
|
script1.type = "text/javascript"; |
|
script1.innerHTML = 'var override = ' + override.toString(); |
|
// inject the script |
|
document.getElementsByTagName('head')[0].appendChild(script1); |
|
// Call our new function |
|
unsafeWindow.override(); |
|
|
|
// Removes adspaces |
|
var adspace6 = document.getElementById('adsIfrme6'); |
|
if (adspace6) { |
|
adspace6.remove(); |
|
} |
|
var adspace7 = document.getElementById('adsIfrme7'); |
|
if (adspace7) { |
|
adspace7.remove(); |
|
} |
|
var adspace8 = document.getElementById('adsIfrme8'); |
|
if (adspace8) { |
|
adspace8.remove(); |
|
} |
|
var adspace10 = document.getElementById('adsIfrme10'); |
|
if (adspace10) { |
|
adspace10.remove(); |
|
} |
|
var adspace11 = document.getElementById('adsIfrme11'); |
|
if (adspace11) { |
|
adspace11.remove(); |
|
} |
|
|
|
var adCheck1 = document.getElementById('adCheck1'); |
|
if (adCheck1) { |
|
adCheck1.remove(); |
|
} |
|
var adCheck2 = document.getElementById('adCheck2'); |
|
if (adCheck2) { |
|
adCheck2.remove(); |
|
} |
|
var adCheck3 = document.getElementById('adCheck3'); |
|
if (adCheck3) { |
|
adCheck3.remove(); |
|
} |
|
|
|
var divdownload = document.getElementById('divDownload'); |
|
if (divdownload) { |
|
divdownload.remove(); |
|
} |
|
var divfilename = document.getElementById('divFileName'); |
|
if (divfilename) { |
|
divfilename.remove(); |
|
} |
|
|
|
// Removes Empty spaces from Video pages |
|
// Remove Clears |
|
var vid_parent = document.getElementById('centerDivVideo').parentElement; |
|
for (var i = 0; i < vid_parent.childElementCount; i++) { |
|
if (vid_parent.children[i].className == 'clear' || vid_parent.children[i].className == 'clear2') { |
|
vid_parent.removeChild(vid_parent.children[i--]); |
|
} |
|
} |
|
vid_parent.children[3].remove(); |
|
|
|
if (remove_comments) { |
|
// Get the comment section on the video pages |
|
var comments = document.getElementById('btnShowComments'); |
|
// If it exist remove it and the element just prior to it also, share stuff of some kind |
|
if (comments) { |
|
comments = comments.parentElement; |
|
comments.previousElementSibling.remove(); |
|
comments.previousElementSibling.remove(); |
|
comments.previousElementSibling.remove(); |
|
comments.remove(); |
|
} |
|
|
|
|
|
// remove comments for kisscartoon site |
|
var alt_comments = document.getElementById('divComments'); |
|
if (alt_comments) { |
|
alt_comments.previousElementSibling.remove(); |
|
alt_comments.previousElementSibling.remove(); |
|
alt_comments.remove(); |
|
} |
|
} |
|
|
|
// Hide on page quality selector, conflicts with custom menu selector |
|
var page_select_player = document.getElementById('selectPlayer'); |
|
if (page_select_player) { |
|
page_select_player.parentElement.style.cssText = 'display:none;'; |
|
} |
|
|
|
// hide lights off feature that is pointless with ads already removed |
|
var lights_off = document.getElementById('switch'); |
|
if (lights_off) { |
|
lights_off.remove(); |
|
} |
|
|
|
// remove device player link and text |
|
$('.clsTempMSg').remove(); |
|
|
|
|
|
var USE_FLASH_FOR_PAGE; |
|
var YOUTUBE_FLASH_PLAYER; |
|
if (player_option == PLAYER_FLASH) { |
|
if (document.cookie.indexOf('usingFlashV1') < 0) { |
|
// Reload page with correct player |
|
document.cookie = 'usingFlashV1=true;path=/'; |
|
document.cookie = 'usingHTML5V1=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'; |
|
document.location.href = document.location.href; |
|
} |
|
// check if page actually has youtube info |
|
if (unsafeWindow.jwplayer) { |
|
USE_FLASH_FOR_PAGE = true; |
|
YOUTUBE_FLASH_PLAYER = false; |
|
} else if (unsafeWindow.myPlayer) { |
|
USE_FLASH_FOR_PAGE = false; |
|
YOUTUBE_FLASH_PLAYER = false; |
|
} else { |
|
USE_FLASH_FOR_PAGE = true; |
|
YOUTUBE_FLASH_PLAYER = true; |
|
} |
|
} else { |
|
if (document.cookie.indexOf('usingHTML5V1') < 0) { |
|
// Reload page with correct player |
|
document.cookie = 'usingFlashV1=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'; |
|
document.cookie = 'usingHTML5V1=true;path=/'; |
|
document.location.href = document.location.href; |
|
} |
|
// check that page actually has html5 player |
|
if (unsafeWindow.myPlayer) { |
|
USE_FLASH_FOR_PAGE = false; |
|
YOUTUBE_FLASH_PLAYER = false; |
|
} else if (unsafeWindow.jwplayer) { |
|
USE_FLASH_FOR_PAGE = true; |
|
YOUTUBE_FLASH_PLAYER = false; |
|
} else { |
|
USE_FLASH_FOR_PAGE = true; |
|
YOUTUBE_FLASH_PLAYER = true; |
|
} |
|
} |
|
|
|
// Flash Player |
|
if (USE_FLASH_FOR_PAGE) { |
|
console.log('Using Flash Player'); |
|
if (YOUTUBE_FLASH_PLAYER) { |
|
console.log('Using YouTube Player'); |
|
|
|
// Functions to inject on page for flash video control |
|
// Fires when youtube player is ready |
|
var onYouTubePlayerReady = function(playerId) { |
|
console.log('Youtube Player Custom Controls Initialized'); |
|
if (pause_option) { |
|
embedVideo.pauseVideo(); |
|
} |
|
embedVideo.addEventListener('onStateChange', 'check_for_end'); |
|
|
|
// translate option into youtubes quality strings values |
|
var youtube_quality_option; |
|
if (quality_option == '1080') { |
|
youtube_quality_option = 'hd1080'; |
|
} else if (quality_option == '720') { |
|
youtube_quality_option = 'hd720'; |
|
} else if (quality_option == '480') { |
|
youtube_quality_option = 'large'; |
|
} else if (quality_option == '360') { |
|
youtube_quality_option = 'medium'; |
|
} |
|
// set the quality |
|
embedVideo.setPlaybackQuality(youtube_quality_option); |
|
|
|
// set the volume |
|
embedVideo.setVolume(volume_control); |
|
|
|
// focus on the video (so pressing f will fullscreen) |
|
setTimeout('embedVideo.focus();', 0); |
|
|
|
// Force position to be absolute (compatibility with 'Turn Off the Lights') |
|
setTimeout(function() { |
|
if (embedVideo.style.cssText.indexOf("position: relative !important") >= 0) { |
|
embedVideo.style.cssText = embedVideo.style.cssText.substr(0, embedVideo.style.cssText.indexOf("position: relative !important;")) + embedVideo.style.cssText.substr(embedVideo.style.cssText.indexOf("position: relative !important") + 30); |
|
} |
|
}, 100); |
|
} |
|
// Check for end of playback and move to next video |
|
var check_for_end = function(state) { |
|
if (state == 0 && autoplay_option && autoplay_count != 0) { |
|
if (autoplay_count > 0) { |
|
autoplay_count--; |
|
if (autoplay_count == 0) { |
|
autoplay_count = -1; |
|
autoplay_option = false; |
|
} |
|
document.dispatchEvent(update_userscript); |
|
} |
|
var button = document.getElementById('btnNext'); |
|
if (button) { |
|
var link = button.parentElement; |
|
document.location.href = link.href; |
|
} |
|
} |
|
} |
|
// Create script to inject |
|
var script2 = document.createElement('script'); |
|
script2.type = "text/javascript"; |
|
script2.innerHTML = 'var onYouTubePlayerReady = ' + onYouTubePlayerReady.toString() + '\n' + |
|
'var check_for_end = ' + check_for_end.toString() + '\n' + |
|
'var pause_option = ' + pause_option.toString() + '\n' + |
|
'var quality_option = "' + quality_option.toString() + '"\n' + |
|
'var autoplay_option = ' + autoplay_option.toString() + '\n' + |
|
'var autoplay_count = ' + autoplay_count.toString() + '\n' + |
|
'var volume_control = ' + volume_control.toString() + '\n' + |
|
'var update_userscript = new Event("UDUS")'; |
|
|
|
// Inject the script |
|
document.getElementsByTagName('head')[0].appendChild(script2); |
|
|
|
// Update values for userscript before switching to next video |
|
document.addEventListener('UDUS', function(event) { |
|
autoplay_count = unsafeWindow.autoplay_count; |
|
autoplay_option = unsafeWindow.autoplay_option; |
|
GM_setValue("auto", autoplay_option); |
|
GM_setValue("auto_count", autoplay_count); |
|
}); |
|
} |
|
else { |
|
console.log('Using jwplayer.'); |
|
// Functions to inject on page for flash video control |
|
// Fires when youtube player is ready |
|
var flash_player_controls = function () { |
|
// wait till video is loaded into player |
|
jwplayer().onReady(function() { |
|
console.log("jwplayer custom Controls Initialized"); |
|
// change the quality to desired flash option |
|
var available_levels = jwplayer().getQualityLevels(); |
|
var level_set = false; |
|
var desired_level = parseInt(quality_option); |
|
|
|
// try to find exact quality level |
|
for (var i = 0; i < available_levels.length; i++) { |
|
if (desired_level == parseInt(available_levels[i].label)) { |
|
jwplayer().setCurrentQuality(i); |
|
level_set = true; |
|
break; |
|
} |
|
} |
|
|
|
// try to find best level alternate |
|
if (!level_set) { |
|
// check if desired level is lower than all available |
|
if (desired_level < parseInt(available_levels[0].label)) { |
|
jwplayer().setCurrentQuality(0); |
|
} |
|
// check if desired level is higher than all available |
|
else if(desired_level > parseInt(available_levels[available_levels.length - 1].label)) { |
|
jwplayer().setCurrentQuality(available_levels.length - 1); |
|
} |
|
// else find level that is next smallest |
|
else { |
|
for (var i = 0; i < available_levels.length; i++) { |
|
if(desired_level < parseInt(available_levels[i].label)) { |
|
jwplayer().setCurrentQuality(i-1); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
// pause the video if option is enabled |
|
if (pause_option) { |
|
jwplayer().pause(); |
|
} |
|
|
|
// settup callback for end of video checks |
|
jwplayer().onComplete(check_for_end); |
|
|
|
}); |
|
} |
|
// Check for end of playback and move to next video |
|
var check_for_end = function () { |
|
var button = document.getElementById('btnNext'); |
|
if (button && autoplay_option && autoplay_count != 0) { |
|
if (autoplay_count > 0) { |
|
autoplay_count--; |
|
if (autoplay_count == 0) { |
|
autoplay_count = -1; |
|
autoplay_option = false; |
|
} |
|
document.dispatchEvent(update_userscript); |
|
} |
|
var link = button.parentElement; |
|
document.location.href = link.href; |
|
} |
|
} |
|
// Create script to inject |
|
var script2 = document.createElement('script'); |
|
script2.type = "text/javascript"; |
|
script2.innerHTML = 'var flash_player_controls = ' + flash_player_controls.toString() + '\n' + |
|
'var check_for_end = ' + check_for_end.toString() + '\n' + |
|
'var pause_option = ' + pause_option.toString() + '\n' + |
|
'var quality_option = "' + quality_option.toString() + '"\n' + |
|
'var autoplay_option = ' + autoplay_option.toString() + '\n' + |
|
'var autoplay_count = ' + autoplay_count.toString() + '\n' + |
|
'var update_userscript = new Event("UDUS")'; |
|
|
|
// Inject the script |
|
document.getElementsByTagName('head')[0].appendChild(script2); |
|
// call injected function, hopefully after jwplayer has been settup |
|
setTimeout(function() { |
|
unsafeWindow.flash_player_controls(); |
|
},500); |
|
|
|
// Update values for userscript before switching to next video |
|
document.addEventListener('UDUS', function(event) { |
|
autoplay_count = unsafeWindow.autoplay_count; |
|
autoplay_option = unsafeWindow.autoplay_option; |
|
GM_setValue("auto", autoplay_option); |
|
GM_setValue("auto_count", autoplay_count); |
|
}); |
|
} |
|
|
|
} |
|
// HTML5 Player |
|
else { |
|
console.log('Using HTML5 Player'); |
|
|
|
// move quality select below player |
|
var html_quality_select = document.getElementById('selectQuality'); |
|
if (html_quality_select) { |
|
var video_area = document.getElementById('centerDivVideo'); |
|
var leftover_text = html_quality_select.parentElement; |
|
var empty_div = document.createElement('div'); |
|
video_area.parentElement.insertBefore(html_quality_select, video_area.nextSibling); |
|
video_area.parentElement.insertBefore(empty_div, video_area.nextSibling); |
|
leftover_text.remove(); |
|
} |
|
|
|
// Functions to inject on page for html5 video control |
|
var html5_video_options = function() { |
|
console.log("HTML5 Player custom Controls Initialized"); |
|
// change the quality to desired flash option |
|
var available_levels = $('#selectQuality')[0]; |
|
var level_set = false; |
|
var desired_level = parseInt(quality_option); |
|
// try to find exact quality level |
|
for (var i = 0; i < available_levels.length; i++) { |
|
if (desired_level == parseInt(available_levels.options[i].innerHTML)) { |
|
available_levels.selectedIndex = i; |
|
$('#selectQuality').change(); |
|
$('.clsTempMSg').remove(); |
|
level_set = true; |
|
break; |
|
} |
|
} |
|
|
|
// try to find best level alternate |
|
if (!level_set) { |
|
// check if desired level is higher than all available |
|
if (desired_level < parseInt(available_levels.options[available_levels.length - 1].innerHTML)) { |
|
available_levels.selectedIndex = available_levels.length - 1; |
|
$('#selectQuality').change(); |
|
$('.clsTempMSg').remove(); |
|
} |
|
// check if desired level is lower than all available |
|
else if (desired_level > parseInt(available_levels.options[0].innerHTML)) { |
|
available_levels.selectedIndex = 0; |
|
$('#selectQuality').change(); |
|
$('.clsTempMSg').remove(); |
|
} |
|
// else find level that is next smallest |
|
else { |
|
for (var i = 0; i < available_levels.length; i++) { |
|
if (desired_level > parseInt(available_levels.options[i].innerHTML)) { |
|
available_levels.selectedIndex = i; |
|
$('#selectQuality').change(); |
|
$('.clsTempMSg').remove(); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
if (pause_option) { |
|
my_video_1_html5_api.pause(); |
|
} |
|
my_video_1_html5_api.volume = volume_control / 100; |
|
my_video_1_html5_api.addEventListener('ended', html5_video_end); |
|
} |
|
var html5_video_end = function() { |
|
var button = document.getElementById('btnNext'); |
|
if (button && autoplay_option && autoplay_count != 0) { |
|
if (autoplay_count > 0) { |
|
autoplay_count--; |
|
if (autoplay_count == 0) { |
|
autoplay_count = -1; |
|
autoplay_option = false; |
|
} |
|
document.dispatchEvent(update_userscript); |
|
} |
|
var link = button.parentElement; |
|
document.location.href = link.href; |
|
} |
|
} |
|
|
|
// injected speed controls |
|
var playback_decrease = function() { |
|
my_video_1_html5_api.playbackRate -= 0.25; |
|
} |
|
var playback_increase = function() { |
|
my_video_1_html5_api.playbackRate += 0.25; |
|
} |
|
|
|
// Create script to inject |
|
var script2 = document.createElement('script'); |
|
script2.type = "text/javascript"; |
|
script2.innerHTML = 'var html5_video_options = ' + html5_video_options.toString() + '\n' + |
|
'var html5_video_end = ' + html5_video_end.toString() + '\n' + |
|
'var pause_option = ' + pause_option.toString() + '\n' + |
|
'var quality_option = ' + quality_option.toString() + '\n' + |
|
'var autoplay_option = ' + autoplay_option.toString() + '\n' + |
|
'var autoplay_count = ' + autoplay_count.toString() + '\n' + |
|
'var playback_decrease = ' + playback_decrease.toString() + '\n' + |
|
'var playback_increase = ' + playback_increase.toString() + '\n' + |
|
'var volume_control = ' + volume_control.toString() + '\n' + |
|
'var update_userscript = new Event("UDUS")'; |
|
// Inject the script |
|
document.getElementsByTagName('head')[0].appendChild(script2); |
|
// Call the injected script |
|
unsafeWindow.html5_video_options(); |
|
|
|
// Update values for userscript before switching to next video |
|
document.addEventListener('UDUS', function(event) { |
|
autoplay_count = unsafeWindow.autoplay_count; |
|
autoplay_option = unsafeWindow.autoplay_option; |
|
GM_setValue("auto", autoplay_option); |
|
GM_setValue("auto_count", autoplay_count); |
|
}); |
|
} |
|
|
|
// Scroll to the Container |
|
if (autoscroll_option) { |
|
document.getElementById('container').scrollIntoView(true); |
|
} |
|
|
|
|
|
var resize_video_area = function() { |
|
if (fake_fullscreen) { |
|
var resize_width = window.innerWidth; |
|
var resize_height = window.innerHeight; |
|
|
|
document.getElementById('container').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('adsIfrme').style.width = "" + (resize_width) + "px"; |
|
$(".barContent")[0].children[0].style.width = "" + (resize_width) + "px"; |
|
|
|
document.getElementById('centerDivVideo').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('centerDivVideo').style.height = "" + (resize_height) + "px"; |
|
|
|
if (USE_FLASH_FOR_PAGE) { |
|
document.getElementById('divContentVideo').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('divContentVideo').style.height = "" + (resize_height) + "px"; |
|
document.getElementById('embedVideo').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('embedVideo').style.height = "" + (resize_height) + "px"; |
|
} else { |
|
document.getElementById('divContentVideo').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('divContentVideo').style.height = "" + (resize_height) + "px"; |
|
document.getElementById('my_video_1').style.width = "" + (resize_width) + "px"; |
|
document.getElementById('my_video_1').style.height = "" + (resize_height) + "px"; |
|
} |
|
|
|
var seek_bar = $('.vjs-control-bar'); |
|
if (seek_bar.length > 0) { |
|
seek_bar[0].style.visibility = 'hidden'; |
|
} |
|
|
|
document.getElementById('centerDivVideo').scrollIntoView(true); |
|
document.body.style.overflow = 'hidden'; |
|
} |
|
else { |
|
var resize_to = window.innerWidth - 30; |
|
if (resize_to > 970) { |
|
resize_to = 970; |
|
} |
|
document.getElementById('container').style.width = "" + (resize_to) + "px"; |
|
document.getElementById('adsIfrme').style.width = "" + (resize_to - 20) + "px"; |
|
$(".barContent")[0].children[0].style.width = "" + (resize_to - 40) + "px"; |
|
|
|
document.getElementById('centerDivVideo').style.width = "" + (resize_to - 40) + "px"; |
|
document.getElementById('centerDivVideo').style.height = "" + (resize_to - 40) * 552 / 845 + "px"; |
|
|
|
if (USE_FLASH_FOR_PAGE) { |
|
document.getElementById('divContentVideo').style.width = "" + (resize_to - 40) + "px"; |
|
document.getElementById('divContentVideo').style.height = "" + (resize_to - 40) * 552 / 845 + "px"; |
|
document.getElementById('embedVideo').style.width = "" + (resize_to - 40) + "px"; |
|
document.getElementById('embedVideo').style.height = "" + (resize_to - 40) * 552 / 845 + "px"; |
|
} else { |
|
document.getElementById('divContentVideo').style.width = "" + (resize_to - 40) + "px"; |
|
document.getElementById('divContentVideo').style.height = "" + (resize_to - 40) * 552 / 845 + "px"; |
|
document.getElementById('my_video_1').style.width = "" + (resize_to - 40) + "px"; |
|
document.getElementById('my_video_1').style.height = "" + (resize_to - 40) * 552 / 845 + "px"; |
|
} |
|
|
|
var seek_bar = $('.vjs-control-bar'); |
|
if (seek_bar.length > 0) { |
|
seek_bar[0].style.visibility = 'visible'; |
|
} |
|
document.body.style.overflow = 'visible'; |
|
} |
|
} |
|
|
|
if (resize_option) { |
|
window.addEventListener("resize", resize_video_area); |
|
// wait some for vid to get added to page, and initialy resize it |
|
setTimeout(function() { |
|
resize_video_area(); |
|
}, 1000); |
|
} |
|
|
|
|
|
// Keys listener for navigating between episodes with left and right arrow keys |
|
// Arrow key keycodes |
|
var LEFT_ARROW_KEY = 37; |
|
var RIGHT_ARROW_KEY = 39; |
|
var MINUS_DASH_KEY = 173; |
|
var PLUS_EQUALS_KEY = 61; |
|
var BAR_FORWARD_SLASH_KEY = 220; |
|
var key_listener = function(event) { |
|
// Get which key is pressed |
|
var key_pressed = event.which; |
|
if (arrow_key_navagation) { |
|
// check to make sure video isnt playing |
|
if ((USE_FLASH_FOR_PAGE && YOUTUBE_FLASH_PLAYER && unsafeWindow.embedVideo.getPlayerState() == 2) || (USE_FLASH_FOR_PAGE && !YOUTUBE_FLASH_PLAYER && unsafeWindow.jwplayer().getState() == "PAUSED") |
|
|| (!USE_FLASH_FOR_PAGE && my_video_1_html5_api.paused)) { |
|
// Left arrow key to go to previous video |
|
if (key_pressed == LEFT_ARROW_KEY) { |
|
var button = document.getElementById('btnPrevious'); |
|
if (button) { |
|
var link = button.parentElement; |
|
document.location.href = link.href; |
|
} |
|
// Prevent Default Action of scrolling |
|
event.preventDefault(); |
|
} |
|
// right arrow key for next video |
|
else if (key_pressed == RIGHT_ARROW_KEY) { |
|
var button = document.getElementById('btnNext'); |
|
if (button) { |
|
var link = button.parentElement; |
|
document.location.href = link.href; |
|
} |
|
// Prevent Default Action of scrolling |
|
event.preventDefault(); |
|
} |
|
} |
|
} |
|
// Speed controls for HTLM5 player (flash doesn't support atm) |
|
if (speed_control && !USE_FLASH_FOR_PAGE) { |
|
if (key_pressed == MINUS_DASH_KEY && unsafeWindow.my_video_1_html5_api.playbackRate > 0.25) { |
|
unsafeWindow.playback_decrease(); |
|
} |
|
if (key_pressed == PLUS_EQUALS_KEY && unsafeWindow.my_video_1_html5_api.playbackRate < 5) { |
|
unsafeWindow.playback_increase(); |
|
} |
|
} |
|
if (key_pressed == BAR_FORWARD_SLASH_KEY) { |
|
fake_fullscreen = !fake_fullscreen; |
|
GM_setValue('fake_fullscreen', fake_fullscreen); |
|
resize_video_area(); |
|
} |
|
} |
|
// Add the listener for keypresses |
|
document.addEventListener("keydown", key_listener); |
|
|
|
console.log('Done!'); |
|
} |
|
|
|
//--------------------------------------------------------------------------------------------------------------- |
|
// Clean All pages |
|
//--------------------------------------------------------------------------------------------------------------- |
|
console.log('Performing Cleaning for All Pages') |
|
|
|
// Remove share stuff next to search bar |
|
// Get the search element near the top of the page |
|
var search = document.getElementById('search'); |
|
// If it exist then proceed to remove the child that is the facebook, share stuff next to it |
|
if (search) { |
|
search.children[0].children[2].remove(); |
|
} |
|
|
|
// Remove Login at the top of the page |
|
if (remove_login) { |
|
var login = document.getElementById('topHolderBox'); |
|
if (login) { |
|
login.remove(); |
|
} |
|
} |
|
|
|
// Remove Tabs I don't Use |
|
var mobile = document.getElementById('liMobile'); |
|
if (mobile) { |
|
mobile.remove(); |
|
} |
|
var report_error = document.getElementById('liReportError'); |
|
if (report_error) { |
|
report_error.remove(); |
|
} |
|
var request_anime = document.getElementById('liRequest'); |
|
if (request_anime) { |
|
request_anime.remove(); |
|
} |
|
var forum = document.getElementById('liCommunity'); |
|
if (forum) { |
|
forum.remove(); |
|
} |
|
var faq = document.getElementById('liFAQ'); |
|
if (faq) { |
|
faq.remove(); |
|
} |
|
var manga = document.getElementById('liReadManga'); |
|
if (manga) { |
|
manga.remove(); |
|
} |
|
|
|
// Remove Footer |
|
var footer = document.getElementById('footer'); |
|
if (footer) { |
|
footer.remove(); |
|
} |
|
|
|
// Remove 'random' hides that appear on the sides of the page, all pages |
|
if ($('div.divCloseBut')) { |
|
$('div.divCloseBut').remove(); |
|
} |
|
|
|
// Keys listener for Script Menu Options |
|
// Home Key Code |
|
var HOME_KEY = 36; |
|
var menu_open = false; |
|
var menu; |
|
var global_key_listener = function(event) { |
|
// Get which key is pressed |
|
var key_pressed = event.which; |
|
if (key_pressed == HOME_KEY) { |
|
// Prevent Default Action of scrolling to top of page |
|
event.preventDefault(); |
|
open_menu(); |
|
} |
|
} |
|
var open_menu = function() { |
|
if (!menu_open) { |
|
menu_open = true; |
|
// Make div element for menu |
|
menu = document.createElement('div'); |
|
menu.style.cssText = 'color:black;width:250px;height:320px;background-color:white;position:fixed;top:0;bottom:0;left:0;right:0;margin:auto;border:5px solid;border-radius:10px;border-color:#7FCA03;padding:10px;z-index:5;'; |
|
menu.innerHTML = '<center><b>KissAnime Cleaner Options</b></center>' + |
|
'<form><input style="margin:2px;" type="checkbox" name="pause" value="true" id="pause_option_box"> Pause Videos on Page Load <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="autoplay" value="true" id="autoplay_option_box"> Automatically Play Next <input style="margin:0px;font-size:111%;font-family:Tahoma,Arial,Helvetica,sans-serif;" type="number" name="autoplaycount" id="autoplay_count" min="-1" max="999"> Video(s) (choose -1 to play all)<br>' + |
|
'<input style="margin:2px;" type="checkbox" name="autoscroll" value="true" id="autoscroll_option_box"> Automatically Scroll Down to Video Area <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="resize" value="true" id="resize_option_box"> Resize Video Area <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="arrow_nav" value="true" id="arrow_nav_box"> Arrow Keys Navigate Between Videos <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="speed_playback" value="true" id="playback_speed_control_box"> Enable HTML5 Playback speed controls <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="remove_login" value="true" id="remove_login_box"> Disable Login <br>' + |
|
'<input style="margin:2px;" type="checkbox" name="remove_comments" value="true" id="remove_comments_box"> Disable Comments <br><br>' + |
|
'<center><b>Player Options</b></center>' + |
|
'<table style="width: 100%;border-collapse:separate;border-spacing:2px;"><tr><td><input style="margin:2px;" type="radio" name="player" value="flash" id="flash_option"> Flash Player</td>' + |
|
'<td align="right"><select style="margin:2px;" id="quality_select">' + |
|
'<option value="360">360p</option>' + |
|
'<option value="480">480p</option>' + |
|
'<option value="720">720p</option>' + |
|
'<option value="1080">1080p</option>' + |
|
'</select></td></tr>' + |
|
'<tr><td><input style="margin:2px;" type="radio" name="player" value="html5" id="html5_option"> HTML5 Player</td>' + |
|
'<td align="right">Volume <input style="margin:0px;font-size:111%;font-family:Tahoma,Arial,Helvetica,sans-serif;" type="number" name="volumepercent" id="volume_percent" min="0" max="100"></td></tr></table>' + |
|
'<center><input style="margin:2px;font-size:111%;font-family:Tahoma,Arial,Helvetica,sans-serif;padding:2px 5px 2px 5px;width:44px;height:27px;line-height:3px;" type="button" value="Save" id="menu_sumbit_button"></center></form>'; |
|
|
|
// Add menu to page |
|
document.getElementById('containerRoot').appendChild(menu); |
|
// Set menus starting options to current values |
|
// Checkboxes |
|
var pause_option_box = document.getElementById('pause_option_box'); |
|
if (pause_option) { |
|
pause_option_box.checked = true; |
|
} |
|
var autoplay_option_box = document.getElementById('autoplay_option_box'); |
|
if (autoplay_option) { |
|
autoplay_option_box.checked = true; |
|
} |
|
var resize_option_box = document.getElementById('resize_option_box'); |
|
if (resize_option) { |
|
resize_option_box.checked = true; |
|
} |
|
|
|
var autoplay_count_input = document.getElementById('autoplay_count'); |
|
autoplay_count_input.style.width = '40px'; |
|
autoplay_count_input.value = autoplay_count; |
|
|
|
var autoscroll_option_box = document.getElementById('autoscroll_option_box'); |
|
if (autoscroll_option) { |
|
autoscroll_option_box.checked = true; |
|
} |
|
var arrow_nav_box = document.getElementById('arrow_nav_box'); |
|
if (arrow_key_navagation) { |
|
arrow_nav_box.checked = true; |
|
} |
|
|
|
var playback_speed_control_box = document.getElementById('playback_speed_control_box'); |
|
if (speed_control) { |
|
playback_speed_control_box.checked = true; |
|
} |
|
|
|
var remove_login_box = document.getElementById('remove_login_box'); |
|
if (remove_login) { |
|
remove_login_box.checked = true; |
|
} |
|
|
|
var remove_comments_box = document.getElementById('remove_comments_box'); |
|
if (remove_comments) { |
|
remove_comments_box.checked = true; |
|
} |
|
|
|
// Player radios |
|
var flash_option = document.getElementById('flash_option'); |
|
var html5_option = document.getElementById('html5_option'); |
|
if (player_option == PLAYER_FLASH) { |
|
if (flash_option) { |
|
flash_option.checked = true; |
|
} |
|
} else if (player_option == PLAYER_HTML5) { |
|
if (html5_option) { |
|
html5_option.checked = true; |
|
} |
|
} |
|
// Quality select |
|
var quality_select = document.getElementById('quality_select'); |
|
if (quality_select) { |
|
quality_select.value = quality_option; |
|
} |
|
|
|
var volume_percent_input = document.getElementById('volume_percent'); |
|
volume_percent_input.style.width = '40px'; |
|
volume_percent_input.value = volume_control; |
|
|
|
// Get the save button |
|
var submit_button = document.getElementById('menu_sumbit_button'); |
|
// Save the values and close the menu |
|
submit_button.onclick = menu_save; |
|
} else { |
|
menu_save(); |
|
} |
|
} |
|
|
|
var menu_save = function() { |
|
// Get all of the form choices for checking |
|
var pause_option_box = document.getElementById('pause_option_box'); |
|
var autoplay_option_box = document.getElementById('autoplay_option_box'); |
|
var autoplay_count_input = document.getElementById('autoplay_count'); |
|
var autoscroll_option_box = document.getElementById('autoscroll_option_box'); |
|
var resize_option_box = document.getElementById('resize_option_box'); |
|
var flash_option = document.getElementById('flash_option'); |
|
var html5_option = document.getElementById('html5_option'); |
|
var quality_select = document.getElementById('quality_select'); |
|
var arrow_nav_box = document.getElementById('arrow_nav_box'); |
|
var playback_speed_control_box = document.getElementById('playback_speed_control_box'); |
|
var volume_percent_input = document.getElementById('volume_percent'); |
|
var remove_login_box = document.getElementById('remove_login_box'); |
|
var remove_comments_box = document.getElementById('remove_comments_box'); |
|
|
|
// Update Greasemonkey stored values for options |
|
GM_setValue("pause", pause_option_box.checked); |
|
GM_setValue("auto", autoplay_option_box.checked); |
|
GM_setValue("scroll", autoscroll_option_box.checked); |
|
GM_setValue("auto_count", parseInt(autoplay_count_input.value)); |
|
GM_setValue("resize", resize_option_box.checked); |
|
GM_setValue("arrow_nav", arrow_nav_box.checked); |
|
GM_setValue("quality", quality_select.value); |
|
GM_setValue("speed_control", playback_speed_control_box.checked); |
|
GM_setValue("volume_control", volume_percent_input.value); |
|
GM_setValue("remove_login", remove_login_box.checked); |
|
GM_setValue("remove_comments", remove_comments_box.checked); |
|
|
|
// Check which player option is checked |
|
if (flash_option.checked) { |
|
// Update greasemonkey stored value |
|
GM_setValue("player", PLAYER_FLASH); |
|
// Set appropriate cookies |
|
document.cookie = 'usingFlashV1=true;path=/'; |
|
document.cookie = 'usingHTML5V1=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'; |
|
// Reload page if value has changed |
|
if (player_option != PLAYER_FLASH && video_page.test(url)) { |
|
document.location.href = document.location.href; |
|
} |
|
player_option = PLAYER_FLASH; |
|
} else if (html5_option.checked) { |
|
// Update greasemonkey stored value |
|
GM_setValue("player", PLAYER_HTML5); |
|
// Set appropriate cookies |
|
document.cookie = 'usingFlashV1=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'; |
|
document.cookie = 'usingHTML5V1=true;path=/'; |
|
// Reload page if value has changed |
|
if (player_option != PLAYER_HTML5 && video_page.test(url)) { |
|
document.location.href = document.location.href; |
|
} |
|
player_option = PLAYER_HTML5; |
|
} |
|
|
|
// Update this pages userscript options |
|
pause_option = pause_option_box.checked; |
|
autoplay_option = autoplay_option_box.checked; |
|
autoscroll_option = autoscroll_option_box.checked; |
|
arrow_key_navagation = arrow_nav_box.checked; |
|
autoplay_count = parseInt(autoplay_count_input.value); |
|
quality_option = quality_select.value; |
|
speed_control = playback_speed_control_box.checked; |
|
|
|
// Update unsafeWindow values that might matter if on video pages |
|
if (video_page.test(url)) { |
|
unsafeWindow.autoplay_option = autoplay_option_box.checked; |
|
unsafeWindow.autoplay_count = parseInt(autoplay_count_input.value); |
|
} |
|
|
|
menu.remove(); |
|
menu_open = false; |
|
} |
|
// Add the listener for keypresses |
|
document.addEventListener("keydown", global_key_listener); |
|
// Also add as GM menu command |
|
GM_registerMenuCommand("Options Menu", open_menu, "o"); |
|
|
|
// The search results |
|
var search_results = document.getElementById('result_box'); |
|
// The search form text box |
|
var search_form = document.getElementById('keyword'); |
|
// Current search selection, -1 if nothing |
|
var search_selection = -1; |
|
// used to scroll search results to current highlighted results |
|
var scroll_height = 0; |
|
// Interval for checking if any results match and appear |
|
var navigation_interval; |
|
// Used to count how many times results are checked for before giving up |
|
var navigation_attempts; |
|
// Key codes |
|
var UP_ARROW_KEY = 38; |
|
var DOWN_ARROW_KEY = 40; |
|
var ENTER_KEY = 13; |
|
// Prevent up and down arrow keys from causing the results to refresh |
|
var prevent_key_reg = function(event) { |
|
var key_pressed = event.which; |
|
if (key_pressed == UP_ARROW_KEY || key_pressed == DOWN_ARROW_KEY) { |
|
event.stopPropagation(); |
|
} |
|
} |
|
// Add above in the capture phase of event propagation, so it happens first |
|
document.addEventListener('keyup', prevent_key_reg, true); |
|
// Intercept Enter key press to check if anything is selected |
|
var go_to_selection = function(event) { |
|
var key_pressed = event.which; |
|
if (key_pressed == ENTER_KEY) { |
|
// Check if anything is selected |
|
if (search_selection >= 0 && search_selection < search_results.childElementCount) { |
|
// Go to selection |
|
document.location.href = search_results.children[search_selection].href; |
|
// Prevent form submission |
|
event.preventDefault(); |
|
} |
|
} |
|
} |
|
document.addEventListener('keydown', go_to_selection); |
|
// Navigate up and down in search results |
|
var navigate_search_results = function(event) { |
|
var key_pressed = event.which; |
|
if (key_pressed == UP_ARROW_KEY) { |
|
if (search_selection > 0) { |
|
search_results.children[search_selection].style.backgroundColor = ''; |
|
search_results.children[--search_selection].style.backgroundColor = '#565E66'; |
|
|
|
scroll_height -= search_results.children[search_selection + 1].clientHeight; |
|
if (search_selection == 0) { |
|
scroll_height = 0; |
|
} |
|
search_results.scrollTop = scroll_height; |
|
} |
|
} |
|
if (key_pressed == DOWN_ARROW_KEY) { |
|
if (search_selection < search_results.childElementCount - 1) { |
|
if (search_selection >= 0) { |
|
search_results.children[search_selection].style.backgroundColor = ''; |
|
} |
|
search_results.children[++search_selection].style.backgroundColor = '#565E66'; |
|
scroll_height += search_results.children[search_selection - 1].clientHeight; |
|
search_results.scrollTop = scroll_height; |
|
} |
|
} |
|
} |
|
// Checks if there are navigatable results and adds navigate listener |
|
var reset_navigation = function() { |
|
search_selection = -1; |
|
scroll_height = 0; |
|
++navigation_attempts; |
|
if (search_results.childElementCount > 0) { |
|
document.addEventListener('keydown', navigate_search_results); |
|
clearInterval(navigation_interval); |
|
} else { |
|
document.removeEventListener('keydown', navigate_search_results); |
|
if (navigation_attempts >= 10) { |
|
clearInterval(navigation_interval); |
|
} |
|
} |
|
|
|
} |
|
// Called everytime search text box input changes to see if there is navigatable results |
|
var try_navigation = function() { |
|
clearInterval(navigation_interval); |
|
navigation_attempts = 0; |
|
navigation_interval = setInterval(reset_navigation, 200); |
|
} |
|
search_form.addEventListener('input', try_navigation); |
|
|
|
console.log('Done!'); |
Can anyone help with this problem? http://i.imgur.com/mbvBR3s.png
The add-on works fine on other pages, but on anime pages it fails to remove certain elements like the login, and that panel with firefox, and it also doesn't show the video.
Also, i don't know if it's possible, but lately there have been some pop-up ads which show up when you click on the site, it would be nice if this script could remove that too.