Steam Video Overlay

让 Steam 游戏详情页面的视频悬浮起来~~~

As of 2015-02-05 09:00:28 UTC. See the latest version.

// ==UserScript==
// @name         Steam Video Overlay
// @version      0.1-alpha
// @description  让 Steam 游戏详情页面的视频悬浮起来~~~
// @author       NotaStudio
// @match        http://store.steampowered.com/app/*
// @match        https://store.steampowered.com/app/*
// @grant        none
// @license      GPLv3
// @namespace https://greasyfork.org/users/8882
// ==/UserScript==

// GPLv3 License
// http://www.gnu.org/licenses/gpl-3.0.html

/*
 * ChangeLog
 * 20150205 0.1-alpha
 * 首次发布
 */

var fileCode,minUrl,maxUrl,fileUrl;

console.log("土豪买买买!!!\n Steam Video Overlay 0.1-alpha\n Created by Nota\n 2015.02.05");

window.collectionToArray = function(collection) {
    var ary = []; 
    for(var i = 0, len = collection.length; i < len; i++) { 
        ary.push(collection[i]); 
    } 
    return ary; 
};
// 网上找的一个函数,作者应该是三水清(http://js8.in/)

window.getFileUrl = function() {
    var videoNode = document.getElementsByTagName("object");
    var i = collectionToArray(videoNode).pop();
    fileCode = i.innerHTML.match(/steam\/apps\/\d*/)[0].slice(11);
    minUrl = "http://cdn.akamai.steamstatic.com/steam/apps/" + fileCode + "/movie480.webm";
    maxUrl = "http://cdn.akamai.steamstatic.com/steam/apps/" + fileCode + "/movie_max.webm";
    if (screen.height > 768)
    {
        fileUrl = maxUrl;
    }
    else
    {
        fileUrl = minUrl;
    }
};

window.scrollEvent = function() {
    if (window.pageYOffset > screen.availHeight)
    {
        if (document.getElementById("svoWindow").style.display == "none")
        {
            document.getElementById("svoWindow").style.display = "inline";
        }
    }
    else
    {
        if (document.getElementById("svoWindow").style.display == "inline")
        {
            document.getElementById("svoWindow").style.display = "none";
        }
    }
    
};

window.changeVideo = function() {
    getFileUrl();
    document.body.removeChild(document.getElementById("svoWindow"));
    var videoNode = document.createElement("VIDEO");
    videoNode.setAttribute("src", fileUrl);
    videoNode.setAttribute("id", "svoWindow");
    videoNode.setAttribute("autoplay", "autoplay");
    videoNode.setAttribute("width", "30%");
    videoNode.setAttribute("height", "30%");
    videoNode.setAttribute("style", "display: none;z-index: 99999;position: fixed;bottom: 25px;right: 25px;top: auto;left: auto;");
    document.body.appendChild(videoNode);
};

window.createWindow = function() {   
    var videoNode = document.createElement("VIDEO");
    videoNode.setAttribute("src", fileUrl);
    videoNode.setAttribute("id", "svoWindow");
    videoNode.setAttribute("autoplay", "autoplay");
    videoNode.setAttribute("width", "30%");
    videoNode.setAttribute("height", "30%");
    videoNode.setAttribute("style", "display: none;z-index: 99999;position: fixed;bottom: 25px;right: 25px;top: auto;left: auto;");
    document.body.appendChild(videoNode);   
};

window.closeWindow = function() {
    document.body.setAttribute("onscroll","");
	document.getElementById("highlight_strip").setAttribute("onclick","");
	document.body.removeChild(document.getElementById("svoWindow"));
};

document.body.setAttribute("onscroll","scrollEvent()");
document.getElementById("highlight_strip").setAttribute("onclick","changeVideo()");
document.body.setAttribute("onload","getFileUrl();createWindow()");

var svoOptions = document.createElement("DIV");
var optionText = document.createTextNode("Steam Video Overlay 选项:");
svoOptions.setAttribute("class", "glance_tags_label");
svoOptions.appendChild(optionText);
document.body.getElementsByClassName("rightcol")[0].appendChild(svoOptions);

var closeButton = document.createElement("A");
var closeButtonSpan = document.createElement("SPAN");
var closeSpanText = document.createTextNode("关闭视频浮窗");
closeButton.setAttribute("onclick", "closeWindow()");
closeButton.setAttribute("class", "btnv6_blue_hoverfade btn_medium app_tag");
closeButtonSpan.appendChild(closeSpanText);
closeButton.appendChild(closeButtonSpan);
document.body.getElementsByClassName("rightcol")[0].appendChild(closeButton);