Skip to content

Instantly share code, notes, and snippets.

@TroudhuK
Last active January 1, 2020 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TroudhuK/51186ee4d8161d46fbe9ea3ad8946e33 to your computer and use it in GitHub Desktop.
Save TroudhuK/51186ee4d8161d46fbe9ea3ad8946e33 to your computer and use it in GitHub Desktop.
Fix Dailymotion integration on Gamekult
// ==UserScript==
// @name Gamekult Video
// @namespace com
// @description Gamekult Video
// @include *gamekult.com/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
// https://developer.mozilla.org/fr/docs/Web/JavaScript/Same_origin_policy_for_JavaScript#Changer_l'origine
document.domain = "gamekult.com";
// https://stackoverflow.com/a/24603642
// This function ONLY works for iFrames of the same origin as their parent
function iFrameReady(iFrame, fn) {
var timer;
var fired = false;
function ready() {
if (!fired) {
fired = true;
clearTimeout(timer);
fn.call(this);
}
}
function readyState() {
if (this.readyState === "complete") {
ready.call(this);
}
}
// cross platform event handler for compatibility with older IE versions
function addEvent(elem, event, fn) {
if (elem.addEventListener) {
return elem.addEventListener(event, fn);
} else {
return elem.attachEvent("on" + event, function () {
return fn.call(elem, window.event);
});
}
}
// use iFrame load as a backup - though the other events should occur first
addEvent(iFrame, "load", function () {
ready.call(iFrame.contentDocument || iFrame.contentWindow.document);
});
function checkLoaded() {
let doc = iFrame.contentDocument || iFrame.contentWindow.document;
// We can tell if there is a dummy document installed because the dummy document
// will have an URL that starts with "about:". The real document will not have that URL
if (doc.URL.indexOf("about:") !== 0) {
if (doc.readyState === "complete") {
ready.call(doc);
} else {
// set event listener for DOMContentLoaded on the new document
addEvent(doc, "DOMContentLoaded", ready);
addEvent(doc, "readystatechange", readyState);
}
} else {
// still same old original document, so keep looking for content or new document
timer = setTimeout(checkLoaded, 1);
}
}
checkLoaded();
}
function processIframes(iframes) {
if (iframes) {
for(i = 0; i < iframes.length; i++) {
let ifr = iframes[i];
if (ifr.src.indexOf('autoplay=1') !== -1) {
ifr.src = ifr.src.replace(/autoplay=1/g,'autoplay=0');
}
if (ifr.src.indexOf('mute=1') !== -1) {
ifr.src = ifr.src.replace(/mute=1/g,'mute=0');
}
if (ifr.src.indexOf('dailymotion.com') !== -1) {
ifr.src += ((ifr.src.indexOf('?') === -1) ? "?" : "&") + "sharing-enable=false&queue-enable=false&quality=1080";
}
if (ifr.src.indexOf('premium.gamekult.com') !== -1) {
iFrameReady(ifr, function() {
processIframes(this.getElementsByTagName('iframe'));
});
}
}
}
}
window.addEventListener('DOMContentLoaded', function() {
processIframes(document.getElementsByTagName('iframe'));
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment