Created
April 24, 2018 05:40
-
-
Save YLaido/2612ea10c537ed0d960428770c672494 to your computer and use it in GitHub Desktop.
Fork of "Youku Browser Full Screen"
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 Youku Browser Full Screen | |
// @version 0.0.0.1 | |
// @description 给优酷的h5播放器增加一个网页全屏按钮,得等网页加载完了才能出来。 | |
// @include /v.youku.com/v_show.*/ | |
// @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js | |
// @run-at document-end | |
// @author AkiyamaYummy | |
// @namespace https://greasyfork.org/users/9356 | |
// ==/UserScript== | |
var player = document.getElementById("player"), | |
body = document.getElementsByTagName("body")[0]; | |
var playerMessage, | |
playerFullScreenMode, | |
playerFullScreenSwitchButton; | |
$(player).ready(function(){ | |
waitForKeyElements('.control-right-grid',function() { | |
browserFullScreenInit(); | |
$(playerFullScreenSwitchButton).click(function(){ | |
browserFullScreenSwitch(); | |
}); | |
}); | |
/*browserFullScreenInit(); | |
$(playerFullScreenSwitchButton).click(function(){ | |
browserFullScreenSwitch(); | |
});*/ | |
}); | |
function browserFullScreenInit() { | |
playerMessage = [["fixed"],["0px"],["0px"],["100%"],["100%"],["10000"],["hidden"]]; | |
playerMessage[0][1] = player.style.position; | |
playerMessage[1][1] = player.style.left; | |
playerMessage[2][1] = player.style.top; | |
playerMessage[3][1] = player.style.height; | |
playerMessage[4][1] = player.style.width; | |
playerMessage[5][1] = player.style.zIndex; | |
playerMessage[6][1] = body.style.overflow; | |
playerFullScreenMode = 1; | |
playerFullScreenSwitchButton = document.createElement("div"); | |
playerFullScreenSwitchButton.setAttribute("class","control-icon control-fullscreen-icon"); | |
playerFullScreenSwitchButton.setAttribute("data-tip","网页全屏"); | |
document.getElementsByClassName("control-right-grid")[0].appendChild(playerFullScreenSwitchButton); | |
} | |
function browserFullScreenSwitch() { | |
playerFullScreenMode = playerFullScreenMode^1; | |
player.style.position = playerMessage[0][playerFullScreenMode]; | |
player.style.left = playerMessage[1][playerFullScreenMode]; | |
player.style.top = playerMessage[2][playerFullScreenMode]; | |
player.style.height = playerMessage[3][playerFullScreenMode]; | |
player.style.width = playerMessage[4][playerFullScreenMode]; | |
player.style.zIndex = playerMessage[5][playerFullScreenMode]; | |
body.style.overflow = playerMessage[6][playerFullScreenMode]; | |
} | |
function waitForKeyElements ( // Credit: https://gist.github.com/mjblay/18d34d861e981b7785e407c3b443b99b | |
selectorTxt, /* Required: The selector string that | |
specifies the desired element(s). | |
*/ | |
actionFunction, /* Required: The code to run when elements are | |
found. It is passed a jNode to the matched | |
element. | |
*/ | |
bWaitOnce /* Optional: If false, will continue to scan for | |
new elements even after the first match is | |
found. | |
*/ | |
) { | |
var targetNodes, btargetsFound; | |
targetNodes = document.querySelectorAll(selectorTxt); | |
if (targetNodes && targetNodes.length > 0) { | |
btargetsFound = true; | |
/*--- Found target node(s). Go through each and act if they | |
are new. | |
*/ | |
targetNodes.forEach(function(element) { | |
var alreadyFound = element.dataset.found == 'alreadyFound' ? 'alreadyFound' : false; | |
if (!alreadyFound) { | |
//--- Call the payload function. | |
var cancelFound = actionFunction (element); | |
if (cancelFound) | |
btargetsFound = false; | |
else | |
element.dataset.found = 'alreadyFound'; | |
} | |
} ); | |
} | |
else { | |
btargetsFound = false; | |
} | |
//--- Get the timer-control variable for this selector. | |
var controlObj = waitForKeyElements.controlObj || {}; | |
var controlKey = selectorTxt.replace (/[^\w]/g, "_"); | |
var timeControl = controlObj [controlKey]; | |
//--- Now set or clear the timer as appropriate. | |
if (btargetsFound && bWaitOnce && timeControl) { | |
//--- The only condition where we need to clear the timer. | |
clearInterval (timeControl); | |
delete controlObj [controlKey]; | |
} | |
else { | |
//--- Set a timer, if needed. | |
if ( ! timeControl) { | |
timeControl = setInterval ( function () { | |
waitForKeyElements ( selectorTxt, | |
actionFunction, | |
bWaitOnce | |
); | |
}, | |
300 | |
); | |
controlObj [controlKey] = timeControl; | |
} | |
} | |
waitForKeyElements.controlObj = controlObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment