Skip to content

Instantly share code, notes, and snippets.

@mewisme
Last active May 16, 2025 18:59
Show Gist options
  • Select an option

  • Save mewisme/9bf4051990d2b459c4dd00e5665adc2d to your computer and use it in GitHub Desktop.

Select an option

Save mewisme/9bf4051990d2b459c4dd00e5665adc2d to your computer and use it in GitHub Desktop.
A user script for AnimeVietsub that enhances video player control using keyboard shortcuts.
/* globals jQuery, $, waitForKeyElements */
/* eslint-disable userscripts/avoid-regexp-include */
// ==UserScript==
// @name AnimeVietsub Hotkey Enhancer
// @namespace http://mewis.me/userscript/animevietsub-hotkey
// @version 1.0.3
// @description A user script for AnimeVietsub that enhances video player control using keyboard shortcuts.
// @author MewTheDev
// @require https://code.jquery.com/jquery-3.7.1.min.js
// @include /^https:\/\/animevietsub\..*/
// @icon https://www.google.com/s2/favicons?sz=64&domain=animevietsub.red
// ==/UserScript==
(function () {
'use strict';
// Tạo giao diện div chuyển đổi bật/tắt auto play
function createDivSwitch(enabled) {
return `
<div style="align-items:center; background:rgba(255,255,255,0.05); border-radius:6px; box-shadow:0 2px 4px rgba(0,0,0,0.2); display:flex; margin-bottom:6px; padding:8px">
<div style="align-items:center; background:#ff4d4d; border-radius:50%; display:flex; height:24px; justify-content:center; margin-right:8px; width:24px">📌</div>
<div style="flex:1">
<div style="align-items:center; display:flex; flex-wrap:wrap; gap:5px; justify-content:space-between">
<div>
<strong>TỰ ĐỘNG PHÁT</strong><br>
<span style="font-size:16px">Tự động phát video khi bạn đã xem xong phần trước</span>
</div>
<button style="background:#ff4d4d; color:#fff; padding:5px 10px; font-size:11px; font-weight:bold; text-decoration:none; border-radius:20px">
Trạng thái: <span class="auto-play-status">${enabled ? 'Đã bật' : 'Đã tắt'}</span>
</button>
</div>
</div>
</div>
`;
}
// Quản lý trạng thái auto play lưu trên localStorage
function autoPlayManager() {
const storageKey = 'animevietsub-auto-play-enabled';
return {
getEnabled: () => localStorage.getItem(storageKey) === 'true',
setEnabled: (enabled) => localStorage.setItem(storageKey, enabled),
toggleEnabled: () => {
const current = localStorage.getItem(storageKey) === 'true';
localStorage.setItem(storageKey, !current);
}
};
}
// Tự động click nút play JWPlayer (có thể gọi khi cần)
function autoPlayJW() {
let attempts = 0;
const maxAttempts = 10;
const interval = setInterval(() => {
const $btn = $('.jw-icon.jw-icon-display.jw-button-color.jw-reset').first();
if ($btn.length) {
console.log('⏯️ Tự động click nút Play JWPlayer với jQuery');
$btn.click();
clearInterval(interval);
} else if (++attempts >= maxAttempts) {
clearInterval(interval);
console.log('❌ Không tìm thấy nút play JWPlayer');
}
}, 500);
}
// Chạy khi DOM sẵn sàng
$(document).ready(() => {
const selectors = {
skip: 'div[button="skipButton"]',
fullscreen: 'div.jw-icon-fullscreen',
reset: 'video.jw-video.jw-reset',
next: 'div#btn-nextepisode'
};
const autoPlay = autoPlayManager();
// Tìm container để append giao diện bật/tắt auto play
const $container = $('.announcement > .ann_text > div:first > div:eq(1)');
if ($container.length === 0) {
console.warn('⚠️ Không tìm thấy container để append giao diện auto play');
return;
}
// Thêm giao diện toggle trạng thái
$container.append(createDivSwitch(autoPlay.getEnabled()));
// Xử lý click nút toggle
$container.find('button').click(function () {
autoPlay.toggleEnabled();
const statusText = autoPlay.getEnabled() ? 'Đã bật' : 'Đã tắt';
$(this).find('.auto-play-status').text(statusText);
});
if (autoPlay.getEnabled()) {
autoPlayJW();
}
// Sự kiện phím tắt
$(document).keydown(event => {
switch (event.key.toLowerCase()) {
case 'b':
$(selectors.skip).click();
break;
case 'z':
$(selectors.fullscreen).click();
break;
case 'p':
if ($(selectors.reset).length) $(selectors.reset)[0].play();
break;
case 'x':
$(selectors.next).click();
break;
case 'a':
if ($(selectors.reset).length) $(selectors.reset)[0].play();
$(selectors.fullscreen).click();
break;
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment