Last active
May 24, 2022 22:09
-
-
Save HelloWorld017/e03851897a0799121fb10001491150c2 to your computer and use it in GitHub Desktop.
라프텔 화질을 최고화질로 고정합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Laftel force highest quality | |
// @namespace https://gist.github.com/HelloWorld017/e03851897a0799121fb10001491150c2 | |
// @version 0.2 | |
// @description Set laftels quality as high as possible | |
// @author Khinenw | |
// @match *://*.laftel.net/* | |
// @grant none | |
// ==/UserScript== | |
const setFormat = callback => { | |
if(!location.href.includes('/player')) | |
return callback(); | |
if(!window.vidComponent || !window.vidComponent.player || !window.vidComponent.state.tracks) | |
return setTimeout(() => setFormat(callback), 1000); | |
try { | |
const formats = window.vidComponent.state.tracks | |
.filter(track => track.raw) | |
.sort((track1, track2) => track2.raw.height - track1.raw.height); | |
if(formats.length === 0) | |
return setTimeout(() => setFormat(callback), 1000); | |
const bestFormat = formats[0].id; | |
window.vidComponent.handleSelectQuality(bestFormat); | |
console.log(`Format set to ${formats[0].text}`); | |
callback(true); | |
} catch(e) { | |
console.error(e); | |
callback(false); | |
} | |
}; | |
const setFormatPromise = () => new Promise(resolve => setFormat(resolve)); | |
let previousUrl; | |
const checkPushState = async () => { | |
if(previousUrl !== location.href) { | |
previousUrl = location.href; | |
await setFormatPromise(); | |
} | |
setTimeout(checkPushState, 1000); | |
}; | |
checkPushState(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment