Skip to content

Instantly share code, notes, and snippets.

@fortserious
Last active March 13, 2024 21:26
Show Gist options
  • Save fortserious/31b8f38a537d3047913ff9aa13de0a07 to your computer and use it in GitHub Desktop.
Save fortserious/31b8f38a537d3047913ff9aa13de0a07 to your computer and use it in GitHub Desktop.
youtube restart button
// ==UserScript==
// @name youtube play from beginning
// @namespace www.rossdoran.com
// @version 0.2
// @description me
// @match https://www.youtube.com/watch?v=*
// @match https://www.youtube.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @copyright ross doran 2023
// ==/UserScript==
// custom style
$('head').append('<style type="text/css">'+
'.ytp-replay-button { -webkit-box-flex: 0; -webkit-flex: 0 0 auto; -moz-box-flex: 0; -ms-flex: 0 0 auto; flex: 0 0 auto; }' +
'</style>');
OnLoad(".ytp-prev-button.ytp-button:not('#ytp-replay-button')", function callback(jNode) {
let video = document.querySelector("video");
var newNode = document.createElement('a');
newNode.setAttribute("id", "ytp-replay-button");
newNode.className = "ytp-prev-button ytp-button";
newNode.innerHTML = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="10px" y="0px"'+
'width="100%" viewBox="-15 -5 50 50">'+
'<g>'+
' <path fill="#FFFFFF" stroke="none" d="M27.094,17.125c0.026,0.283,0.044,0.568,0.044,0.857'+
' c0,5.171-4.206,9.377-9.377,9.377s-9.377-4.206-9.377-9.377s4.207-9.377,9.377-9.377v-4c-7.376,0-13.377,6.001-13.377,13.377'+
' c0,7.376,6.001,13.377,13.377,13.377c7.376,0,13.377-6.001,13.377-13.377c0-0.289-0.025-0.572-0.044-0.857H27.094z"/>'+
'</g>'+
'<polygon fill="#FFFFFF" stroke="none" points="17.659,2.25 17.659,10.896 22.94,6.573 "/>'+
'<polygon fill="#FFFFFF" stroke="none" points="16.659,13.25 16.659,23.959 21.94,18.604 "/>'+
'</svg>';
jNode.parent().prepend(newNode);
newNode.addEventListener('click', function(){
video.currentTime = 0;
video.play();
}, false);
});
function OnLoad(selector, callback)
{
waitForKeyElements(selector, callback);
}
@fortserious
Copy link
Author

v0.2 - added youtube home page to match to ensure script is loaded from general homepage results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment