(function(){ 'use strict'; var plugin_url = 'https://memes.tw'; if (window.MEMES_MAKER_LOADDED) return; window.MEMES_MAKER_LOADDED = true; var threads = document.querySelectorAll('.memes-maker'); for (var i = 0; i < threads.length; ++i) { const thread = threads[i]; const id = thread.dataset.id; const loader = document.createElement('div'); loader.innerText = '正在載入梗圖產生器...'; thread.appendChild(loader); const url = window.location.href; const iframe = document.createElement('iframe'); iframe.src = plugin_url + '/maker/embed/' + id + '?url=' + encodeURI(url); iframe.width = '100%'; iframe.frameBorder = '0'; iframe.style.width = '600px'; iframe.style.maxWidth = '100%'; iframe.onload = function() { loader.style.display = 'none'; } thread.appendChild(iframe); window.addEventListener( "message", function (e) { if (e.origin == plugin_url) { if (id == e.data.id) { const currentPosX = window.scrollX || window.screenLeft; const currentPosY = window.scrollY || window.screenTop; thread.style.height = e.data.height + 'px'; iframe.height = e.data.height; window.scrollTo(currentPosX, currentPosY); } } }, false ); } })();