My m.youtube.com greasyfork scripts https://greasyfork.org/en/users/1193838-hlorand
Last active
August 10, 2024 12:59
-
-
Save hlorand/e74cfddb641878b10e800237cc55913d to your computer and use it in GitHub Desktop.
My m.youtube.com greasyfork scripts https://greasyfork.org/en/users/1193838-hlorand
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 m.YouTube.com auto fullscreen on rotate | |
// @namespace m-youtube-com-auto-fullcreen-on-rotate | |
// @version 1.1 | |
// @description Switches the video to full-screen mode when you rotate your smart device | |
// @author hlorand.hu | |
// @match https://m.youtube.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// @license https://creativecommons.org/licenses/by-nc-sa/4.0/ | |
// @downloadURL https://update.greasyfork.org/scripts/477524/mYouTubecom%20auto%20fullscreen%20on%20rotate.user.js | |
// @updateURL https://update.greasyfork.org/scripts/477524/mYouTubecom%20auto%20fullscreen%20on%20rotate.meta.js | |
// ==/UserScript== | |
// Screenshot: https://ibb.co/chtmD9F | |
(function() { | |
//'use strict'; | |
var isFullscreen = false; | |
window.addEventListener("orientationchange", (event) => { | |
let player = document.getElementById("player-container-id"); | |
let angle = event.target.screen.orientation.angle; | |
console.log(angle, isFullscreen); | |
// enter fullscreen | |
if( !isFullscreen && (angle > 60 && angle < 120 || angle > 240 && angle < 300) ){ | |
player.requestFullscreen(); | |
isFullscreen = true; | |
return; | |
} | |
// exit fullscreen | |
if( isFullscreen && (angle > 330 || angle < 30 || angle > 150 && angle < 210) ){ | |
document.exitFullscreen(); | |
isFullscreen = false; | |
return; | |
} | |
}); | |
})(); |
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 YouTube.com more playback speeds (Mobile / Desktop) | |
// @namespace m-youtube-com-more-playback-speeds | |
// @version 1.11 | |
// @description Adds 2.25x 2.5x 2.75x 3x speed buttons below the video. Works on mobile, tablet (m.youtube.com) and on desktop. | |
// @author hlorand.hu | |
// @match https://m.youtube.com/* | |
// @match https://youtube.com/* | |
// @match https://*.youtube.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// @license https://creativecommons.org/licenses/by-nc-sa/4.0/ | |
// ==/UserScript== | |
// Screenshot: https://ibb.co/chtmD9F | |
(function() { | |
//'use strict'; | |
function setspeed(speed){ | |
// highlight | |
document.querySelectorAll(".speedbutton").forEach((btn)=>{ | |
if( btn.textContent == speed){ | |
btn.style.backgroundColor = "darkorange"; | |
} else { | |
btn.style.backgroundColor = "blue"; | |
} | |
}); | |
let video = document.querySelector("video"); | |
if(video && video.readyState >= 2) { | |
localStorage.setItem("yt_playbackspeed", speed); | |
video.playbackRate = speed; | |
video.mozPreservesPitch = video.webkitPreservesPitch = video.preservePitch = true; | |
} | |
} | |
function addbuttons(){ | |
document.getElementById("speedbuttons").innerHTML = ""; | |
const speeds = ["3.5","3.25","3.0","2.75","2.5","2.25","2.0","1.75","1.5","1.25","1.0"]; | |
speeds.forEach((speed)=>{ | |
let button = document.createElement('button'); | |
button.textContent = speed; | |
button.className = "speedbutton"; | |
button.style.margin = "4px"; | |
button.style.padding = "4px"; | |
button.style.backgroundColor = "blue"; | |
button.style.position = "relative"; | |
button.onclick = function() { | |
setspeed(this.textContent); | |
}; | |
let target = document.getElementById("speedbuttons"); | |
target.insertBefore(button, target.firstChild); | |
}); // end speeds foreach | |
} // end addbuttons | |
// Periodically check if the buttons are visible | |
// (sometimes YouTube redraws its interface). | |
setInterval(()=>{ | |
// Creating a div that will contain buttons. | |
if( document.getElementById("speedbuttons") == undefined ){ | |
// placement of buttons on desktop | |
let parent = document.getElementById('above-the-fold'); | |
// placement of buttons on tablet | |
if( !parent ){ | |
parent = document.querySelector('.watch-below-the-player'); | |
} | |
// placement of buttons on mobile | |
if( !parent ){ | |
parent = document.querySelector('.related-chips-slot-wrapper'); | |
} | |
let wrapper = document.createElement('div'); | |
wrapper.setAttribute("id","speedbuttons"); | |
parent.insertBefore(wrapper, parent.firstChild); | |
addbuttons(); | |
} | |
// Sometimes the buttons are not added, so I check and add them if necessary. | |
if( document.getElementById("speedbuttons").textContent.trim() === '' ){ | |
addbuttons(); | |
} | |
setspeed( localStorage.getItem("yt_playbackspeed") ?? 1 ); | |
}, 1000); | |
})(); |
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 m.YouTube.com allow background play TEST SCRIPT | |
// @namespace m-youtube-com-allow-background-play | |
// @version 1.0 | |
// @description Allows m.YouTube.com background play, especially useful for iPhone users | |
// @author hlorand.hu | |
// @match https://m.youtube.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// @license https://creativecommons.org/licenses/by-nc-sa/4.0/ | |
// ==/UserScript== | |
// Original code: https://addons.mozilla.org/en-US/android/addon/video-background-play-fix/ | |
(function() { | |
//'use strict'; | |
const IS_YOUTUBE = window.location.hostname.search(/(?:^|.+\.)youtube\.com/) > -1 || | |
window.location.hostname.search(/(?:^|.+\.)youtube-nocookie\.com/) > -1; | |
const IS_MOBILE_YOUTUBE = window.location.hostname == 'm.youtube.com'; | |
const IS_DESKTOP_YOUTUBE = IS_YOUTUBE && !IS_MOBILE_YOUTUBE; | |
const IS_VIMEO = window.location.hostname.search(/(?:^|.+\.)vimeo\.com/) > -1; | |
const IS_ANDROID = window.navigator.userAgent.indexOf('Android') > -1; | |
// Page Visibility API | |
if (IS_ANDROID || !IS_DESKTOP_YOUTUBE) { | |
Object.defineProperties(document.wrappedJSObject, | |
{ 'hidden': {value: false}, 'visibilityState': {value: 'visible'} }); | |
} | |
window.addEventListener( | |
'visibilitychange', evt => evt.stopImmediatePropagation(), true); | |
// Fullscreen API | |
if (IS_VIMEO) { | |
window.addEventListener( | |
'fullscreenchange', evt => evt.stopImmediatePropagation(), true); | |
} | |
// User activity tracking | |
if (IS_YOUTUBE) { | |
loop(pressKey, 60 * 1000, 10 * 1000); // every minute +/- 5 seconds | |
} | |
function pressKey() { | |
const keyCodes = [18]; | |
let key = keyCodes[getRandomInt(0, keyCodes.length)]; | |
sendKeyEvent("keydown", key); | |
sendKeyEvent("keyup", key); | |
} | |
function sendKeyEvent (aEvent, aKey) { | |
document.dispatchEvent(new KeyboardEvent(aEvent, { | |
bubbles: true, | |
cancelable: true, | |
keyCode: aKey, | |
which: aKey, | |
})); | |
} | |
function loop(aCallback, aDelay, aJitter) { | |
let jitter = getRandomInt(-aJitter/2, aJitter/2); | |
let delay = Math.max(aDelay + jitter, 0); | |
window.setTimeout(() => { | |
aCallback(); | |
loop(aCallback, aDelay, aJitter); | |
}, delay); | |
} | |
function getRandomInt(aMin, aMax) { | |
let min = Math.ceil(aMin); | |
let max = Math.floor(aMax); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment