// ==UserScript==
// @name 播放器增强
// @namespace https://viayoo.com/
// @version 0.0.7
// @homepageURL https://app.viayoo.com/addons/26
// @author Nihility
// @run-at document-start
// @match *
// @grant none
// ==/UserScript==

.replace("", (_, __, config_text) => {
(window.__load_scripts__ = window.__load_scripts__ || []).push([config_text,
function () {

/* lib begin */

function debounce(fn, ms = 0) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn.apply(this, args), ms);
};
};

function throttle(fn, wait) {
let inThrottle, lastFn, lastTime;
return function(...args) {
if (!inThrottle) {
fn.apply(this, args);
lastTime = Date.now();
inThrottle = true;
} else {
clearTimeout(lastFn);
lastFn = setTimeout(function() {
if (Date.now() - lastTime >= wait) {
fn.apply(this, args);
lastTime = Date.now();
}
}, Math.max(wait - (Date.now() - lastTime), 0));
}
};
};

function is_same_size_position(ele1, ele2) {
try {
return ele1.clientWidth == ele2.clientWidth &&
ele1.clientHeight == ele2.clientHeight &&
ele1.scrollHeight == ele2.scrollHeight;
} catch {
return false;
}
}

function find_top_wrap_ele(ele) {
let wrap = ele;
while (ele.tagName !== 'BODY') {
ele = ele.parentElement;
if (is_same_size_position(wrap, ele)) {
wrap = ele;
}
}
return wrap;
}

function is_parent(ele, parent) {
while (ele.tagName !== 'BODY' &&
ele !== parent && ele.parentElement !== parent) {
ele = ele.parentElement;
}
return ele.parentElement === parent;
}

function flatten(array) {
if (!Array.isArray(array)) {
return [array];
} else if (array.length == 0) {
return [];
} else {
return flatten(array[0]).concat(flatten(array.slice(1)));
}
}

function zero_padding(number, length = 2) {
return Array(Math.max(length - number.toString().length, 0) + 1).join(0) + number;
}

function sec2HHMMSS(time, sec_base = 1) {
const sec = sec_base, min = 60 * sec, hour = 60 * min;
const h = Math.floor(time / hour);
const m = Math.floor(time % hour / min);
const s = Math.floor(time % min / sec);
let result = zero_padding(m) + ':' + zero_padding(s);
if (h) {
return zero_padding(h) + ':' + result;
} else {
return result;
}
}

function HHMMSS2sec(time, sec_base = 1) {
const sec = sec_base, min = 60 * sec, hour = 60 * min;
const split = time.split(':');
if (split.length < 3) {
split.unshift(0);
}
const h = split[0];
const m = split[1];
const s = split[2];
return h * hour + m * min + s * sec;
}

function get_1cm_pixel_num() {
const div = document.createElement('div');
div.style.cssText = ['position: fixed', 'width: 1cm', 'visibility: hidden'].join('; ');
document.body.append(div);
const pixel = div.clientWidth;
div.remove();
get_1cm_pixel_num = () => pixel;
return pixel;
}

function px2cm(px) {
return px / get_1cm_pixel_num();
}

/* lib end */

/* add custom event begin */

function copy(obj) {
const new_obj = {};
for (let i in obj) {
new_obj[i] = obj[i];
}
return new_obj;
}

function TapEvent(touch_event) {
return new TouchEvent('tap',
Object.assign(copy(touch_event),
{ bubbles: true, cancelable: true, composed: true }));
}

function DoubleTapEvent(touch_event) {
return new TouchEvent('doubletap',
Object.assign(copy(touch_event),
{ bubbles: true, cancelable: true, composed: true }));
}

function TouchEvent2MouseEvent(event_type, event) {
const touch = event.targetTouches && event.targetTouches[0] || {};
return new MouseEvent(event_type,
Object.assign({}, copy(event), copy(touch),
{ bubbles: true, cancelable: true, composed: true }));
}

function add_tap_event_hook(element) {
let start_touch, end_touch, end_event = {};
const start = e => {
start_touch = end_touch = copy(e.touches[0]);
end_event = copy(e);
};
const move = e => {
end_touch = copy(e.touches[0]);
end_event = copy(e);
};
const end = e => {
if (Math.abs(start_touch.clientX - end_touch.clientX) <= 10 &&
Math.abs(start_touch.clientY - end_touch.clientY) <= 10) {
e.target.dispatchEvent(new TapEvent(end_event));
e.preventDefault();
e.target.dispatchEvent(TouchEvent2MouseEvent('click', end_event));
}
};

element.addEventListener('touchstart', start, true);
element.addEventListener('touchmove', move, true);
element.addEventListener('touchend', end, true);

return function event_clearer() {
element.removeEventListener('touchstart', start, true);
element.removeEventListener('touchmove', move, true);
element.removeEventListener('touchend', end, true);
};
}

function add_doubletap_event_hook(element) {
let start_time = 0;
const doubletap_judge = e => {
if (Date.now() - start_time <= 250) {
start_time = 0;
e.target.dispatchEvent(new DoubleTapEvent(e));
} else {
start_time = Date.now();
}
};

element.addEventListener('tap', doubletap_judge, true);

return function event_clearer() {
element.removeEventListener('tap', doubletap_judge, true);
};
}

/* add custom event end */

function create_prompt_panel() {
const prompt_div = document.createElement('div');
const prompt_symbol_div = document.createElement('div');
const prompt_time_div = document.createElement('div');
const prompt_time_begin_span = document.createElement('span');
const prompt_time_end_span = document.createElement('span');

prompt_div.append(prompt_symbol_div, prompt_time_div);
prompt_time_div.append(prompt_time_begin_span, ' / ', prompt_time_end_span);

prompt_div.style.cssText = `
width: 10em;
position: absolute;
z-index: 99999999;
left: 50%;
top: 50%;
padding: 15px 0px;
margin: calc(-0.5em - 15px) auto auto -5em;
background-color: rgba(51, 51, 51, 0.8);
border-radius: 15px;
text-align: center;
font-size: 0.5cm;
color: white;
display: none;
`;
prompt_time_begin_span.style.color = '#2fb3ff';

return {
div: prompt_div,
symbol: prompt_symbol_div,
left_time: prompt_time_begin_span,
right_time: prompt_time_end_span,
};
}

function create_control_panel() {
const div = document.createElement('div');
const content_divs = Array(5).fill().map(() => document.createElement('div'));
div.append.apply(div, content_divs);

div.style.cssText = `
width: 100%;
height: 100%;
margin: 0;
padding: 0;
position: absolute;
z-index: 9999999999;
top: 0;
background-color: rgba(51, 51, 51, 0.8);
color: white;
box-sizing: border-box;

Next
Pg.: 1 2 3


Back to home | File page

Subscribe | Register | Login | N