Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Doctored Version to remove embedding.
This file has been truncated, but you can view the full file.
/**
The MIT License (MIT)
Copyright © 2015 Jeppe Rune Mortensen
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**/
// ==UserScript==
// @id YouTubeCenter Mikhoul Hack to revove embedded
// @name YouTube Center Developer Build - Mikhoul Hack to revove embedded
// @namespace http://www.facebook.com/YouTubeCenter
// @version 548.01
// @author Jeppe Rune Mortensen <jepperm@gmail.com>
// @description YouTube Center Developer Build contains all kind of different useful functions which makes your visit on YouTube much more entertaining.
// @icon https://raw.github.com/YePpHa/YouTubeCenter/master/assets/icon48.png
// @icon64 https://raw.github.com/YePpHa/YouTubeCenter/master/assets/icon64.png
// @domain yeppha.github.io
// @domain youtube.com
// @domain www.youtube.com
// @domain gdata.youtube.com
// @domain apis.google.com
// @domain plus.googleapis.com
// @domain googleapis.com
// @domain raw.github.com
// @domain raw2.github.com
// @domain raw.githubusercontent.com
// @domain s.ytimg.com
// @match http://www.youtube.com/*
// @match https://www.youtube.com/*
// @match http://youtube.com/*
// @match https://youtube.com/*
// @match https://yeppha.github.io/downloads/YouTubeCenter.meta.js
// @match http://s.ytimg.com/yts/jsbin/*
// @match https://s.ytimg.com/yts/jsbin/*
// @match https://raw.github.com/YePpHa/YouTubeCenter/master/*
// @match https://raw.githubusercontent.com/YePpHa/YouTubeCenter/master/*
// @match http://raw.github.com/YePpHa/YouTubeCenter/master/*
// @match http://raw.githubusercontent.com/YePpHa/YouTubeCenter/master/*
// @match http://apis.google.com/*/widget/render/comments?*
// @match https://apis.google.com/*/widget/render/comments?*
// @match http://plus.googleapis.com/*/widget/render/comments?*
// @match https://plus.googleapis.com/*/widget/render/comments?*
// @include http://www.youtube.com/*
// @include https://www.youtube.com/*
// @include http://youtube.com/*
// @include https://youtube.com/*
// @include http://apis.google.com/*/widget/render/comments?*
// @include https://apis.google.com/*/widget/render/comments?*
// @include http://plus.googleapis.com/*/widget/render/comments?*
// @include https://plus.googleapis.com/*/widget/render/comments?*
// @exclude http://apiblog.youtube.com/*
// @exclude https://apiblog.youtube.com/*
// @exclude http://*.youtube.com/subscribe_embed?*
// @exclude https://*.youtube.com/subscribe_embed?*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_registerMenuCommand
// @grant unsafeWindow
// @updateURL https://github.com/YePpHa/YouTubeCenter/raw/master/dist/YouTubeCenter.meta.js
// @downloadURL https://github.com/YePpHa/YouTubeCenter/raw/master/dist/YouTubeCenter.user.js
// @updateVersion 155
// @run-at document-start
// @priority 9001
// @homepageURL https://github.com/YePpHa/YouTubeCenter/wiki
// @contributionURL https://github.com/YePpHa/YouTubeCenter/wiki/Donate
// @supportURL https://github.com/YePpHa/YouTubeCenter/issues
// @license MIT
// ==/UserScript==
(function(){
"use strict";
function inject(func, bypass) {
if (hasInjected && !bypass) return;
hasInjected = true;
injectScript(func);
}
function injectScript(func, filename, noArgs) {
filename = filename || "YouTubeCenter.js";
var script = document.createElement("script");
var parent = document.body || document.head || document.documentElement;
if (!parent) {
setTimeout(bind(null, injectScript, func, true), 0);
return;
}
script.setAttribute("type", "text/javascript");
if (typeof func === "string") {
func = "function(){" + func + "}";
}
var fn = "(" + func + ")";
if (noArgs) {
fn += "()";
} else {
fn += "(true, 0, true, 548)";
}
script.appendChild(document.createTextNode(fn + ";\n//# sourceURL=" + filename));
parent.appendChild(script);
parent.removeChild(script);
}
function bind(scope, func) {
var args = Array.prototype.slice.call(arguments, 2);
return function(){
return func.apply(scope, args.concat(Array.prototype.slice.call(arguments)))
};
}
function getNavigator() {
try {
if (window && typeof window.navigator === "object") {
return window.navigator;
} else if (typeof navigator === "object") {
return navigator;
}
} catch (e) {
return { /* empty */ };
}
}
function isCookieEnabled() {
try {
var cookieEnabled = getNavigator().cookieEnabled;
if (cookieEnabled === false) return false;
setCookie("ytc_cookie_test", "testing", ".youtube.com", "/", 3600*60*24*30);
var isEnabled = getCookie("ytc_cookie_test") === "testing";
// Removing the test cookie
setCookie("ytc_cookie_test", null, ".youtube.com", "/", 0);
return isEnabled;
} catch (e) {
return false;
}
}
function setCookie(name, value, domain, path, expires) {
domain = domain ? ";domain=" + encodeURIComponent(domain) : "";
path = path ? ";path=" + encodeURIComponent(path) : "";
expires = 0 > expires ? "" : 0 == expires ? ";expires=" + (new Date(1970, 1, 1)).toUTCString() : ";expires=" + (new Date(now() + 1E3 * expires)).toUTCString();
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + domain + path + expires;
}
function getCookie(key) {
return getCookies()[key];
}
function getCookies() {
function trimLeft(obj){
return obj.replace(/^\s+/, "");
}
function trimRight(obj){
return obj.replace(/\s+$/, "");
}
function map(obj, callback, thisArg) {
for (var i = 0, n = obj.length, a = []; i < n; i++) {
if (i in obj) a[i] = callback.call(thisArg, obj[i]);
}
return a;
}
var c = document.cookie, v = 0, cookies = {};
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
c = RegExp.$1;
v = 1;
}
if (v === 0) {
map(c.split(/[,;]/), function(cookie) {
var parts = cookie.split(/=/, 2),
name = decodeURIComponent(trimLeft(parts[0])),
value = parts.length > 1 ? decodeURIComponent(trimRight(parts[1])) : null;
cookies[name] = value;
});
} else {
map(c.match(/(?:^|\s+)([!#$%&'*+\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\-.0-9A-Z^`a-z|~]*|"(?:[\x20-\x7E\x80\xFF]|\\[\x00-\x7F])*")(?=\s*[,;]|$)/g), function($0, $1) {
var name = $0,
value = $1.charAt(0) === '"'
? $1.substr(1, -1).replace(/\\(.)/g, "$1")
: $1;
cookies[name] = value;
});
}
return cookies;
}
function isEmbeddedVideo() {
return !!loc.href.match(/^http(s)?:\/\/(www\.)?youtube\.com\/ZZZembed\//) || !!loc.href.match(/^http(s)?:\/\/(www\.)?youtube\.com\/ZZZwatch_popup\?\//);
}
var main_function = function(injected, identifier, devbuild, devnumber, _unsafeWindow, preloadedSettings, undefined){
"use strict";
/* UTILS */
function $UpdateChecker() {
if (!ytcenter.settings.enableUpdateChecker) return;
var curr = (new Date().getTime()),
c = curr - 1000*60*60*parseInt(ytcenter.settings.updateCheckerInterval);
con.log("Checking for updates in " + ((ytcenter.settings.updateCheckerLastUpdate - c)/1000/60/60) + " hours...");
if (c >= ytcenter.settings.updateCheckerLastUpdate) {
con.log("Checking for updates now...");
ytcenter.settings.updateCheckerLastUpdate = curr;
ytcenter.saveSettings();
ytcenter.checkForUpdates();
}
}
function $CreateAspectButton() {
var btn = document.createElement("button");
btn.className = "yt-uix-button yt-uix-tooltip" + (ytcenter.settings.aspectEnable ? "" : " hid") + (!ytcenter.watch7 ? " yt-uix-button-default" : " yt-uix-button-text");
btn.setAttribute("title", ytcenter.language.getLocale("BUTTON_ASPECT_TOOLTIP"));
btn.setAttribute("type", "button");
btn.setAttribute("role", "button");
ytcenter.events.addEvent("ui-refresh", function(){
btn.setAttribute("title", ytcenter.language.getLocale("BUTTON_ASPECT_TOOLTIP"));
if (ytcenter.settings.aspectEnable) {
ytcenter.utils.removeClass(btn, "hid");
} else {
ytcenter.utils.addClass(btn, "hid");
}
});
var btnContent = document.createElement("span");
btnContent.className = "yt-uix-button-content";
btnContent.textContent = ytcenter.language.getLocale("BUTTON_ASPECT_TEXT");
ytcenter.language.addLocaleElement(btnContent, "BUTTON_ASPECT_TEXT", "@textContent");
btn.appendChild(btnContent);
var arrow = document.createElement("img");
arrow.className = "yt-uix-button-arrow";
arrow.src = "//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif";
arrow.setAttribute("alt", "");
btn.appendChild(arrow);
var groups = {
'crop': 'BUTTON_ASPECT_CROP',
'stretch': 'BUTTON_ASPECT_STRETCH'
};
var groupChoices = {
'4:3': 'BUTTON_ASPECT_4:3',
'3:2': 'BUTTON_ASPECT_3:2',
'16:9': 'BUTTON_ASPECT_16:9'
};
var menu = document.createElement("ul");
menu.className = "yt-uix-button-menu yt-uix-button-menu-default yt-uix-button-menu-external hid";
menu.setAttribute("role", "menu");
menu.setAttribute("aria-haspopup", "true");
var playerAspectTMP = ytcenter.settings['aspectValue'];
var item;
item = document.createElement("span");
if (ytcenter.settings.aspectValue === "none") {
item.setAttribute("style", "background:#555!important;color:#FFF!important;");
}
item.className = "yt-uix-button-menu-item";
item.setAttribute("onclick", ";return false;");
item.textContent = ytcenter.language.getLocale("BUTTON_ASPECT_NONE");
ytcenter.language.addLocaleElement(item, "BUTTON_ASPECT_NONE", "@textContent");
ytcenter.utils.addEventListener(item, "click", function(){
playerAspectTMP = "none";
if (ytcenter.settings.aspectSave) {
ytcenter.settings['aspectValue'] = "none";
}
for (var i = 0; i < this.parentNode.parentNode.children.length; i++) {
if (this.parentNode.parentNode.children[i].children[0] && this.parentNode.parentNode.children[i].children[0].tagName === "SPAN") {
this.parentNode.parentNode.children[i].children[0].setAttribute("style", "");
}
}
this.setAttribute("style", "background:#555!important;color:#FFF!important;");
ytcenter.saveSettings();
ytcenter.player.aspect("none");
}, false);
var li = document.createElement("li");
li.setAttribute("role", "menuitem");
li.appendChild(item);
menu.appendChild(li);
item = document.createElement("span");
if (ytcenter.settings.aspectValue === "default") {
item.setAttribute("style", "background:#555!important;color:#FFF!important;");
}
item.className = "yt-uix-button-menu-item";
item.setAttribute("onclick", ";return false;");
item.textContent = ytcenter.language.getLocale("BUTTON_ASPECT_DEFAULT");
ytcenter.utils.addEventListener(item, "click", function(){
playerAspectTMP = "default";
if (ytcenter.settings.aspectSave) {
ytcenter.settings['aspectValue'] = "default";
}
for (var i = 0; i < this.parentNode.parentNode.children.length; i++) {
if (this.parentNode.parentNode.children[i].children[0] && this.parentNode.parentNode.children[i].children[0].tagName === "SPAN") {
this.parentNode.parentNode.children[i].children[0].setAttribute("style", "");
}
}
this.setAttribute("style", "background:#555!important;color:#FFF!important;");
ytcenter.saveSettings();
ytcenter.player.aspect("default");
}, false);
ytcenter.language.addLocaleElement(item, "BUTTON_ASPECT_DEFAULT", "@textContent");
li = document.createElement("li");
li.setAttribute("role", "menuitem");
li.appendChild(item);
menu.appendChild(li);
for (var group in groups) {
if (groups.hasOwnProperty(group)) {
item = document.createElement("li");
item.style.fontWeight = "bold";
item.style.padding = "6px";
item.textContent = ytcenter.language.getLocale(groups[group]);
ytcenter.language.addLocaleElement(item, groups[group], "@textContent");
menu.appendChild(item);
for (var child in groupChoices) {
if (groupChoices.hasOwnProperty(child)) {
if (child === "4:3" && group === "crop") continue;
var val = "yt:" + group + "=" + child;
item = document.createElement("span");
if (val === ytcenter.settings.aspectValue) {
item.setAttribute("style", "background:#555!important;color:#FFF!important;");
}
item.className = "yt-uix-button-menu-item";
item.setAttribute("role", "menuitem");
item.setAttribute("onclick", ";return false;");
item.textContent = ytcenter.language.getLocale(groupChoices[child]);
ytcenter.language.addLocaleElement(item, groupChoices[child], "@textContent");
ytcenter.utils.addEventListener(item, "click", (function(val, group, child){
return function(){
var val = "yt:" + group + "=" + child;
playerAspectTMP = val;
if (ytcenter.settings.aspectSave) {
ytcenter.settings['aspectValue'] = val;
}
for (var i = 0; i < this.parentNode.parentNode.children.length; i++) {
if (this.parentNode.parentNode.children[i].children[0] && this.parentNode.parentNode.children[i].children[0].tagName === "SPAN") {
this.parentNode.parentNode.children[i].children[0].setAttribute("style", "");
}
}
this.setAttribute("style", "background:#555!important;color:#FFF!important;");
ytcenter.saveSettings();
ytcenter.player.aspect(val);
};
})(val, group, child), false);
var li = document.createElement("li");
li.setAttribute("role", "menuitem");
li.appendChild(item);
menu.appendChild(li);
}
}
if (group === "crop") {
var val = "yt:" + group + "=24:10";
item = document.createElement("span");
if (val === ytcenter.settings.aspectValue) {
item.setAttribute("style", "background:#555!important;color:#FFF!important;");
}
item.className = "yt-uix-button-menu-item";
item.setAttribute("role", "menuitem");
item.setAttribute("onclick", ";return false;");
item.textContent = ytcenter.language.getLocale("BUTTON_ASPECT_24:10");
ytcenter.language.addLocaleElement(item, "BUTTON_ASPECT_24:10", "@textContent");
ytcenter.utils.addEventListener(item, "click", (function(val, group, child){
return function(){
var val = "yt:" + group + "=24:10";
playerAspectTMP = val;
if (ytcenter.settings.aspectSave) {
ytcenter.settings['aspectValue'] = val;
}
for (var i = 0; i < this.parentNode.parentNode.children.length; i++) {
if (this.parentNode.parentNode.children[i].children[0] && this.parentNode.parentNode.children[i].children[0].tagName === "SPAN") {
this.parentNode.parentNode.children[i].children[0].setAttribute("style", "");
}
}
this.setAttribute("style", "background:#555!important;color:#FFF!important;");
ytcenter.saveSettings();
ytcenter.player.aspect(val);
};
})(val, group, child), false);
var li = document.createElement("li");
li.setAttribute("role", "menuitem");
li.appendChild(item);
menu.appendChild(li);
}
}
}
item = document.createElement("div");
item.style.padding = "7px 9px 0 9px";
item.style.borderTop = "1px #555 solid";
var itemLabel = document.createElement("label");
var label = document.createTextNode(ytcenter.language.getLocale("SETTINGS_ASPECT_REMEMBER"));
itemLabel.appendChild(label);
ytcenter.language.addLocaleElement(label, "SETTINGS_ASPECT_REMEMBER", "@textContent");
var itemCheckbox = $CreateCheckbox(ytcenter.settings.aspectSave);
itemCheckbox.style.marginLeft = "3px";
ytcenter.utils.addEventListener(itemLabel, "click", function(){
ytcenter.settings.aspectSave = !ytcenter.settings.aspectSave;
if (ytcenter.settings.aspectSave) {
ytcenter.utils.addClass(itemCheckbox, "checked");
ytcenter.settings.aspectValue = playerAspectTMP;
} else {
ytcenter.utils.removeClass(itemCheckbox, "checked");
}
ytcenter.saveSettings();
}, false);
itemLabel.appendChild(itemCheckbox);
item.appendChild(itemLabel);
menu.appendChild(item);
btn.appendChild(menu);
ytcenter.placementsystem.addElement("ytcenter", "aspectbtn", btn);
}
function $CreateResizeButton() {
function getItemTitle(item) {
var dim = ytcenter.utils.calculateDimensions(item.config.width, item.config.height);
if (typeof item.config.customName !== "undefined" && item.config.customName !== "") {
return item.config.customName;
} else if (isNaN(parseInt(item.config.width)) && isNaN(parseInt(item.config.height))) {
return (item.config.large ? ytcenter.language.getLocale("SETTINGS_RESIZE_LARGE") : ytcenter.language.getLocale("SETTINGS_RESIZE_SMALL"));
} else {
return dim[0] + "×" + dim[1];
}
}
function getItemSubText(item) {
if (isNaN(parseInt(item.config.width)) && isNaN(parseInt(item.config.height))) {
return ytcenter.language.getLocale("SETTINGS_RESIZE_CENTER") + (item.config.scrollToPlayer ? " - " + ytcenter.language.getLocale("SETTINGS_RESIZE_SCROLLTOPLAYER") : "");
} else {
return (item.config.large ? ytcenter.language.getLocale("SETTINGS_RESIZE_LARGE") : ytcenter.language.getLocale("SETTINGS_RESIZE_SMALL")) + " - " + ytcenter.language.getLocale("SETTINGS_RESIZE_CENTER") + (item.config.scrollToPlayer ? " - " + ytcenter.language.getLocale("SETTINGS_RESIZE_SCROLLTOPLAYER") : "");
}
}
function setValue(id) {
var item;
ytcenter.utils.each(ytcenter.settings["resize-playersizes"], function(i, val){
if (val.id !== ytcenter.player.currentResizeId) return;
item = val;
return false;
});
}
function updateItems(items) {
menu.innerHTML = "";
var db = [];
ytcenter.utils.each(items, function(i, item){
var li = document.createElement("li");
li.setAttribute("role", "menuitem");
var span = document.createElement("span");
db.push(span);
span.className = "yt-uix-button-menu-item" + (ytcenter.player.currentResizeId === item.id ? " ytcenter-resize-dropdown-selected" : "");
span.style.paddingBottom = "12px";
if (ytcenter.player.currentResizeId === item.id) {
setValue(ytcenter.player.currentResizeId);
}
var title = document.createElement("span");
title.textContent = getItemTitle(item);
ytcenter.events.addEvent("ui-refresh", function(){
title.textContent = getItemTitle(item);
});
title.style.display = "block";
title.style.fontWeight = "bold";
var subtext = document.createElement("span");
subtext.textContent = getItemSubText(item);
ytcenter.events.addEvent("ui-refresh", function(){
subtext.textContent = getItemSubText(item);
});
subtext.style.display = "block";
subtext.style.fontSize = "11px";
subtext.style.lineHeight = "0px";
ytcenter.utils.addEventListener(li, "click", function(){
try {
ytcenter.player.currentResizeId = item.id;
ytcenter.player.updateResize();
setValue(ytcenter.player.currentResizeId);
try {
document.body.click();
} catch (e) {
con.error(e);
}
ytcenter.utils.each(db, function(_i, elm){
ytcenter.utils.removeClass(elm, "ytcenter-resize-dropdown-selected");
});
ytcenter.utils.addClass(span, "ytcenter-resize-dropdown-selected");
} catch (e) {
con.error(e);
}
});
span.appendChild(title);
span.appendChild(subtext);
li.appendChild(span);
menu.appendChild(li);
});
}
var btnLabel = ytcenter.gui.createYouTubeButtonTextLabel("BUTTON_RESIZE_TEXT");
var menu = document.createElement("ul");
menu.className = "yt-uix-button-menu yt-uix-button-menu-default yt-uix-button-menu-external hid";
menu.setAttribute("role", "menu");
var arrow = ytcenter.gui.createYouTubeButtonArrow();
var btn = ytcenter.gui.createYouTubeButton("BUTTON_RESIZE_TOOLTIP", [btnLabel, arrow, menu]);
btn.style.textAlign = "left";
if (ytcenter.settings.resizeEnable && ytcenter.settings.enableResize) {
ytcenter.utils.removeClass(btn, "hid");
} else {
ytcenter.utils.addClass(btn, "hid");
}
updateItems(ytcenter.settings["resize-playersizes"]);
ytcenter.events.addEvent("settings-update", function(){
updateItems(ytcenter.settings["resize-playersizes"]);
});
ytcenter.player.resizeCallback.push(function(){
updateItems(ytcenter.settings["resize-playersizes"]);
});
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.resizeEnable && ytcenter.settings.enableResize) {
ytcenter.utils.removeClass(btn, "hid");
} else {
ytcenter.utils.addClass(btn, "hid");
}
});
ytcenter.placementsystem.addElement("ytcenter", "resizebtn", btn);
}
function $CreateCheckbox(_checked) {
var checked = _checked || false;
var cont = document.createElement("span");
cont.className = "yt-uix-form-input-checkbox-container" + (checked ? " checked" : "");
var inp = document.createElement("input");
inp.setAttribute("type", "checkbox");
inp.className = "yt-uix-form-input-checkbox";
inp.value = "true";
if (checked) {
inp.checked = "checked";
}
var span = document.createElement("span");
span.className = "yt-uix-form-input-checkbox-element";
cont.appendChild(inp);
cont.appendChild(span);
return cont;
}
function $CreateLightButton() {
var btn = document.createElement("button");
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.lightbulbEnable) {
ytcenter.utils.removeClass(btn, "hid");
} else {
ytcenter.utils.addClass(btn, "hid");
}
});
btn.setAttribute("onclick", ";return false;");
btn.setAttribute("type", "button");
btn.setAttribute("role", "button");
btn.className = "yt-uix-button yt-uix-tooltip" + (ytcenter.settings.lightbulbEnable ? "" : " hid") + (!ytcenter.watch7 ? " yt-uix-button-default" : " yt-uix-button-text");
btn.title = ytcenter.language.getLocale("LIGHTBULB_TOOLTIP");
//btn.style.marginLeft = ".5em";
ytcenter.language.addLocaleElement(btn, "LIGHTBULB_TOOLTIP", "title");
var s = document.createElement("span");
s.className = "yt-uix-button-content";
var icon = document.createElement("img");
icon.setAttribute("alt", "");
icon.src = ytcenter.icon.lightbulb;
s.appendChild(icon);
btn.appendChild(s);
ytcenter.utils.addEventListener(btn, "click", function(){
ytcenter.player.toggleLights();
}, false);
ytcenter.placementsystem.addElement("ytcenter", "lightbtn", btn);
}
function $CreateRepeatButton() {
var btn = document.createElement("button");
btn.style.margin = "0 2px 0 0";
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.enableRepeat) {
ytcenter.utils.removeClass(btn, 'hid');
} else {
ytcenter.utils.addClass(btn, 'hid');
}
});
btn.title = ytcenter.language.getLocale("BUTTON_REPEAT_TOOLTIP");
ytcenter.language.addLocaleElement(btn, "BUTTON_REPEAT_TOOLTIP", "title");
btn.setAttribute("role", "button");
btn.setAttribute("type", "button");
btn.setAttribute("onclick", ";return false;");
btn.className = "yt-uix-button yt-uix-tooltip" + (ytcenter.settings.autoActivateRepeat ? " ytcenter-uix-button-toggled" : " yt-uix-button-text") + (ytcenter.settings.enableRepeat ? "" : " hid");
ytcenter.utils.addEventListener(btn, "click", function(){
if (ytcenter.doRepeat) {
ytcenter.utils.removeClass(this, 'ytcenter-uix-button-toggled');
ytcenter.utils.addClass(this, 'yt-uix-button-text');
ytcenter.doRepeat = false;
} else {
ytcenter.utils.addClass(this, 'ytcenter-uix-button-toggled');
ytcenter.utils.removeClass(this, 'yt-uix-button-text');
ytcenter.doRepeat = true;
}
}, false);
if (ytcenter.settings.autoActivateRepeat) {
ytcenter.doRepeat = true;
} else {
ytcenter.doRepeat = false;
}
var iconw = document.createElement("span");
iconw.className = "yt-uix-button-icon-wrapper";
if (!ytcenter.settings.repeatShowIcon) {
iconw.style.display = "none";
}
var icon = document.createElement("img");
icon.className = "yt-uix-button-icon " + (ytcenter.watch7 ? "ytcenter-repeat-icon" : "yt-uix-button-icon-playlist-bar-autoplay");
icon.src = "//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif";
if (!ytcenter.watch7) {
icon.style.background = "no-repeat url(//s.ytimg.com/yts/imgbin/www-refresh-vflMaphyY.png) -173px -60px";
icon.style.width = "20px";
icon.style.height = "17px";
}
/*icon.style.width = "20px";
icon.style.height = "18px";
icon.style.background = "no-repeat url(//s.ytimg.com/yt/imgbin/www-master-vfl8ZHa_q.png) -303px -38px";*/
icon.setAttribute("alt", "");
iconw.appendChild(icon);
btn.appendChild(iconw);
var t = document.createElement("span");
t.className = "yt-uix-button-content";
t.textContent = ytcenter.language.getLocale("BUTTON_REPEAT_TEXT");
ytcenter.language.addLocaleElement(t, "BUTTON_REPEAT_TEXT", "@textContent");
if (!ytcenter.settings.repeatShowText) {
t.style.display = "none";
}
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.repeatShowIcon) {
iconw.style.display = "";
} else {
iconw.style.display = "none";
}
if (ytcenter.settings.repeatShowText) {
t.style.display = "";
} else {
t.style.display = "none";
}
});
btn.appendChild(t);
ytcenter.placementsystem.addElement("ytcenter", "repeatbtn", btn);
}
function $DownloadButtonStream() {
var priority = ['small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'highres'];
var stream;
var format = (function(){
for (var i = 0; i < ytcenter.video.format.length; i++) {
if (ytcenter.settings.downloadFormat == ytcenter.video.format[i].key) {
return ytcenter.video.format[i].type;
}
}
return ytcenter.language.getLocale("UNKNOWN");
})();
for (var i = 0; i < ytcenter.video.streams.length; i++) {
if ((stream == null || $ArrayIndexOf(priority, ytcenter.video.streams[i].quality) > $ArrayIndexOf(priority, stream.quality)) && $ArrayIndexOf(priority, ytcenter.video.streams[i].quality) <= $ArrayIndexOf(priority, ytcenter.settings.downloadQuality) && ytcenter.video.streams[i].type && ytcenter.video.streams[i].type.indexOf(format) == 0 && ytcenter.video.streams[i].url) {
stream = ytcenter.video.streams[i];
}
}
return stream;
}
function $CreateDownloadButton() {
if (identifier === 8) return; // The Chrome Webstore version of YouTube Center Developer Build has the download feature disabled.
var g = document.createElement("span");
g.style.margin = "0 2px 0 0";
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.enableDownload) {
ytcenter.utils.removeClass(g, "hid");
g.style.display = "";
} else {
ytcenter.utils.addClass(g, "hid");
g.style.display = "none";
}
});
g.className = "yt-uix-button-group" + (ytcenter.settings.enableDownload ? "" : " hid");
if (!ytcenter.settings.enableDownload) {
g.style.display = "none";
}
var stream = $DownloadButtonStream();
var btn1a = document.createElement("a");
if (stream) {
btn1a.setAttribute("href", ytcenter.video.downloadLink(stream));
btn1a.setAttribute("download", ytcenter.video.getFilename(stream) + ytcenter.video.getFilenameExtension(stream));
}
btn1a.setAttribute("target", "_blank");
ytcenter.events.addEvent("ui-refresh", function(){
stream = $DownloadButtonStream();
if (stream) {
btn1a.setAttribute("href", ytcenter.video.downloadLink(stream));
btn1a.setAttribute("download", ytcenter.video.getFilename(stream) + ytcenter.video.getFilenameExtension(stream));
}
});
var btn1 = document.createElement("button");
btn1.className = "start yt-uix-button yt-uix-tooltip" + (!ytcenter.watch7 ? " yt-uix-button-default" : " yt-uix-button-text");
//btn1.setAttribute("onclick", ";return false;");
btn1.setAttribute("type", "button");
btn1.setAttribute("role", "button");
ytcenter.utils.addEventListener(btn1, "click", function(e){
if (!ytcenter.settings.downloadAsLinks) {
stream = $DownloadButtonStream();
if (stream) {
ytcenter.video.download(stream.itag);
}
e.preventDefault();
}
}, false);
if (stream != null) {
var stream_name = {
highres: ytcenter.language.getLocale("HIGHRES"),
hd1440: ytcenter.language.getLocale("HD1440"),
hd1080: ytcenter.language.getLocale("HD1080"),
hd720: ytcenter.language.getLocale("HD720"),
large: ytcenter.language.getLocale("LARGE"),
medium: ytcenter.language.getLocale("MEDIUM"),
small: ytcenter.language.getLocale("SMALL")
}[stream.quality];
btn1.title = ytcenter.utils.replaceTextAsString(ytcenter.language.getLocale("BUTTON_DOWNLOAD_TOOLTIP"), {
stream_name: stream_name,
stream_resolution: (stream.dimension ? stream.dimension.split("x")[1] + "p" : "N/A"),
stream_dimension: stream.dimension,
stream_3d: (stream.stereo3d && stream.stereo3d == 1 ? "&nbsp;3D" : ""),
stream_type: (function(stream){
for (var i = 0; i < ytcenter.video.format.length; i++) {
if (stream.type.indexOf(ytcenter.video.format[i].type) == 0) {
return ytcenter.language.getLocale(ytcenter.video.format[i].name);
}
}
return ytcenter.language.getLocale("UNKNOWN");
})(stream)
});
} else {
btn1.title = ytcenter.utils.replaceTextAsString(ytcenter.language.getLocale("BUTTON_DOWNLOAD_TOOLTIP_NONE"), {
type: (function(){
for (var i = 0; i < ytcenter.video.format.length; i++) {
if (ytcenter.settings.downloadFormat == ytcenter.video.format[i].key) {
return ytcenter.language.getLocale(ytcenter.video.format[i].name);
}
}
return ytcenter.language.getLocale("UNKNOWN");
})()
});
}
ytcenter.events.addEvent("ui-refresh", function(){
var stream = $DownloadButtonStream();
if (stream != null) {
var stream_name = {
highres: ytcenter.language.getLocale("HIGHRES"),
hd1440: ytcenter.language.getLocale("HD1440"),
hd1080: ytcenter.language.getLocale("HD1080"),
hd720: ytcenter.language.getLocale("HD720"),
large: ytcenter.language.getLocale("LARGE"),
medium: ytcenter.language.getLocale("MEDIUM"),
small: ytcenter.language.getLocale("SMALL")
}[stream.quality];
btn1.title = ytcenter.utils.replaceTextAsString(ytcenter.language.getLocale("BUTTON_DOWNLOAD_TOOLTIP"), {
stream_name: stream_name,
stream_resolution: (stream.dimension ? stream.dimension.split("x")[1] + "p" : "N/A"),
stream_dimension: stream.dimension,
stream_3d: (stream.stereo3d && stream.stereo3d == 1 ? " 3D" : ""),
stream_type: (function(stream){
for (var i = 0; i < ytcenter.video.format.length; i++) {
if (stream.type.indexOf(ytcenter.video.format[i].type) == 0) {
return ytcenter.language.getLocale(ytcenter.video.format[i].name);
}
}
return ytcenter.language.getLocale("UNKNOWN");
})(stream)
});
} else {
btn1.title = ytcenter.utils.replaceTextAsString(ytcenter.language.getLocale("BUTTON_DOWNLOAD_TOOLTIP_NONE"), {
type: (function(){
for (var i = 0; i < ytcenter.video.format.length; i++) {
if (ytcenter.settings.downloadFormat == ytcenter.video.format[i].key) {
return ytcenter.language.getLocale(ytcenter.video.format[i].name);
}
}
return ytcenter.language.getLocale("UNKNOWN");
})()
});
}
});
btn1a.appendChild(btn1);
var btn1_text = document.createElement("span");
btn1_text.className = "yt-uix-button-content";
btn1_text.textContent = ytcenter.language.getLocale("BUTTON_DOWNLOAD_TEXT");
ytcenter.language.addLocaleElement(btn1_text, "BUTTON_DOWNLOAD_TEXT", "@textContent");
btn1.appendChild(btn1_text);
g.appendChild(btn1a);
var btn2 = document.createElement("button");
btn2.className = "end yt-uix-button yt-uix-tooltip" + (!ytcenter.watch7 ? " yt-uix-button-default" : " yt-uix-button-text");
btn2.setAttribute("onclick", ";return false;");
btn2.setAttribute("type", "button");
btn2.setAttribute("role", "button");
btn2.title = ytcenter.language.getLocale("BUTTON_DOWNlOAD2_TOOLTIP");
ytcenter.language.addLocaleElement(btn2, "BUTTON_DOWNlOAD2_TOOLTIP", "title");
var img = document.createElement("img");
img.className = "yt-uix-button-arrow";
img.src = "//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif";
img.setAttribute("alt", "");
img.style.marginLeft = "0px";
img.style.marginRight = "0px";
btn2.appendChild(img);
var stream_groups = (function(){
var groups = (function(){
var obj = {};
for (var i = 0; i < ytcenter.video.format.length; i++) {
obj[ytcenter.video.format[i].type] = {
label: ytcenter.video.format[i].name,
key: ytcenter.video.format[i].key,
help: ytcenter.video.format[i].help
};
}
return obj;
})();
var sorted = {};
for (var i = 0; i < ytcenter.video.streams.length; i++) {
if (ytcenter.video.streams[i].type.indexOf("audio/mp4") !== 0 && (ytcenter.video.streams[i].size || ytcenter.video.streams[i].bitrate)) continue;
if (ytcenter.video.streams[i].type) {
var f = ytcenter.video.streams[i].type.split(";")[0];
if (groups.hasOwnProperty(f)) {
if (!sorted[groups[f].label]) sorted[groups[f].label] = {streams: [], key: groups[f].key, help: groups[f].help};
sorted[groups[f].label].streams.push(ytcenter.video.streams[i]);
} else {
if (!sorted['UNKNOWN']) sorted['UNKNOWN'] = {streams: [], key: "unknown"};
sorted['UNKNOWN'].streams.push(ytcenter.video.streams[i]);
}
} else {
if (!sorted['UNKNOWN']) sorted['UNKNOWN'] = {streams: [], key: "unknown"};
sorted['UNKNOWN'].streams.push(ytcenter.video.streams[i]);
}
}
return sorted;
})();
var menu = document.createElement("ul");
menu.className = "yt-uix-button-menu yt-uix-button-menu-default yt-uix-button-menu-external hid" + (ytcenter.settings.show3DInDownloadMenu ? "" : " ytcenter-menu-3d-hide");
menu.setAttribute("role", "menu");
menu.setAttribute("aria-haspopup", "true");
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.show3DInDownloadMenu) {
ytcenter.utils.removeClass(menu, "ytcenter-menu-3d-hide");
} else {
ytcenter.utils.addClass(menu, "ytcenter-menu-3d-hide");
}
});
for (var key in stream_groups) {
if (stream_groups.hasOwnProperty(key)) {
var title = document.createElement("li");
title.setAttribute("role", "menuitem");
title.style.color = "#666";
title.style.fontSize = "0.9166em";
title.style.paddingLeft = "9px";
if (key !== "UNKNOWN") {
var __t = document.createTextNode(ytcenter.language.getLocale(key));
title.appendChild(__t);
ytcenter.language.addLocaleElement(__t, key, "@textContent");
title.className = "ytcenter-downloadmenu-" + stream_groups[key].key;
if (stream_groups[key].help) {
var help = document.createElement("a");
help.setAttribute("href", stream_groups[key].help);
help.setAttribute("target", "_blank");
help.setAttribute("style", "vertical-align: super; font-size: 10px");
help.appendChild(document.createTextNode('?'));
var replace = {
option: {
toString: function() { return ytcenter.language.getLocale(key); }
}
};
help.setAttribute("title", ytcenter.utils.replaceTextAsString(ytcenter.language.getLocale("SETTINGS_HELP_ABOUT"), replace));
ytcenter.language.addLocaleElement(help, "SETTINGS_HELP_ABOUT", "title", replace);
title.appendChild(help);
}
} else {
title.className = "ytcenter-downloadmenu-unknown";
title.textContent = ytcenter.language.getLocale("UNKNOWN");
ytcenter.language.addLocaleElement(title, "UNKNOWN", "@textContent");
}
//stream_groups[key] = stream_groups[key].streams; // Just lazy...
menu.appendChild(title);
for (var i = 0; i < stream_groups[key].streams.length; i++) {
var is3D = (stream_groups[key].streams[i].stereo3d && stream_groups[key].streams[i].stereo3d == 1 ? true : false);
var item = document.createElement("a");
if (!stream_groups[key].streams[i].url) {
item.style.color = "#A7A7A7";
item.style.display = "block";
item.style.margin = "0";
item.style.padding = "6px 20px";
item.style.textDecoration = "none";
item.style.whiteSpace = "nowrap";
item.style.wordWrap = "normal";
} else {
item.className = "yt-uix-button-menu-item";
item.setAttribute("target", "_blank");
item.setAttribute("download", ytcenter.video.getFilename(stream_groups[key].streams[i]) + ytcenter.video.getFilenameExtension(stream_groups[key].streams[i]));
item.href = ytcenter.video.downloadLink(stream_groups[key].streams[i]);
var downloadStreamListener = (function(_stream){
return function(e){
if (!ytcenter.settings.downloadAsLinks) {
ytcenter.video.download(_stream.itag);
e.preventDefault();
}
};
})(stream_groups[key].streams[i]);
ytcenter.utils.addEventListener(item, "click", downloadStreamListener, false);
ytcenter.events.addEvent("ui-refresh", (function(__stream, item, _downloadStreamListener){
return function(){
item.href = ytcenter.video.downloadLink(__stream);
item.setAttribute("download", ytcenter.video.getFilename(__stream) + ytcenter.video.getFilenameExtension(__stream));
};
})(stream_groups[key].streams[i], item, downloadStreamListener));
}
var stream_name = {
highres: ytcenter.language.getLocale("HIGHRES"),
hd1440: ytcenter.language.getLocale("HD1440"),
hd1080: ytcenter.language.getLocale("HD1080"),
hd720: ytcenter.language.getLocale("HD720"),
large: ytcenter.language.getLocale("LARGE"),
medium: ytcenter.language.getLocale("MEDIUM"),
small: ytcenter.language.getLocale("SMALL")
}[stream_groups[key].streams[i].quality];
var _t = document.createElement("table"), _tb = document.createElement("tbody"), _tr = document.createElement("tr"), _td = document.createElement("td"), _td2 = document.createElement("td");
_t.style.width = "100%";
_t.style.border = "0";
_t.style.margin = "0";
_t.style.padding = "0";
if (stream_groups[key].streams[i].bitrate) {
_td.textContent = Math.round(parseInt(stream_groups[key].streams[i].bitrate)/1000) + " Kbps";
} else {
_td.textContent = stream_name + ", " + (stream_groups[key].streams[i].dimension ? stream_groups[key].streams[i].dimension.split("x")[1] : "") + "p (" + (stream_groups[key].streams[i].dimension ? stream_groups[key].streams[i].dimension : "") + ")";
_td2.textContent = (is3D ? "&nbsp;3D" : "");
}
_tr.appendChild(_td);
_tr.appendChild(_td2);
_tb.appendChild(_tr);
_t.appendChild(_tb);
item.appendChild(_t);
ytcenter.events.addEvent("ui-refresh", (function(stream, _is3D, _td, _td2){
return function(){
var stream_name = {
highres: ytcenter.language.getLocale("HIGHRES"),
hd1440: ytcenter.language.getLocale("HD1440"),
hd1080: ytcenter.language.getLocale("HD1080"),
hd720: ytcenter.language.getLocale("HD720"),
large: ytcenter.language.getLocale("LARGE"),
medium: ytcenter.language.getLocale("MEDIUM"),
small: ytcenter.language.getLocale("SMALL")
}[stream.quality];
if (stream.bitrate) {
_td.textContent = Math.round(parseInt(stream.bitrate)/1000) + " Kbps";
} else {
_td.textContent = stream_name + ", " + (stream.dimension ? stream.dimension.split("x")[1] : "") + "p (" + (stream.dimension ? stream.dimension : "") + ")";
_td2.textContent = (_is3D ? "&nbsp;3D" : "");
}
};
})(stream_groups[key].streams[i], is3D, _td, _td2));
var li = document.createElement("li");
li.className = "ytcenter-downloadmenu-" + (stream_groups[key].key === "UNKNOWN" ? "unknown" : stream_groups[key].key) + (is3D ? " ytcenter-menu-item-3d" : "");
li.setAttribute("role", "menuitem");
li.appendChild(item);
menu.appendChild(li);
}
}
}
var mp3title = document.createElement("li");
mp3title.className = (ytcenter.settings.mp3Services == '' ? "hid" : "");
if (ytcenter.settings.mp3Services === '') {
mp3title.style.display = "none";
}
mp3title.style.color = "#666";
mp3title.style.fontSize = "0.9166em";
mp3title.style.paddingLeft = "9px";
mp3title.textContent = ytcenter.language.getLocale("BUTTON_DOWNLOAD_MENU_MP3SERVICES");
ytcenter.language.addLocaleElement(mp3title, "BUTTON_DOWNLOAD_MENU_MP3SERVICES", "@textContent");
ytcenter.events.addEvent("ui-refresh", function(){
if (ytcenter.settings.mp3Services === '') {
ytcenter.utils.addClass(mp3title, 'hid');
mp3title.style.display = "none";
} else {
ytcenter.utils.removeClass(mp3title, 'hid');
mp3title.style.display = "";
}
});
menu.appendChild(mp3title);
var hasMP3Service = function(value){
var a = ytcenter.settings.mp3Services.split("&");
for (var i = 0; i < a.length; i++) {
if (decodeURIComponent(a[i]) === value) {
return true;
}
}
return false;
};
var removeNonExistentMP3Services = function(){
var newArr = [];
var a = ytcenter.settings.mp3Services.split("&");
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < ytcenter.mp3services.length; j++) {
if (ytcenter.mp3services[j].value === decodeURIComponent(a[i])) {
newArr.push(a[i]);
break;
}
}
}
ytcenter.settings.mp3Services = newArr.join("&");
};
removeNonExistentMP3Services();
for (var i = 0; i < ytcenter.mp3services.length; i++) {
var li = document.createElement("li");
var item = document.createElement("a");
item.className = "yt-uix-button-menu-item";
li.setAttribute("role", "menuitem");
li.className = "ytcenter-downloadmenu-MP3" + (hasMP3Service(ytcenter.mp3services[i].value) ? "" : " hid");
if (!hasMP3Service(ytcenter.mp3services[i].value)) {
li.style.display = "none";
}
item.setAttribute("href", ytcenter.utils.replaceTextAsString(ytcenter.mp3services[i].value, {
title: ytcenter.video.title,
videoid: ytcenter.video.id,
author: ytcenter.video.author,
url: loc.href
}));
item.setAttribute("target", "_blank");
var mp3RedirectListener = (function(mp3){
return function(e){
if (!ytcenter.settings.downloadAsLinks) {
ytcenter.redirect(mp3.value, true);
e.preventDefault();
return false;
}
};
})(ytcenter.mp3services[i]);
ytcenter.utils.addEventListener(item, "click", mp3RedirectListener, false);
ytcenter.events.addEvent("ui-refresh", (function(mp3, li){
return function(){
var a = ytcenter.settings.mp3Services.split("&");
var f = false;
for (var i = 0; i < a.length; i++) {
if (decodeURIComponent(a[i]) === mp3.value) {
f = true;
break;
}
}
if (f) {
ytcenter.utils.removeClass(li, 'hid');
li.style.display = "";
} else {
ytcenter.utils.addClass(li, 'hid');
li.style.display = "none";
}
};
})(ytcenter.mp3services[i], li));
item.textContent = ytcenter.language.getLocale(ytcenter.mp3services[i].label);
ytcenter.language.addLocaleElement(item, ytcenter.mp3services[i].label, "@textContent");
li.appendChild(item);
menu.appendChild(li);
}
btn2.appendChild(menu);
g.appendChild(btn2);
ytcenter.placementsystem.addElement("ytcenter", "downloadgroup", g);
}
function $CreateSettingsUI() {
var appbar = document.getElementById("appbar-settings-menu"),
appSecondaryContainer = document.getElementById("appbar-secondary-container"),
liSettings = document.createElement("li"),
spanText = document.createElement("span"),
textIconContainer = document.createElement("span"),
textIcon = document.createElement("img"),
text = null;
if (ytcenter.feather) {
var wrapper = document.getElementById("us"),
aLink = document.createElement("a"),
gearicon = document.createElement("img");
gearicon.src = ytcenter.icon.gear;
gearicon.setAttribute("alt", "");
aLink.appendChild(gearicon);
aLink.className = "ml";
aLink.setAttribute("href", "javascript:void(0);");
ytcenter.utils.addEventListener(aLink, "click", function(e){
if (!ytcenter.settingsPanelDialog) ytcenter.settingsPanelDialog = ytcenter.settingsPanel.createDialog();
ytcenter.settingsPanelDialog.setVisibility(true);
e && e.preventDefault && e.preventDefault();
return false;
}, false);
aLink.title = ytcenter.language.getLocale("BUTTON_SETTINGS_TITLE");
ytcenter.language.addLocaleElement(aLink, "BUTTON_SETTINGS_TITLE", "title");
wrapper.appendChild(aLink);
} else if (appbar) {
liSettings.setAttribute("id", "ytcenter-settings-toggler");
liSettings.setAttribute("role", "menuitem");
liSettings.className = "yt-uix-button-menu-new-section-separator";
spanText.className = "yt-uix-button-menu-item upload-menu-item";
ytcenter.utils.addEventListener(spanText, "click", function(){
if (!ytcenter.settingsPanelDialog) ytcenter.settingsPanelDialog = ytcenter.settingsPanel.createDialog();
ytcenter.settingsPanelDialog.setVisibility(true);
}, false);
textIconContainer.className = "yt-valign icon-container";
textIcon.className = "upload-menu-account-settings-icon yt-valign-container";
textIcon.setAttribute("src", "//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif");
textIconContainer.appendChild(textIcon);
text = document.createTextNode(ytcenter.language.getLocale("BUTTON_SETTINGS_LABEL"));
ytcenter.language.addLocaleElement(text, "BUTTON_SETTINGS_LABEL", "@textContent");
spanText.appendChild(textIconContainer);
spanText.appendChild(text);
liSettings.appendChild(spanText);
appbar.appendChild(liSettings);
} else if (appSecondaryContainer) {
var btn = document.createElement("button"),
iconWrapper = document.createElement("span"),
icon = document.createElement("img");
btn.className = "appbar-action-button flip yt-uix-button yt-uix-button-default yt-uix-button-size-default yt-uix-button-has-icon yt-uix-button-empty yt-uix-tooltip";
btn.title = ytcenter.language.getLocale("BUTTON_SETTINGS_TITLE");
ytcenter.language.addLocaleElement(btn, "BUTTON_SETTINGS_TITLE", "title");
btn.setAttribute("type", "button");
btn.setAttribute("role", "button");
btn.setAttribute("onclick", ";return false;");
ytcenter.utils.addEventListener(btn, "click", function(){
if (!ytcenter.settingsPanelDialog) ytcenter.settingsPanelDialog = ytcenter.settingsPanel.createDialog();
ytcenter.settingsPanelDialog.setVisibility(true);
}, false);
iconWrapper.className = "yt-uix-button-icon-wrapper";
icon.className = "yt-uix-button-icon yt-uix-button-icon-appbar-settings";
icon.src = "https://s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif";
icon.setAttribute("alt", "");
icon.setAttribute("title", "");
iconWrapper.appendChild(icon);
btn.appendChild(iconWrapper);
appSecondaryContainer.appendChild(btn);
} else {
var btn = document.createElement("button");
btn.id = "masthead-user-button";
if (document.getElementById("masthead-gaia-photo-expander")) {
btn.style.marginTop = "3px";
} else if (document.getElementById("masthead-user-expander")) {
btn.style.verticalAlign = "middle";
}
btn.title = ytcenter.language.getLocale("BUTTON_SETTINGS_TITLE");
ytcenter.language.addLocaleElement(btn, "BUTTON_SETTINGS_TITLE", "title");
btn.setAttribute("type", "button");
btn.setAttribute("role", "button");
btn.setAttribute("onclick", ";return false;");
btn.className = "yt-uix-tooltip-reverse yt-uix-button " + (ytcenter.watch7 ? "yt-uix-button-text" : "yt-uix-button-text") + " yt-uix-tooltip";
var btnt = document.createElement("span");
btnt.className = "yt-uix-button-icon-wrapper";
btnt.style.margin = "0";
var gearicon = document.createElement("img");
gearicon.src = ytcenter.icon.gear;
gearicon.setAttribute("alt", "");
var ytvt = document.createElement("span");
ytvt.className = "yt-valign-trick";
btnt.appendChild(gearicon);
btnt.appendChild(ytvt);
btn.appendChild(btnt);
var ytuixbc = document.createElement("span");
ytuixbc.className = "yt-uix-button-content";
ytuixbc.textContent = " ";
btn.appendChild(ytuixbc);
ytcenter.utils.addEventListener(btn, "click", function(){
if (!ytcenter.settingsPanelDialog) ytcenter.settingsPanelDialog = ytcenter.settingsPanel.createDialog();
ytcenter.settingsPanelDialog.setVisibility(true);
}, false);
if (document.getElementById("masthead-user")) {
document.getElementById("masthead-user").appendChild(btn);
} else if (document.getElementById("yt-masthead-user")) {
document.getElementById("yt-masthead-user").appendChild(btn);
} else if (document.getElementById("yt-masthead-signin")) {
btn.style.margin = "0 10px";
document.getElementById("yt-masthead-signin").appendChild(btn);
} else {
con.error("Settings UI - Couldn't add settings button");
}
}
}
function $CloneArray(arr) {
var copy = [];
for (var i = 0; i < arr.length; i++) {
copy[i] = arr[i];
}
return copy;
}
function $Clone(obj) {
var copy;
if (null == obj || typeof obj != "object") {
return obj;
}
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}
if (obj instanceof Array) {
copy = [];
for (var i = 0; i < obj.length; i++) {
copy[i] = $Clone(obj[i]);
}
return copy;
}
if (obj instanceof Object) {
copy = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
copy[key] = $Clone(obj[key]);
}
}
return copy;
}
return null;
}
function $ArrayIndexOf(arr, obj) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === obj) return i;
}
return -1;
}
function $SlideRange(elm, handle, min, max, defaultValue) {
function mousemove(e){
if (range.mouse.down) {
e.preventDefault();
if (e && e.type.indexOf("touch") !== -1 && e.changedTouches && e.changedTouches.length > 0 && e.changedTouches[0]) {
e = e.changedTouches[0];
}
var pos = e.clientX - $AbsoluteOffset(range.elm)[0] - range.handle.offsetWidth/2;
var max = range.elm.clientWidth - range.handle.offsetWidth;
if (pos > max) {
pos = max;
} else if (pos < 0) {
pos = 0;
}
range.handle.style.left = pos + "px";
for (var i = 0; i < range.listeners.length; i++) {
if (range.listeners[i].e === 'valuechange') {
var max = range.elm.clientWidth - range.handle.offsetWidth;
var a = range.max - range.min;
range.listeners[i].c(parseFloat(range.handle.style.left)/max*a+range.min);
}
}
}
}
function mousedownListener(e){
range.mouse.down = true;
throttleFunc = ytcenter.utils.throttle(mousemove, 50);
ytcenter.utils.addEventListener(document, "mousemove", throttleFunc, false);
ytcenter.utils.addEventListener(document, "touchmove", throttleFunc, false);
e.preventDefault();
}
function mouseupListener(e){
if (range.mouse.down) {
range.mouse.down = false;
e.stopPropagation();
for (var i = 0; i < range.listeners.length; i++) {
if (range.listeners[i].e === 'change') {
var max = range.elm.clientWidth - range.handle.offsetWidth;
var a = range.max - range.min;
range.listeners[i].c(parseFloat(range.handle.style.left)/max*a+range.min);
}
}
if (throttleFunc) ytcenter.utils.removeEventListener(document, "mousemove", throttleFunc, false);
if (throttleFunc) ytcenter.utils.removeEventListener(document, "touchmove", throttleFunc, false);
e.preventDefault();
}
}
function clickListener(e) {
var a;
var pos = e.clientX - $AbsoluteOffset(range.elm)[0] - range.handle.offsetWidth/2;
var max = range.elm.clientWidth - range.handle.offsetWidth;
if (pos > max) {
pos = max;
} else if (pos < 0) {
pos = 0;
}
range.handle.style.left = pos + "px";
for (var i = 0; i < range.listeners.length; i++) {
if (range.listeners[i].e === 'valuechange') {
max = range.elm.clientWidth - range.handle.offsetWidth;
a = range.max - range.min;
range.listeners[i].c(parseFloat(range.handle.style.left)/max*a+range.min);
} else if (range.listeners[i].e === 'change') {
max = range.elm.clientWidth - range.handle.offsetWidth;
a = range.max - range.min;
range.listeners[i].c(parseFloat(range.handle.style.left)/max*a+range.min);
}
}
e.preventDefault();
}
var range = {
elm: elm,
handle: handle,
min: (min ? min : 0),
max: (max ? max : 100),
defaultValue: (defaultValue ? defaultValue : min),
mouse: {
down: false
},
listeners: [],
width: 240,
height: 15
}, throttleFunc = null;
range.elm.style.marginTop = "-4px";
range.elm.style.width = range.width + "px";
range.elm.style.height = range.height + "px";
range.handle.style.width = range.height + "px";
range.handle.style.height = range.height + "px";
var returnKit = {
addEventListener: (function(range){
return function(event, callback){
range.listeners.push({
e: event,
c: callback
});
};
})(range),
getValue: (function(range){
return function(){
var max = parseInt(range.elm.style.width) - (range.height + 2);
var a = range.max - range.min;
return parseFloat(range.handle.style.left)/max*a+range.min || range.defaultValue;
};
})(range),
setValue: (function(range){
return function(val){
var max = parseInt(range.elm.style.width) - (range.height + 2);
var pos = (val - range.min)/(range.max - range.min)*max;
if (pos > max) {
pos = max;
} else if (pos < 0) {
pos = 0;
}
range.handle.style.left = pos + "px";
if (val == 0) {
return 0;
} else {
return returnKit.getValue();
}
};
})(range)
};
returnKit.setValue(range.defaultValue);
ytcenter.utils.addEventListener(elm, "click", clickListener, false);
/* Mouse */
ytcenter.utils.addEventListener(elm, "mousedown", mousedownListener, false);
ytcenter.utils.addEventListener(document, "mouseup", mouseupListener, false);
/* Touch */
ytcenter.utils.addEventListener(elm, "touchstart", mousedownListener, false);
ytcenter.utils.addEventListener(document, "touchend", mouseupListener, false);
return returnKit;
}
function $AbsoluteOffset(elm) {
var pos = [elm.offsetLeft || 0, elm.offsetTop || 0];
if (elm.offsetParent) {
var ao = $AbsoluteOffset(elm.offsetParent);
pos[0] += ao[0];
pos[1] += ao[1];
}
return pos;
}
function addPropertyWrapper(parent, property, wrapperFunc, callback) {
function waitObject(parent, token) {
var value;
var loaded = false;
// TODO research if it's possible to add listeners to an object instead of using setter and getter.
defineLockedProperty(parent, token, function(aValue){
value = aValue; // Always set the value as it's supposed to act like a normal property.
if (!loaded) {
loaded = true;
iterate(); // Let's start the iteration again.
}
}, function(){
return value;
});
}
function iterate() {
var token;
// Make sure that at least one item is in the tokens array.
while (tokens.length > 1 && (token = tokens.shift())) {
// If the next token doesn't exists as a property then attach a `getter and setter` and wait for it to be written to.
if (!parent[token]) {
con.log("[Property Wrapper] Property doesn't exists in parent, attaching trigger using `getter and setter`.");
waitObject(parent, token);
tokens = [token].concat(tokens); // We attach the token at the start of the array because we removed it in while.
return; // I will return one day...
}
parent = parent[token];
}
// We got to the end and we will then add the wrapper.
addWrapper();
}
function addWrapper() {
var func = parent[tokens[0]];
con.log("[Property Wrapper] Wrapping `" + tokens[0] + "` function in a wrapper.");
defineLockedProperty(parent, tokens[tokens.length - 1], function(value){
func = value;
}, function(){
return function(){
if (typeof func === "function") {
var args = Array.prototype.slice.call(arguments, 0);
var value = func.apply(this, args);
wrapperFunc.apply(this, [value].concat(args));
} else {
con.warn("[Property Wrapper] Wrapped function is not a function!", func);
}
return value;
};
});
callback();
}
con.log("[Property Wrapper] Wrapping the function " + tokens + " into a function wrapper.");
// Creating the tokens from property
var tokens = property.split(".");
// Let's start our iteration
iterate();
}
/* END UTILS */
/* Classes (what) */
function defineLockedProperty(obj, key, setter, getter) {
if (typeof obj !== "object") obj = {};
if (ytcenter.utils.ie || (typeof Object.defineProperty === "function" && !obj.__defineGetter__)) {
Object.defineProperty(obj, key, {
get: getter,
set: setter
});
return obj;
} else {
obj.__defineGetter__(key, getter);
obj.__defineSetter__(key, setter);
return obj;
}
}
function freeze(parent, freezeObject, predefinedObject) {
function wait(_parent, _freezeObject) {
var args = _freezeObject.split(".");
var _object = undefined;
defineLockedProperty(_parent, args[0], function(val){
args.splice(0, 1);
freeze(val, args.join("."));
_object = val;
}, function(){
return _object;
});
}
var args = freezeObject.split(".");
var at = parent;
for (var i = 0, len = args.length - 1; i < len; i++) {
if (typeof at[args[i]] === "object") {
at = at[args[i]];
} else {
args.splice(0, i);
wait(at, args.join("."));
return;
}
}
var defObject = predefinedObject;
var frozen = typeof predefinedObject !== "undefined";
if (typeof at[args[args.length - 1]] !== "undefined") {
defObject = at[args[args.length - 1]];
frozen = true;
}
defineLockedProperty(at, args[args.length - 1], function(val){
if (!frozen) {
frozen = true;
defObject = val;
}
}, function(){
return defObject;
});
}
var console_debug = devbuild; // Disable this to stop YouTube Center Developer Build from writing in the console log.
var _console = [];
var uw = null,
loc = null,
con = null,
ytcenter = {},
yt = {};
uw = _unsafeWindow || (function(){
var a;
try {
a = unsafeWindow === window ? false : unsafeWindow;
} catch (e) {
} finally {
return a || (function(){
try {
var e = document.createElement('p');
e.setAttribute('onclick', 'return window;');
return e.onclick();
} catch (e) {
return window;
}
}());
}
})();
if (uw && typeof uw.ytcenter !== "undefined") {
return;
}
ytcenter.unsafe = {};
uw.ytcenter = ytcenter.unsafe;
ytcenter.ltr = true;
ytcenter.utils = {};
ytcenter.utils.createCustomEvent = function(type, detail) {
try {
var e = document.createEvent('CustomEvent');
if (detail) {
e.initCustomEvent(type, true, true, detail);
} else {
e.initCustomEvent(type, true, true);
}
return e;
} catch (e) {
var e = new CustomEvent(type);
if (detail) {
e.detail = detail;
}
return e;
}
};
ytcenter.utils.ie = (function(){
for (var v = 3, el = document.createElement('b'), all = el.all || []; el.innerHTML = '<!--[if gt IE ' + (++v) + ']><i><![endif]-->', all[0];);
return v > 4 ? v : !!document.documentMode;
}());
function getAPIKey() {
return ytcenter.settings.google_apikey || "AIzaSyCO5gfGpEiqmc8XTknN9RyC3TCJz1-XyAI";
}
/**
* UAParser.js v0.7.3
* Lightweight JavaScript-based User-Agent string parser
* https://github.com/faisalman/ua-parser-js
*
* Copyright © 2012-2014 Faisal Salman <fyzlman@gmail.com>
* Dual licensed under GPLv2 & MIT
*/
(function(e,t){"use strict";var n="0.7.3",r="",i="?",s="function",o="undefined",u="object",a="major",f="model",l="name",c="type",h="vendor",p="version",d="architecture",v="console",m="mobile",g="tablet",y="smarttv",b="wearable",w="embedded";var E={extend:function(e,t){for(var n in t){if("browser cpu device engine os".indexOf(n)!==-1&&t[n].length%2===0){e[n]=t[n].concat(e[n])}}return e},has:function(e,t){if(typeof e==="string"){return t.toLowerCase().indexOf(e.toLowerCase())!==-1}},lowerize:function(e){return e.toLowerCase()}};var S={rgx:function(){var e,n=0,r,i,a,f,l,c,h=arguments;while(n<h.length&&!l){var p=h[n],d=h[n+1];if(typeof e===o){e={};for(a in d){f=d[a];if(typeof f===u){e[f[0]]=t}else{e[f]=t}}}r=i=0;while(r<p.length&&!l){l=p[r++].exec(this.getUA());if(!!l){for(a=0;a<d.length;a++){c=l[++i];f=d[a];if(typeof f===u&&f.length>0){if(f.length==2){if(typeof f[1]==s){e[f[0]]=f[1].call(this,c)}else{e[f[0]]=f[1]}}else if(f.length==3){if(typeof f[1]===s&&!(f[1].exec&&f[1].test)){e[f[0]]=c?f[1].call(this,c,f[2]):t}else{e[f[0]]=c?c.replace(f[1],f[2]):t}}else if(f.length==4){e[f[0]]=c?f[3].call(this,c.replace(f[1],f[2])):t}}else{e[f]=c?c:t}}}}n+=2}return e},str:function(e,n){for(var r in n){if(typeof n[r]===u&&n[r].length>0){for(var s=0;s<n[r].length;s++){if(E.has(n[r][s],e)){return r===i?t:r}}}else if(E.has(n[r],e)){return r===i?t:r}}return e}};var x={browser:{oldsafari:{major:{1:["/8","/1","/3"],2:"/4","?":"/"},version:{"1.0":"/8",1.2:"/1",1.3:"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"}}},device:{amazon:{model:{"Fire Phone":["SD","KF"]}},sprint:{model:{"Evo Shift 4G":"7373KT"},vendor:{HTC:"APA",Sprint:"Sprint"}}},os:{windows:{version:{ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2",8.1:"NT 6.3",10:"NT 6.4",RT:"ARM"}}}};var T={browser:[[/(opera\smini)\/((\d+)?[\w\.-]+)/i,/(opera\s[mobiletab]+).+version\/((\d+)?[\w\.-]+)/i,/(opera).+version\/((\d+)?[\w\.]+)/i,/(opera)[\/\s]+((\d+)?[\w\.]+)/i],[l,p,a],[/\s(opr)\/((\d+)?[\w\.]+)/i],[[l,"Opera"],p,a],[/(kindle)\/((\d+)?[\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,/(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?((\d+)?[\w\.]*)/i,/(?:ms|\()(ie)\s((\d+)?[\w\.]+)/i,/(rekonq)((?:\/)[\w\.]+)*/i,/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron)\/((\d+)?[\w\.-]+)/i],[l,p,a],[/(trident).+rv[:\s]((\d+)?[\w\.]+).+like\sgecko/i],[[l,"IE"],p,a],[/(yabrowser)\/((\d+)?[\w\.]+)/i],[[l,"Yandex"],p,a],[/(comodo_dragon)\/((\d+)?[\w\.]+)/i],[[l,/_/g," "],p,a],[/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i,/(uc\s?browser|qqbrowser)[\/\s]?((\d+)?[\w\.]+)/i],[l,p,a],[/(dolfin)\/((\d+)?[\w\.]+)/i],[[l,"Dolphin"],p,a],[/((?:android.+)crmo|crios)\/((\d+)?[\w\.]+)/i],[[l,"Chrome"],p,a],[/version\/((\d+)?[\w\.]+).+?mobile\/\w+\s(safari)/i],[p,a,[l,"Mobile Safari"]],[/version\/((\d+)?[\w\.]+).+?(mobile\s?safari|safari)/i],[p,a,l],[/webkit.+?(mobile\s?safari|safari)((\/[\w\.]+))/i],[l,[a,S.str,x.browser.oldsafari.major],[p,S.str,x.browser.oldsafari.version]],[/(konqueror)\/((\d+)?[\w\.]+)/i,/(webkit|khtml)\/((\d+)?[\w\.]+)/i],[l,p,a],[/(navigator|netscape)\/((\d+)?[\w\.-]+)/i],[[l,"Netscape"],p,a],[/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.-]+)/i,/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,/(links)\s\(((\d+)?[\w\.]+)/i,/(gobrowser)\/?((\d+)?[\w\.]+)*/i,/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i,/(mosaic)[\/\s]((\d+)?[\w\.]+)/i],[l,p,a]],cpu:[[/(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i],[[d,"amd64"]],[/(ia32(?=;))/i],[[d,E.lowerize]],[/((?:i[346]|x)86)[;\)]/i],[[d,"ia32"]],[/windows\s(ce|mobile);\sppc;/i],[[d,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i],[[d,/ower/,"",E.lowerize]],[/(sun4\w)[;\)]/i],[[d,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+;))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i],[[d,E.lowerize]]],device:[[/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i],[f,h,[c,g]],[/applecoremedia\/[\w\.]+ \((ipad)/],[f,[h,"Apple"],[c,g]],[/(apple\s{0,1}tv)/i],[[f,"Apple TV"],[h,"Apple"]],[/(archos)\s(gamepad2?)/i,/(hp).+(touchpad)/i,/(kindle)\/([\w\.]+)/i,/\s(nook)[\w\s]+build\/(\w+)/i,/(dell)\s(strea[kpr\s\d]*[\dko])/i],[h,f,[c,g]],[/(kf[A-z]+)\sbuild\/[\w\.]+.*silk\//i],[f,[h,"Amazon"],[c,g]],[/(sd|kf)[0349hijorstuw]+\sbuild\/[\w\.]+.*silk\//i],[[f,S.str,x.device.amazon.model],[h,"Amazon"],[c,m]],[/\((ip[honed|\s\w*]+);.+(apple)/i],[f,h,[c,m]],[/\((ip[honed|\s\w*]+);/i],[f,[h,"Apple"],[c,m]],[/(blackberry)[\s-]?(\w+)/i,/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola|polytron)[\s_-]?([\w-]+)*/i,/(hp)\s([\w\s]+\w)/i,/(asus)-?(\w+)/i],[h,f,[c,m]],[/\(bb10;\s(\w+)/i],[f,[h,"BlackBerry"],[c,m]],[/android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7)/i],[f,[h,"Asus"],[c,g]],[/(sony)\s(tablet\s[ps])/i],[h,f,[c,g]],[/\s(ouya)\s/i,/(nintendo)\s([wids3u]+)/i],[h,f,[c,v]],[/android.+;\s(shield)\sbuild/i],[f,[h,"Nvidia"],[c,v]],[/(playstation\s[3portablevi]+)/i],[f,[h,"Sony"],[c,v]],[/(sprint\s(\w+))/i],[[h,S.str,x.device.sprint.vendor],[f,S.str,x.device.sprint.model],[c,m]],[/(lenovo)\s?(S(?:5000|6000)+(?:[-][\w+]))/i],[h,f,[c,g]],[/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i,/(zte)-(\w+)*/i,/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]+)*/i],[h,[f,/_/g," "],[c,m]],[/[\s\(;](xbox(?:\sone)?)[\s\);]/i],[f,[h,"Microsoft"],[c,v]],[/(kin\.[onetw]{3})/i],[[f,/\./g," "],[h,"Microsoft"],[c,m]],[/\s((milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?(:?\s4g)?))[\w\s]+build\//i,/(mot)[\s-]?(\w+)*/i],[[h,"Motorola"],f,[c,m]],[/android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i],[f,[h,"Motorola"],[c,g]],[/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9|nexus 10))/i,/((SM-T\w+))/i],[[h,"Samsung"],f,[c,g]],[/((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-n900))/i,/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,/sec-((sgh\w+))/i],[[h,"Samsung"],f,[c,m]],[/(samsung);smarttv/i],[h,f,[c,y]],[/\(dtv[\);].+(aquos)/i],[f,[h,"Sharp"],[c,y]],[/sie-(\w+)*/i],[f,[h,"Siemens"],[c,m]],[/(maemo|nokia).*(n900|lumia\s\d+)/i,/(nokia)[\s_-]?([\w-]+)*/i],[[h,"Nokia"],f,[c,m]],[/android\s3\.[\s\w-;]{10}(a\d{3})/i],[f,[h,"Acer"],[c,g]],[/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i],[[h,"LG"],f,[c,g]],[/(lg) netcast\.tv/i],[h,f,[c,y]],[/(nexus\s[45])/i,/lg[e;\s\/-]+(\w+)*/i],[f,[h,"LG"],[c,m]],[/android.+(ideatab[a-z0-9\-\s]+)/i],[f,[h,"Lenovo"],[c,g]],[/linux;.+((jolla));/i],[h,f,[c,m]],[/((pebble))app\/[\d\.]+\s/i],[h,f,[c,b]],[/android.+;\s(glass)\s\d/i],[f,[h,"Google"],[c,b]],[/(mobile|tablet);.+rv\:.+gecko\//i],[[c,E.lowerize],h,f]],engine:[[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i,/(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i,/(icab)[\/\s]([23]\.[\d\.]+)/i],[l,p],[/rv\:([\w\.]+).*(gecko)/i],[p,l]],os:[[/microsoft\s(windows)\s(vista|xp)/i],[l,p],[/(windows)\snt\s6\.2;\s(arm)/i,/(windows\sphone(?:\sos)*|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i],[l,[p,S.str,x.os.windows.version]],[/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i],[[l,"Windows"],[p,S.str,x.os.windows.version]],[/\((bb)(10);/i],[[l,"BlackBerry"],p],[/(blackberry)\w*\/?([\w\.]+)*/i,/(tizen)[\/\s]([\w\.]+)/i,/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego|contiki)[\/\s-]?([\w\.]+)*/i,/linux;.+(sailfish);/i],[l,p],[/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i],[[l,"Symbian"],p],[/\((series40);/i],[l],[/mozilla.+\(mobile;.+gecko.+firefox/i],[[l,"Firefox OS"],p],[/(nintendo|playstation)\s([wids3portablevu]+)/i,/(mint)[\/\s\(]?(\w+)*/i,/(mageia|vectorlinux)[;\s]/i,/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?([\w\.-]+)*/i,/(hurd|linux)\s?([\w\.]+)*/i,/(gnu)\s?([\w\.]+)*/i],[l,p],[/(cros)\s[\w]+\s([\w\.]+\w)/i],[[l,"Chromium OS"],p],[/(sunos)\s?([\w\.]+\d)*/i],[[l,"Solaris"],p],[/\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]+)*/i],[l,p],[/(ip[honead]+)(?:.*os\s*([\w]+)*\slike\smac|;\sopera)/i],[[l,"iOS"],[p,/_/g,"."]],[/(mac\sos\sx)\s?([\w\s\.]+\w)*/i,/(macintosh|mac(?=_powerpc)\s)/i],[[l,"Mac OS"],[p,/_/g,"."]],[/((?:open)?solaris)[\/\s-]?([\w\.]+)*/i,/(haiku)\s(\w+)/i,/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i,/(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms)/i,/(unix)\s?([\w\.]+)*/i],[l,p]]};var N=function(t,n){if(!(this instanceof N)){return(new N(t,n)).getResult()}var i=t||(e&&e.navigator&&e.navigator.userAgent?e.navigator.userAgent:r);var s=n?E.extend(T,n):T;this.getBrowser=function(){return S.rgx.apply(this,s.browser)};this.getCPU=function(){return S.rgx.apply(this,s.cpu)};this.getDevice=function(){return S.rgx.apply(this,s.device)};this.getEngine=function(){return S.rgx.apply(this,s.engine)};this.getOS=function(){return S.rgx.apply(this,s.os)};this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}};this.getUA=function(){return i};this.setUA=function(e){i=e;return this};this.setUA(i)};N.VERSION=n;N.BROWSER={NAME:l,MAJOR:a,VERSION:p};N.CPU={ARCHITECTURE:d};N.DEVICE={MODEL:f,VENDOR:h,TYPE:c,CONSOLE:v,MOBILE:m,SMARTTV:y,TABLET:g,WEARABLE:b,EMBEDDED:w};N.ENGINE={NAME:l,VERSION:p};N.OS={NAME:l,VERSION:p};ytcenter.UAParser=N})(this)
ytcenter.reportIssue = (function(){
function createSettingsCategory() {
cat = ytcenter.settingsPanel.createCategory("SETTINGS_CAT_REPORT");
createInstructions();
createIssueTemplate();
}
function createInstructions() {
var instructions = ytcenter.settingsPanel.createSubCategory("SETTINGS_SUBCAT_INSTRUCTIONS");
cat.addSubCategory(instructions);
var instructionElement = document.createElement("div");
instructionElement.textContent = "Coming soon.";
var option = ytcenter.settingsPanel.createOption(
null,
"simpleElement",
null,
{
"element": instructionElement
}
);
instructions.addOption(option);
}
function createIssueTemplate() {
browserDetails = getBrowserDetails();
var template = ytcenter.settingsPanel.createSubCategory("SETTINGS_SUBCAT_ISSUE_TEMPLATE");
cat.addSubCategory(template);
var tempElement = document.createElement("div");
template.addEventListener("click", function(){
generateTemplateElement(tempElement);
});
tempElement.addEventListener("copy", function(){
var selection = window.getSelection();
var selectionRange = null;
if (selection.getRangeAt && selection.rangeCount) {
selectionRange = selection.getRangeAt(0);
}
var clonedTemplate = tempElement.cloneNode(true);
clonedTemplate.className = "ytc-copying";
var titles = clonedTemplate.getElementsByClassName("title");
for (var i = 0, len = titles.length; i < len; i++) {
titles[i].textContent = "__" + titles[i].textContent + "__";
}
document.body.appendChild(clonedTemplate);
selection.selectAllChildren(clonedTemplate);
ytcenter.settingsPanel.statusbar.setMessage("Copied", 1500); // TODO Use translated locale
setTimeout(function(){
selection.removeAllRanges();
selection.addRange(selectionRange);
clonedTemplate.parentNode.removeChild(clonedTemplate);
}, 7);
});
//generateTemplateElement(tempElement);
var option = ytcenter.settingsPanel.createOption(
null,
"simpleElement",
null,
{
"element": tempElement
}
);
template.addOption(option);
}
function generateTemplateElement(tempElement) {
tempElement.innerHTML = "";
var list = document.createElement("ul");
for (var i = 0, len = templateList.length; i < len; i++) {
var listItem = templateList[i];
var generatedContent = listItem.value();
if (listItem.emptyHide && generatedContent === "") continue;
var item = document.createElement("li");
var title = document.createElement("span");
title.className = "title";
title.style.fontWeight = "bold";
title.textContent = listItem.title;
item.appendChild(title);
var split = document.createElement("span");
split.textContent = ":" + (listItem.addLines ? "" : " ");
item.appendChild(split);
var content = null;
if (listItem.wrapper) {
contentGist = contentGist || document.createElement("span");
contentGist.innerHTML = "";
if (!uploadLink) {
uploadLink = document.createElement("a");
uploadLink.textContent = "Upload";
uploadLink.setAttribute("href", "#");
uploadLink.addEventListener("click", function(e){
e = e || window.event;
contentGist.textContent = "Uploading...";
contentGist.style.fontStyle = "italic";
var data = {
"description": null,
"public": false,
"files": {
"debug_log.js": {
"content": JSON.stringify(ytcenter.getDebug(false), undefined, 2)
}
}
};
ytcenter.utils.xhr({
method: "POST",
url: "https://api.github.com/gists",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: JSON.stringify(data),
contentType: "application/x-www-form-urlencoded", // Firefox Addon
content: JSON.stringify(data), // Firefox Addon
onload: (function(contentGist){
return function(response) {
var details = JSON.parse(response.responseText);
gistURL = details.html_url;
var link = document.createElement("a");
link.href = gistURL;
link.textContent = gistURL;
contentGist.innerHTML = "";
contentGist.style.fontStyle = "";
contentGist.appendChild(link);
};
})(contentGist)
});
e && e.preventDefault && e.preventDefault();
return false;
}, false);
}
if (!orSpan) {
orSpan = document.createElement("span");
orSpan.textContent = " or ";
}
if (!useExistingLink) {
useExistingLink = document.createElement("a")