Raw Source
esoytekin / Eksi Okutman

// ==UserScript==
// @name       Eksi Okutman
// @namespace  http://eksisozluk.com/*
// @version    5.0.2
// @license Apache-2.0
// @description  Eksi Sozlugu Kolay Okunabilir Yapma Aparati
// @include http://eksisozluk.com/*
// @include https://eksisozluk.com/*
// @match      http://eksisozluk.com/*
// @match      https://eksisozluk.com/*
// @copyright  2021+, b w n s p
// @grant      none
// @downloadURL http://userscripts.org/scripts/source/162247.user.js
// @updateURL https://openuserjs.org/meta/esoytekin/Eksi_Okutman.meta.js
// ==/UserScript==

function setCookie(e,t,n){var l=new Date,t=(l.setDate(l.getDate()+n),escape(t)+(null==n?"":"; expires="+l.toUTCString()));document.cookie=e+"="+t}function getCookie(e){for(var t,n,l=document.cookie.split(";"),o=0;o<l.length;o++)if(t=l[o].substr(0,l[o].indexOf("=")),n=l[o].substr(l[o].indexOf("=")+1),(t=t.replace(/^\s+|\s+$/g,""))==e)return unescape(n)}function delCookie(e){document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"}var hizliOkuWordIndex=0,n="";const resetReader=()=>{hizliOkuWordIndex=0,clearInterval(timeOut)},setFastBody=e=>{var t=document.getElementById("txtBody"),l=(t.innerHTML="",document.createElement("div")),e=(l.classList.add("txtFastContent"),l.style.paddingTop="60px",resetReader(),getArticleContentForFast(e)),e="<div class = 'divText' style  = 'width:100%;text-align:center;font-size:45px; border-bottom:solid 0px;'>"+(n=e.split(" "))[hizliOkuWordIndex]+"</div><br /><center><div class='textMeterBack' style = 'width:150px; height:30px; background:#ebebeb;box-shadow: 0px 0px 8px #000;'><div class = 'textMeterFront' style = 'height:30px; width : "+150*(hizliOkuWordIndex+1)/n.length+"px; background:#ccc; float:left;'></div></div></center>";document.body.parentNode.style.overflow="hidden",l.innerHTML=e,t.appendChild(l),setFastButtons(),setFastButtonEvents()},setFastButtonEvents=()=>{const l=document.getElementById("txtBody");var e,t=l.querySelector(".btnOkutmanOptions"),o="goster",t=(t.onclick=function(){var n=setInterval(function(){var e=l.getElementsByClassName("okutmanSettings")[0],t=parseInt(e.style.height);"goster"==o&&190<=t||"gizle"==o&&t<=0?(o="goster"==o?"gizle":"goster",clearInterval(n)):e.style.height="goster"==o?t+5+"px":t-5+"px"},1)},l.getElementsByClassName("textSpeed")[0]),t=(t.value=getCookie("okutmanSpeed"),t.onchange=function(){setCookie("okutmanSpeed",this.options[this.selectedIndex].value,30)},l.getElementsByClassName("chClose")[0]),t=(getCookie("okutmanClose")&&"true"==getCookie("okutmanClose")?t.checked=!0:t.checked=!1,t.onchange=function(){this.checked?setCookie("okutmanClose",!0,30):delCookie("okutmanClose")},l.getElementsByClassName("chOtoStart")[0]),n=(getCookie("okutmanOtoStart")&&"true"==getCookie("okutmanOtoStart")?(t.checked=!0,n=l.querySelector(".btnStop"),e=0,e=parseInt(getCookie("okutmanSpeed"))||200,n.innerHTML="durdur",timeOut=setInterval(function(){flowText(l),hizliOkuWordIndex++},6e4/e)):t.checked=!1,t.onchange=function(){this.checked?setCookie("okutmanOtoStart",!0,30):delCookie("okutmanOtoStart")},l.getElementsByClassName("btnStop")[0]);n.onclick=startStopContent},setFastButtons=()=>{let e="<center><button class = 'btnStop'>baslat</button><button class='btnOkutmanOptions'>secenekler</button></center><br /><center><div class='okutmanSettings' style='height:0px;display:inline-block;overflow:hidden;'><table><tr><td><label for='chClose'>bitiste otomatik kapansin</label></td><td ><input type='checkbox' name='autoClose' value='closePanel' id = 'chClose' class = 'chClose'/></td></tr><tr><td><label for='chOtoStart'>acilista otomatik baslasin</label></td><td><input type = 'checkbox' class = 'chOtoStart' id = 'chOtoStart'/></td></tr><tr><td><label>dakikada kelime hizi</label></td><td><select style = 'width:100px' class='textSpeed' size = '1'>";for(var t=200;t<550;t+=50)e+="<option value = '"+t+"'>"+t+"</option>";e+="</select></td></tr></table></div></center>";var n=document.createElement("div");n.style.marginTop="10px",n.innerHTML=e,document.querySelector("#txtBody").appendChild(n)};function getHizliOkuContent(e,t){showPagingDiv(),hideMainButtons(),isLarge=!(isFast=!0),hizliOkuWordIndex=0,showModal(),setTitle(e),setFastBody(e),createSuserPanel(e),document.body.parentNode.style.overflow="hidden",createPageContent(),setPageIndexColor(t)}function startStopContent(){var e,t=document.getElementById("txtBody"),n=t.getElementsByClassName("btnStop")[0];"durdur"==n.innerHTML?(n.innerHTML="baslat",clearInterval(timeOut)):(e=0,e=parseInt(getCookie("okutmanSpeed"))||200,n.innerHTML="durdur",timeOut=setInterval(function(){flowText(t),hizliOkuWordIndex++},6e4/e)),madeBlack(t)}function findArticleIndex(t,e){var n=e.closest("li").getAttribute("data-id");for(let e=0;e<t.length;e++)if(t[e].getAttribute("data-id")===n)return e}function createSuserPanel(e){var t=document.getElementById("suserPanel"),n=(t.innerHTML="",e.getElementsByClassName("info")[0]),l=n.getElementsByClassName("entry-author")[0].cloneNode(!0);l.style.cssFloat="right",t.appendChild(l);var l=n.getElementsByClassName("entry-date")[0].cloneNode(!0);l.style.cssFloat="right",l.style.paddingRight="10px",t.appendChild(l),e.getElementsByClassName("favorite-count")[0]&&(n=e.getElementsByClassName("favorite-count")[0].innerText,(l=document.createElement("div")).style.cssFloat="right",l.style.paddingRight="10px",l.style.color="#888",l.style.fontWeight="bold",l.innerHTML="[f: "+n+"]",t.appendChild(l))}function madeBlack(l){var o=l.style.backgroundColor,e=o.indexOf(")")-4,i=(o=(o=o.substr(4,e)).split(", "),setInterval(function(){var e=l.style.backgroundColor.toString(),t=e.indexOf(")")-4,t=(e=(e=e.substr(4,t)).split(", "),parseInt(e[0])-3),n=parseInt(e[1])-3,e=parseInt(e[2])-3;l.style.backgroundColor="#"+rgbToHex(t,n,e),t<=120&&(clearInterval(i),fadeToColor(l,o))},10))}const hidePanels=()=>{clearInterval(timeOut);var e=document.getElementById("backPnl");e.style.display="none",(e=document.getElementById("whitPnl")).style.display="none",document.body.parentNode.style.overflow="auto"},isDarkTheme=()=>document.body.classList.contains("dark-theme");function flowText(e){if(hizliOkuWordIndex==n.length)clearInterval(timeOut),getCookie("okutmanClose")&&"true"==getCookie("okutmanClose")&&hidePanels(),e.getElementsByClassName("btnStop")[0].innerHTML="baslat",hizliOkuWordIndex=-1;else{for(;n[hizliOkuWordIndex].length<=0;)hizliOkuWordIndex++;for(;n[hizliOkuWordIndex].split(" ")[0]==n[hizliOkuWordIndex+1];)n[hizliOkuWordIndex+1]=n[hizliOkuWordIndex]+" "+n[hizliOkuWordIndex+1],hizliOkuWordIndex++;e.getElementsByClassName("divText")[0].innerHTML=n[hizliOkuWordIndex],e.getElementsByClassName("textMeterFront")[0].style.width=150*(hizliOkuWordIndex+1)/n.length+"px"}}function rgbToHex(e,t,n){return toHex(e)+toHex(t)+toHex(n)}function toHex(e){return e=parseInt(e,10),isNaN(e)?"00":(e=Math.max(0,Math.min(e,255)),"0123456789ABCDEF".charAt((e-e%16)/16)+"0123456789ABCDEF".charAt(e%16))}function fadeToColor(l,o){var i=setInterval(function(){var e=l.style.backgroundColor.toString(),t=e.indexOf(")")-4,t=(e=(e=e.substr(4,t)).split(", "),parseInt(e[0])+3),n=parseInt(e[1])+3,e=parseInt(e[2])+3;l.style.backgroundColor="#"+rgbToHex(t,n,e),t>=parseInt(o[0])&&clearInterval(i)},10)}const setFastPanelContent=e=>{setFastBody(e);e=getArticleTitle(e);setModalTitle(e)};function getRahatOkuContent(e,t){var n=getMaxIndex(),n=(document.getElementById("PageContent").style.display=1<n?"block":"none",isFast=!(isLarge=!0),console.log("new articleIndex: "+t),document.getElementById("backPnl"));n.style.display="block",(n=document.getElementById("whitPnl")).style.display="block",setTitle(e);document.getElementById("txtBody").style.paddingTop="10px";n=getArticleContent(e);setTextBody(n),document.body.parentNode.style.overflow="hidden",createSuserPanel(e),createPageContent(),setPageIndexColor(t)}const setTextBody=e=>{var t=document.getElementById("txtBody"),n=(t.innerHTML="",document.createElement("p"));n.id="txtBodyP",n.tabindex="0",n.innerHTML=e,n.style.textAlign="justify",t.appendChild(n)},setRahatBody=e=>{var t=document.getElementById("txtBody"),e=getArticleContent(e);setTextBody(e),t.scrollTop=0};function setRahatOkuContent(e){createSuserPanel(e),setRahatBody(e);e=getArticleTitle(e);setModalTitle(e)}function createPageContent(){var e=document.getElementById("PageContent");if(""===e.innerHTML)for(var t=getMaxIndex(),n=0;n<t;n++){var l=document.createElement("a");l.href="javascript://",l.style.display="inline-block",l.style.height="20px",l.style.margin="3px",l.style.width="20px",isDarkTheme()?(l.style.backgroundColor="#2d2d2d",l.style.color="#cccccc"):l.style.backgroundColor="#cccccc",l.innerHTML=n+1,l.onclick=function(e){goToArticle(parseInt(e.target.innerHTML)-1)},e.appendChild(l)}}function setPageIndexColor(e){setArticleIndex(e);for(var t=document.getElementById("PageContent").childNodes,n=0;n<t.length;n++){var l=t[n],o=parseInt(l.innerHTML)-1;isDarkTheme()?l.style.backgroundColor="#2d2d2d":l.style.backgroundColor="#cccccc",l.style.boxShadow="",e==o&&(l.style.backgroundColor="#04B486",l.style.boxShadow="0px 0px 3px #000")}}function prevClicked(){var e,t=getArticleIndex();0!==t&&(t=t-1,e=document.querySelectorAll("ul#entry-item-list > li")[t],isLarge?setRahatOkuContent(e):isFast&&setFastPanelContent(e),setPageIndexColor(t),document.querySelector("p#txtBodyP").focus())}function nextClicked(){var e,t=getArticleIndex();t!=getMaxIndex()-1&&(t=t+1,e=document.querySelectorAll("ul#entry-item-list > li")[t],isLarge?setRahatOkuContent(e):isFast&&setFastPanelContent(e),setPageIndexColor(t),document.querySelector("p#txtBodyP").focus())}function goToArticle(e){articleIndex=e;var t=document.querySelectorAll("ul#entry-item-list > li")[e];isLarge?setRahatOkuContent(t):isFast&&setFastPanelContent(t),setPageIndexColor(e)}var isLarge=!1,isFast=!1,timeOut=0;const createButtons=()=>{var e=document.createElement("div");return e.innerHTML=`
            <a class = 'btnGenis' style = 'font-size:0.8em; color:#666; margin-right: 5px;display:none;'>rahat oku</a>
            <a class = 'btnCls' style = 'font-size:0.8em; color:#666;display:none;' >hızlı oku</a>
    `,e.style.height="20px",e.style.width="100%",e.style.textAlign="right",e.style.position="absolute",e.style.display="flex",e.style.justifyContent="flex-end",e.style.top="-2em",e},getAllArticles=()=>document.querySelectorAll("ul#entry-item-list > li"),getMaxIndex=()=>getAllArticles().length;var createMainButtons=function(){var t=getAllArticles();if(t)for(let e=0;e<t.length;e++){var n=createButtons();const l=t[e];l.getElementsByTagName("footer")[0].appendChild(n),l.getElementsByClassName("btnCls")[0].addEventListener("click",function(){getHizliOkuContent(l,e)},!1),l.getElementsByClassName("btnGenis")[0].addEventListener("click",function(){getRahatOkuContent(l,e)},!1),l.onmouseover=function(){var e=this.getElementsByClassName("btnCls");e&&(e[0].style.display="inline",e=this.getElementsByClassName("btnGenis"))&&(e[0].style.display="inline")},l.onmouseout=function(){var e=this.getElementsByClassName("btnCls");e&&(e[0].style.display="none",e=this.getElementsByClassName("btnGenis"))&&(e[0].style.display="none")}}};function switchView(){resetReader(),hidePanels();var e=getCurrentArticle();(isFast?getRahatOkuContent:getHizliOkuContent)(e,articleIndex)}function createPanel(){window.screen.availWidth||window.screen.width,window.screen.availHeight||window.screen.height;var e=document.createElement("div"),e=(e.id="backPnl",e.style.backgroundColor="#000",e.style.width="100%",e.style.height="100%",e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.zIndex="9999",e.style.display="none",e.style.opacity="1",e.addEventListener("click",hidePanels,!1),document.body.appendChild(e),document.createElement("div")),t=(e.id="whitPnl",e.style.zIndex="10000",e.style.width="80%",e.style.height="85%",e.style.backgroundColor="#ebebeb",e.style.position="fixed",e.style.left="10%",e.style.top="50px",e.style.padding="0px",e.style.display="none",document.body.appendChild(e),document.createElement("div")),n=(t.style.height="35px",t.style.width="100%",t.style.textAlign="center",t.style.boxShadow="0px 0px 8px #000",t.style.position="absolute",t.style.top="-35px",t.innerHTML="<h2 id='txtHeader' style='float:left;width:95%;margin-bottom:0px;'></h2>",e.appendChild(t),isDarkTheme()?(t.style.backgroundColor="#2d2d2d",t.style.color="#ddd"):t.style.backgroundColor="#ccc",document.createElement("a")),l=(n.style.float="right",n.style.background="transparent url('https://i.hizliresim.com/gh3RMf.png') -40px 0px",n.style.width="30px",n.style.height="30px",n.style.marginTop="-15px",n.style.position="absolute",n.addEventListener("click",hidePanels,!1),t.appendChild(n),document.createElement("div")),o=(l.style.width="100%",l.style.height="100%",l.style.overflow="auto",l.style.padding="2rem 8rem",l.style.fontSize="15px",l.style.fontFamily="Monospace",l.id="txtBody",isDarkTheme()?(l.style.backgroundColor="#2d2d2d",l.style.color="#ddd"):(l.style.backgroundColor="#ebebeb",l.style.color="#000"),l.onclick=function(e){"DIV"!=e.target.nodeName&&"CENTER"!=e.target.nodeName||isFast&&startStopContent()},document.createElement("div"));const i=e=>{var t=l.style.fontSize,t=parseInt(t.substring(0,t.length-2));l.style.fontSize="inc"===e?t+1+"px":t-1+"px"};o.style.width="2rem";const s=(()=>{let l=0;return()=>{if(0===l){{const e=`
            <ol>
              <h5>Klavye Kisayollari</h5>
              <hr />
              <li> sonraki sayfa -&gt; &lt;right_arrow&gt;</li>
              <li> onceki sayfa -&gt; &lt;left_arrow&gt;</li>
              <li> kapat -&gt; &lt;esc&gt;</li>
              <li> mod degistir -&gt; %</li>
              <li> durdur/baslat -&gt; &lt;space&gt;</li>
              <li> klavye kisayollari yardim -&gt; ?</li>
            </ol>
        `;setTextBody(e)}l=1}else{{const t=getCurrentArticle();if(isFast)setFastBody(t);else{const n=getArticleContent(t);setTextBody(n)}}l=0}}})();[{text:"+",action:()=>i("inc"),title:"font buyut"},{text:"-",action:()=>i("dec"),title:"font kucult"},{text:"%",action:switchView,title:"mod degistir"},{text:"?",action:s,title:"klavye kisayollari"}].forEach(({text:e,action:t,title:n})=>{const l=document.createElement("a");l.href="#",l.title=n,l.classList.add("btnControl"),l.innerHTML=e,l.addEventListener("click",t.bind(l)),l.style.cursor="pointer",l.style.padding="5px",l.style.border="solid 1px #ccc",l.onmouseover=()=>{l.style.backgroundColor="lightgreen"},l.onmouseout=()=>{l.style.backgroundColor="transparent"},o.appendChild(l)}),o.style.display="flex",o.style.flexDirection="column",o.style.textAlign="center",o.style.marginRight="15px",o.style.position="absolute",o.style.right="0",o.id="pnlBodyControls",e.appendChild(o),e.appendChild(l),l.focus();t=document.createElement("div"),t.style.height="26px",t.style.width="100%",t.style.position="absolute",t.style.bottom="-26px",t.style.paddingRight="5px",t.id="suserPanel",isDarkTheme()?(t.style.backgroundColor="#2d2d2d",t.style.color="#ebebeb"):t.style.backgroundColor="#ebebeb",e.appendChild(t),n=document.createElement("div"),n.style.height="26px",n.style.width="100%",n.style.textAlign="center",n.style.position="absolute",n.style.bottom="-54px",n.style.boxShadow="0px 0px 8px #000",n.id="PageContent",isDarkTheme()?(n.style.backgroundColor="#2d2d2d",n.style.color="#cccccc"):n.style.backgroundColor="#cccccc",e.appendChild(n),t=document.createElement("a"),t.style.background="url('https://i.hizliresim.com/gh3RMf.png') repeat scroll -40px -60px transparent",t.style.width="30px",t.style.height="30px",t.style.position="absolute",t.href="javascript://",t.id="btnRight",t.style.top="50%",t.style.left="100%",n=getMaxIndex(),t.style.display=1<n?"block":"none",t.onclick=nextClicked,e.appendChild(t),t=document.createElement("a");t.style.background="url('https://i.hizliresim.com/gh3RMf.png') repeat scroll -40px -30px transparent",t.style.width="30px",t.style.height="30px",t.style.position="absolute",t.href="javascript://",t.style.top="50%",t.style.left="-30px",t.id="btnLeft",t.style.display=1<n?"block":"none",t.onclick=prevClicked,window.chrome&&window.chrome.webstore;document.onkeydown=function(e){39==e.keyCode?nextClicked():37==e.keyCode&&prevClicked(),scrollKeys(e.keyCode),isFast&&32===e.keyCode&&startStopContent(),53===e.keyCode&&switchView(),27===e.keyCode&&hidePanels(),191===e.keyCode&&s()},e.appendChild(t)}function scrollKeys(e){var t=document.querySelector("p#txtBodyP");t&&(75==e?t.scrollTop-=50:74==e&&(t.scrollTop+=50))}createMainButtons(),createPanel();const showPagingDiv=()=>{var e=getMaxIndex();document.getElementById("PageContent").style.display=1<e?"block":"none"},getCurrentArticle=()=>{var e=getArticleIndex();return getAllArticles()[e]},showModal=()=>{document.getElementById("backPnl").style.display="block",document.getElementById("whitPnl").style.display="block"},setModalTitle=e=>{document.getElementById("txtHeader").innerHTML=e},hideMainButtons=()=>{document.getElementById("btnLeft").style.display="none",document.getElementById("btnRight").style.display="none"},getModal=()=>document.getElementById("whitPnl"),getArticleContent=e=>e.querySelector(".content").innerHTML.trim(),getArticleContentForFast=e=>{return e.querySelector(".content").innerText.trim().replace(/<br>/g," ")},getArticleTitle=e=>{var t=e.closest("ul").previousSibling.previousSibling.previousSibling.previousSibling,e=(t=null==t?e.closest("ul").previousSibling.previousSibling:t).getAttribute("data-title");return e||document.getElementById("title").getAttribute("data-title")||""},setTitle=e=>{e=getArticleTitle(e);setModalTitle(e)};let articleIndex=0;const getArticleIndex=()=>articleIndex,setArticleIndex=e=>{articleIndex=e};