Common.js/redditWidget.js

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: メニュー → 設定 (Mac では Opera → 環境設定) に移動し、プライバシーとセキュリティ → 閲覧データを消去 → キャッシュされた画像およびファイル からキャッシュをクリアしてください。
/* ================================================== */ 
/* ====   Reddit Widget                          ==== */ 
/* ================================================== */ 
$(document).ready(function()
{     
    var enableWidget = document.getElementById("reddit-widget");
    
    if (enableWidget)     
    {         
        // Reddit cannot be loaded through appending script tag as homepage has scripts that interferes with reddit script         
        var redditWidget = document.createElement("iframe");         
        redditWidget.width = "100%";         
        enableWidget.appendChild(redditWidget);           
        
        // Add the script          
        redditWidget.contentWindow.document.write("<html><head></head><body><script src='https://www.reddit.com/r/PolandballJapanese/new/.embed?limit=4&t=all&sort=new' type='text/javascript'></script></body></html>");           
        
        // Readjust height based on how much content reddit widget has         
        var tryReadjust = setInterval(function()         
        {             
            // Take contents of iframe out and put it on page (lol)             
            // Otherwise page keeps loading (for some reason), and cannot be clicked because Reddit            
            // set X-Frame-options to SAMEORIGIN             
            var t = redditWidget.contentDocument.children;              
            t = t[0].getElementsByClassName("rembeddit")[0];              
            if (t)             
            {                 
                // Have to wait until element exists before taking it out               
                document.getElementById("reddit-widget").appendChild(t);                 
                redditWidget.remove();                 
                clearInterval(tryReadjust);             
            }
        }, 1000);       
    
    }   
                
});