Created
April 12, 2020 07:35
-
-
Save leobenkel/7668898fc05d1931ef8758d6fa815a18 to your computer and use it in GitHub Desktop.
Redirect to embed video when you open a youtube video link
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 Redirect to embed for youtube | |
// @namespace com.leobenkel | |
// @version 0.1 | |
// @description Redirect to embed video when you open a youtube video link | |
// @author Leo Benkel | |
// @match https://www.youtube.com/watch?v=* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var input = window.location.href; | |
var getArgs = input.split('?')[1]; | |
var getPairs = getArgs.split("&").map(function(x) { | |
var pair = x.split("=") | |
return pair; | |
}) | |
.reduce(function(map, obj) { | |
map[obj[0]] = obj[1]; | |
return map; | |
}, {}); | |
var videoId = getPairs.v; | |
var validPairs = {'v': videoId, 'feature': "emb_rel_end"}; | |
var validKeys = Object.keys(validPairs); | |
var values = Object.values(getPairs); | |
var keys = Object.keys(getPairs); | |
var myArray = keys.map(function(e, i) { | |
return [e, values[i]]; | |
}); | |
var filteredValues = myArray.filter(function(pair) { | |
var key = pair[0]; | |
var value = pair[1]; | |
console.log(key); | |
console.log(value); | |
var isValid = validKeys.includes(key) && validPairs[key] == value; | |
return !isValid; | |
}); | |
if (filteredValues.length == 0) { | |
var url = 'https://www.youtube.com/embed/' + videoId | |
window.location = url | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment