Last active
September 13, 2024 10:33
-
-
Save remram44/cf9330ce5805bb3413f20f9fbee25d15 to your computer and use it in GitHub Desktop.
Embed HTML in Google Slides
This file contains hidden or 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 Google Slides embedder | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Shows an iframe in Google Slides presentation to fake embedding | |
// @author Remi Rampin | |
// @match https://docs.google.com/presentation/d/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var injectFrame; | |
window.setInterval(function() { | |
if(injectFrame && !injectFrame.parentNode) { | |
console.log("Frame is gone"); | |
injectFrame = undefined; | |
} | |
var presoFrame = document.getElementsByClassName('punch-present-iframe') | |
if(!presoFrame || !presoFrame.length) { | |
return; | |
} | |
presoFrame = presoFrame[0]; | |
console.log("found punch-present-iframe", presoFrame); | |
if(!injectFrame) { | |
injectFrame = presoFrame.contentDocument.createElement('iframe'); | |
injectFrame.setAttribute('src', 'https://spire.remram.fr/'); | |
injectFrame.setAttribute('width', '400'); | |
injectFrame.setAttribute('height', '400'); | |
injectFrame.setAttribute('style', 'position: absolute; z-index: 300;'); | |
injectFrame.className = "rr4_inject_frame"; | |
presoFrame.contentDocument.body.appendChild(injectFrame); | |
console.log("created iframe", injectFrame); | |
} | |
var texts = presoFrame.contentDocument.getElementsByTagName('text'); | |
console.log("", texts.length, "text elements"); | |
var targetText; | |
for(var i = 0; i < texts.length; ++i) { | |
console.log("text:", texts[i].textContent); | |
if(texts[i].textContent === 'Embedding...') { | |
targetText = texts[i]; | |
} | |
} | |
if(targetText) { | |
console.log("Found target text", targetText); | |
var rect = targetText.getClientRects()[0]; | |
injectFrame.setAttribute('style', 'position: absolute; z-index: 300; left: ' + Math.round(rect.left) + 'px; top: ' + Math.round(rect.top) + 'px;'); | |
} else { | |
console.log("deleting iframe"); | |
injectFrame.parentNode.removeChild(injectFrame); | |
injectFrame = undefined; | |
} | |
}, 800); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The setInterval is only useful in preview mode, suggestion: only register the interval in presentation mode, also then you're inside the iframe you can just use
window.document
: