Litnet copy text

try to take over the world! OVER WORLD!

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Litnet copy text
// @namespace    http://eldor.besaba.com
// @version      0.1
// @description  try to take over the world! OVER WORLD!
// @author       KoctrX
// @match        https://litnet.com/*
// @grant        none
// ==/UserScript==

getTextPage = () => {
    let text = '';
    let title = null;
    b = document.getElementsByClassName('reader-text')[0].children;
    for(let a of b) {
        if(a.tagName.toLowerCase() === 'p' && a.innerHTML) {
            text+=`<p>${a.innerHTML}</p>`;
        }
        if(a.tagName.toLowerCase() === 'h2') { title = a.innerHTML; }
    }
    return openWindow(text? text : getTextInDiv(b), title);
};

openWindow = (text, title) => {
    let html = `<h2>${title? title: ''}</h2>${text}`;
    window.open('','','width=800, height=500')
        .document.write(html);
};

getTextInDiv = (elements) => {
    let text = '';
    for(let el of elements) {
        if(el.tagName.toLowerCase() === 'div' && !el.getAttribute('class')) {
            text += `<p>${el.children[0].innerHTML.replace(/(<span).*?(span>)/g, '')}</p>`;
        }
    }
    return text;
};

function createElement() {
    let d = document.getElementsByClassName('topbar-nav')[0],
    li = document.createElement('li'),
    a = document.createElement('a');
    a.innerHTML = 'Copy Text';
    a.setAttribute('href', '#');
    a.setAttribute('onclick', 'getTextPage();');
    li.appendChild(a);
    d.appendChild(li);
}

(function(){
    createElement();
})();