// ==UserScript==
// @name 9anime Bingewatcher+
// @namespace https://greasyfork.org/en/users/10118-drhouse
// @version 3.3
// @description Auto-fullscreen, skip intros, jump to next episode 9anime on Vidstream and MyCloud videos
// @include https://www*.9anime.*/*
// @include https://9anime.*/*
// @include https://*.9anime.*/*
// @match *.9anime.to/watch/*
// @include https://vidstream.pro/*
// @include https://vidstreamz.online/*
// @include https://mcloud.to/*
// @include https://mcloud2.to/*
// @include https://storage.googleapis.com/*
// @include https://movies7.to/*
// @include https://*.mp4upload.com:*/*
// @include https://*.mp4upload.com*/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_notification
// @grant GM_getMetadata
// @author drhouse
// @license CC-BY-NC-SA-4.0
// @icon https://s2.bunnycdn.ru/assets/9anime/favicons/favicon.png?v1
// @downloadURL none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
function MonkeyConfig() {
var cfg = this,
/* Data object passed to the constructor */
data,
/* Configuration parameters (data.parameters or data.params) */
params,
/* Current values of configuration parameters */
values = {},
/* Identifier used to store/retrieve configuration */
storageKey,
/* Is the configuration dialog displayed? */
displayed,
/* Currently displayed window/layer */
openWin, openLayer,
/* DOM element wrapping the configuration form */
container,
/* Darkened overlay used in the layer display mode */
overlay;
/**
* Initialize configuration
*
* @param newData New data object
*/
function init(newData) {
data = newData;
if (data) {
params = data.parameters || data.params;
if (data.buttons === undefined)
/* Set default buttons */
data.buttons = [ 'save', 'defaults', 'cancel' ];
if (data.title === undefined)
/*
* If GM_getMetadata is available, get the name of the script
* and use it in the dialog title
*/
if (typeof GM_getMetadata == 'function') {
var scriptName = GM_getMetadata('name');
data.title = scriptName + ' Configuration';
}
else
data.title = 'Configuration';
}
/* Make a safe version of title to be used as stored value identifier */
var safeTitle = data && data.title ?
data.title.replace(/[^a-zA-Z0-9]/g, '_') : '';
storageKey = '_MonkeyConfig_' + safeTitle + '_cfg';
var storedValues;
/* Load stored values (if present) */
if (GM_getValue(storageKey))
storedValues = JSON.parse(GM_getValue(storageKey));
for (var name in params) {
/* If there's a value defined in the passed data object, use it */
if (params[name]['value'] !== undefined)
set(name, params[name].value);
/* Check if there's a stored value for this parameter */
else if (storedValues && storedValues[name] !== undefined)
set(name, storedValues[name]);
/* Otherwise, set the default value (if defined) */
else if (params[name]['default'] !== undefined)
set(name, params[name]['default']);
else
set(name, '');
}
if (data.menuCommand) {
/* Add an item to the User Script Commands menu */
var caption = data.menuCommand !== true ? data.menuCommand :
data.title;
GM_registerMenuCommand(caption, function () { cfg.open(); });
}
/* Expose public methods */
cfg.open = open;
cfg.close = close;
cfg.get = get;
cfg.set = function (name, value) {
set(name, value);
update();
};
}
/**
* Get the value of a configuration parameter
*
* @param name Name of the configuration parameter
* @returns Value of the configuration parameter
*/
function get(name) {
return values[name];
}
/**
* Set the value of a configuration parameter
*
* @param name Name of the configuration parameter
* @param value New value of the configuration parameter
*/
function set(name, value) {
values[name] = value;
}
/**
* Reset configuration parameters to default values
*/
function setDefaults() {
for (var name in params) {
if (typeof params[name]['default'] !== 'undefined') {
set(name, params[name]['default']);
}
}
}
/**
* Render the configuration dialog
*/
function render() {
var html = '
' +
'
' + data.title + '
' +
'
';
for (var name in params) {
html += MonkeyConfig.formatters['tr'](name, params[name]);}
html += '
' +
'
';
/* Render buttons */
for (var button in data.buttons) {
html += '
';
switch (data.buttons[button]) {
case 'cancel':
html += '';
break;
case 'defaults':
html += '';
break;
case 'save':
html += '';
break;
}
html += '
';
}
html += '
';
html += "
";
return html;
}
/**
* Update the fields in the dialog to reflect current values
*/
function update() {
/* Do nothing if the dialog is not currently displayed */
if (!displayed)
return;
for (var name in params) {
var value = values[name];
switch (params[name].type) {
case 'checkbox':
var elem = container.querySelector('[name="' + name + '"]');
elem.checked = !!value;
break;
case 'custom':
params[name].set(value, container
.querySelector('#__MonkeyConfig_parent_' + name));
break;
case 'number':
case 'text':
case 'color':
elem = container.querySelector('[name="' + name + '"]');
elem.value = value;
break;
case 'select':
elem = container.querySelector('[name="' + name + '"]');
if (elem.tagName.toLowerCase() == 'input') {
if (elem.type && elem.type == 'radio') {
/* Single selection with radio buttons */
elem = container.querySelector(
'[name="' + name + '"][value="' + value + '"]');
elem.checked = true;
}
else if (elem.type && elem.type == 'checkbox') {
/* Multiple selection with checkboxes */
var checkboxes = container.querySelectorAll(
'input[name="' + name + '"]');
for (var i = 0; i < checkboxes.length; i++)
checkboxes[i].checked =
(value.indexOf(checkboxes[i].value) > -1);
}
}
else if (elem.tagName.toLowerCase() == 'select')
if (elem.multiple) {
/* Multiple selection element */
var options = container.querySelectorAll(
'select[name="' + name + '"] option');
for (i = 0; i < options.length; i++)
options[i].selected =
(value.indexOf(options[i].value) > -1);
}
else
/* Single selection element */
elem.value = value;
break;
}
}
}
/**
* Save button click event handler
*/
function saveClick() {
for (var name in params) {
switch (params[name].type) {
case 'checkbox':
var elem = container.querySelector('[name="' + name + '"]');
values[name] = elem.checked;
break;
case 'custom':
values[name] = params[name].get(container
.querySelector('#__MonkeyConfig_parent_' + name));
break;
case 'number':
case 'text':
case 'color':
elem = container.querySelector('[name="' + name + '"]');
values[name] = elem.value;
break;
case 'select':
elem = container.querySelector('[name="' + name + '"]');
if (elem.tagName.toLowerCase() == 'input') {
if (elem.type && elem.type == 'radio')
/* Single selection with radio buttons */
values[name] = container.querySelector(
'[name="' + name + '"]:checked').value;
else if (elem.type && elem.type == 'checkbox') {
/* Multiple selection with checkboxes */
values[name] = [];
var inputs = container.querySelectorAll(
'input[name="' + name + '"]');
for (var i = 0; i < inputs.length; i++)
if (inputs[i].checked)
values[name].push(inputs[i].value);
}
}
else if (elem.tagName.toLowerCase() == 'select' && elem.multiple) {
/* Multiple selection element */
values[name] = [];
var options = container.querySelectorAll(
'select[name="' + name + '"] option');
for ( i = 0; i < options.length; i++)
if (options[i].selected)
values[name].push(options[i].value);
}
else
values[name] = elem.value;
break;
}
}
GM_setValue(storageKey, JSON.stringify(values));
close();
if (data.onSave)
data.onSave(values);
location.reload();
}
/**
* Cancel button click event handler
*/
function cancelClick() {
close();
}
/**
* Set Defaults button click event handler
*/
function defaultsClick() {
setDefaults();
update();
}
/**
* Open configuration dialog
*
* @param mode
* Display mode ("iframe", "layer", or "window", defaults to
* "iframe")
* @param options
* Display mode options
*/
function open(mode, options) {
function openDone() {
/* Attach button event handlers */
var button;
if (button = container.querySelector('#__MonkeyConfig_button_save'))
button.addEventListener('click', saveClick, true);
if (button = container.querySelector('#__MonkeyConfig_button_cancel'))
button.addEventListener('click', cancelClick, true);
if (button = container.querySelector('#__MonkeyConfig_button_defaults'))
button.addEventListener('click', defaultsClick, true);
displayed = true;
update();
}
switch (mode) {
case 'window':
var windowFeatures = {
location: 'no',
status: 'no',
left: window.screenX,
top: window.screenY,
width: 100,
height: 100
};
/* Additional features may be specified as an option */
if (options && options.windowFeatures)
for (var name in options.windowFeatures)
windowFeatures[name] = options.windowFeatures[name];
var featuresArray = [];
for (name in windowFeatures)
featuresArray.push(name + '=' + windowFeatures[name]);
var win = window.open('', data.title, featuresArray.join(','));
/* Find head and body (then call the blood spatter analyst) */
var head = win.document.getElementsByTagName('head')[0],
body = win.document.getElementsByTagName('body')[0];
head.innerHTML = '' + data.title + '' +
'';
body.className = '__MonkeyConfig_window';
/* Place the rendered configuration dialog inside the window body */
body.innerHTML = render();
/* Find the container (CBAN-3489) */
container = win.document.querySelector('.__MonkeyConfig_container');
/* Resize window to the dimensions of the container div */
win.innerWidth = container.clientWidth;
win.resizeBy(0, -win.innerHeight + container.clientHeight);
/* Place the window centered relative to the parent */
win.moveBy(Math.round((window.outerWidth - win.outerWidth) / 2),
Math.round((window.outerHeight - win.outerHeight) / 2));
openWin = win;
openDone();
break;
case 'layer':
if (!MonkeyConfig.styleAdded) {
GM_addStyle(MonkeyConfig.res.stylesheets.main);
MonkeyConfig.styleAdded = true;
}
body = document.querySelector('body');
/* Create the layer element */
openLayer = document.createElement('div');
openLayer.className = '__MonkeyConfig_layer';
/* Create the overlay */
overlay = document.createElement('div');
overlay.className = '__MonkeyConfig_overlay';
overlay.style.left = 0;
overlay.style.top = 0;
overlay.style.width = window.innerWidth + 'px';
overlay.style.height = window.innerHeight + 'px';
overlay.style.zIndex = 9999;
body.appendChild(overlay);
body.appendChild(openLayer);
/*
* Place the rendered configuration dialog inside the layer element
*/
openLayer.innerHTML = render();
/* Position the layer in the center of the viewport */
openLayer.style.left = Math.round((window.innerWidth -
openLayer.clientWidth) / 2) + 'px';
openLayer.style.top = Math.round((window.innerHeight -
openLayer.clientHeight) / 2) + 'px';
openLayer.style.zIndex = 9999;
container = document.querySelector('.__MonkeyConfig_container');
openDone();
break;
case 'iframe':
default:
if (!MonkeyConfig.styleAdded) {
GM_addStyle(MonkeyConfig.res.stylesheets.main);
MonkeyConfig.styleAdded = true;
}
body = document.querySelector('body');
var iframe = document.createElement('iframe');
/* Create the layer element */
openLayer = document.createElement('div');
openLayer.className = '__MonkeyConfig_layer';
/* Create the overlay */
overlay = document.createElement('div');
overlay.className = '__MonkeyConfig_overlay';
overlay.style.left = 0;
overlay.style.top = 0;
overlay.style.width = window.innerWidth + 'px';
overlay.style.height = window.innerHeight + 'px';
overlay.style.zIndex = 9999;
iframe.id = '__MonkeyConfig_frame';
/*
* Make the iframe transparent so that it remains invisible until
* the document inside it is ready
*/
iframe.style.opacity = 0;
iframe.src = 'about:blank';
/* Make the iframe seamless with no border and no scrollbars */
if (undefined !== iframe.frameborder)
iframe.frameBorder = '0';
if (undefined !== iframe.scrolling)
iframe.scrolling = 'no';
if (undefined !== iframe.seamless)
iframe.seamless = true;
/* Do the rest in the load event handler */
iframe.addEventListener('load', function () {
iframe.contentDocument.body.innerHTML = render();
iframe.style.opacity = 1;
/* Append the style to the head */
var head = iframe.contentDocument.querySelector('head'),
style = iframe.contentDocument.createElement('style');
style.setAttribute('type', 'text/css');
style.appendChild(iframe.contentDocument.createTextNode(
MonkeyConfig.res.stylesheets.main));
head.appendChild(style);
var body = iframe.contentDocument.querySelector('body');
body.className = '__MonkeyConfig_body';
container = iframe.contentDocument
.querySelector('.__MonkeyConfig_container');
iframe.width = container.clientWidth;
iframe.height = container.clientHeight;
/* Position the layer in the center of the viewport */
openLayer.style.left = Math.round((window.innerWidth -
openLayer.clientWidth) / 2) + 'px';
openLayer.style.top = Math.round((window.innerHeight -
openLayer.clientHeight) / 2) + 'px';
openLayer.style.zIndex = 9999;
openDone();
}, false);
setTimeout(function () {
iframe.width = container.clientWidth;
iframe.height = container.clientHeight;
/* Position the layer in the center of the viewport */
openLayer.style.left = Math.round((window.innerWidth -
openLayer.clientWidth) / 2) + 'px';
openLayer.style.top = Math.round((window.innerHeight -
openLayer.clientHeight) / 2) + 'px';
openLayer.style.zIndex = 9999;
}, 0);
body.appendChild(overlay);
body.appendChild(openLayer);
openLayer.appendChild(iframe);
break;
}
}
/**
* Close configuration dialog
*/
function close() {
if (openWin) {
openWin.close();
openWin = undefined;
}
else if (openLayer) {
openLayer.parentNode.removeChild(openLayer);
openLayer = undefined;
if (overlay) {
overlay.parentNode.removeChild(overlay);
overlay = undefined;
}
}
displayed = false;
}
init(arguments[0]);
}
/**
* Replace double quotes with entities so that the string can be safely used
* in a HTML attribute
*
* @param string A string
* @returns String with double quotes replaced with entities
*/
MonkeyConfig.esc = function (string) {
return string.replace(/"/g, '"');
};
MonkeyConfig.HTML = {
'_field': function (name, options, data) {
var html;
if (options.type && MonkeyConfig.HTML[options.type])
html = MonkeyConfig.HTML[options.type](name, options, data);
else
return;
if (/\[FIELD\]/.test(options.html)) {
html = options.html.replace(/\[FIELD\]/, html);
}
return html;
},
'_label': function (name, options, data) {
var label = options['label'] ||
name.substring(0, 1).toUpperCase() + name.substring(1)
.replace(/_/g, ' ');
return '';
},
'checkbox': function (name, options, data) {
return '';
},
'custom': function (name, options, data) {
return options.html;
},
'number': function (name, options, data) {
return '';
},
'select': function (name, options, data) {
var choices = {}, html = '';
if (options.choices.constructor == Array) {
/* options.choices is an array -- build key/value pairs */
for (var i = 0; i < options.choices.length; i++)
choices[options.choices[i]] = options.choices[i];
}
else
/* options.choices is an object -- use it as it is */
choices = options.choices;
if (!options.multiple) {
/* Single selection */
if (!/^radio/.test(options.variant)) {
/* Select element */
html += '';
}
else {
/* Radio buttons */
for ( value in choices) {
html += '' +
(/ column/.test(options.variant) ? ' ' : '');
}
}
}
else {
/* Multiple selection */
if (!/^checkbox/.test(options.variant)) {
/* Checkboxes */
html += '';
}
else {
/* Select element */
for ( value in choices) {
html += '' +
(/ column/.test(options.variant) ? ' ' : '');
}
}
}
return html;
},
'text': function (name, options, data) {
if (options.long)
return '';
else
return '';
},
'color': function(name, options, data) {
return '';
}
};
MonkeyConfig.formatters = {
'tr': function (name, options, data) {
var html = '
';
switch (options.type) {
case 'checkbox':
/* Checkboxes get special treatment */
html += '
';
html += MonkeyConfig.HTML['_field'](name, options, data) + ' ';
html += MonkeyConfig.HTML['_label'](name, options, data);
html += '
';
break;
default:
html += '
';
html += MonkeyConfig.HTML['_label'](name, options, data);
html += '
';
html += MonkeyConfig.HTML['_field'](name, options, data);
html += '