leonardo.corsettigmail.com / Semplifica articoli SD AUTO DIV NEW

// ==UserScript==
// @name         Semplifica articoli SD AUTO DIV NEW
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.sciencedaily.com/releases/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';




    //_______________________________________________________________________________________________________
    //Le seguenti righe, scritte male, servono a rimuovere i tag le pubblicitĂ  presenti nel corpo del testo
    //identifico la classe del div che contiene la pubblicitĂ  e se presente la elimino prima che vengano generate
    //le successive variabili. DOVREBBE ESSERE FATTO DUE VOLTE, MA SEMBRA FUNZIONI ANCHE CON UNA SOLA.


    var divPubblicitaUno = document.getElementsByClassName("mobile-middle-rectangle hidden-md hidden-lg")[0];
    if (divPubblicitaUno) {
        divPubblicitaUno.parentNode.removeChild(divPubblicitaUno);
    }

    //var divPubblicitaUno = document.getElementsByClassName("mobile-middle-rectangle hidden-md hidden-lg")[0];
    //if (divPubblicitaUno) {
    //   divPubblicitaUno.parentNode.removeChild(divPubblicitaUno);
    //}

    //_______________________________________________________________________________________________________


    var titolo = document.getElementById("headline").innerText;
    var titoletto = document.getElementById("first").innerText;
    var testo = document.getElementById("text").innerHTML;
    var fonte = document.getElementById("story_source").innerHTML;
    var LinkFonte;
    var pubblicazione;


    //estraggo i dati che mi interessano dalla pagina

    function getElementByXpath(path) {
        return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }

   
    //se il documento non contiene le informazioni relative alla pubblicazione allora un messaggio
    //di errore permette comunque di non interrompere la prcedura

    if (document.getElementById("journal_references") == null){

        LinkFonte = "<font color='red'> NESSUNA FONTE DISPONIBILE!</font>";
        pubblicazione = "<font color='red'> NESSUN VALORE PER Journal_References</font>";

    }
    else {
        LinkFonte = "<a href=" + getElementByXpath('//*[@id="journal_references"]/ol/li/a') +" target='_blank' rel='noopener'>Link Fonte</a>";
        pubblicazione = document.getElementById("journal_references").innerHTML;
    }




    //Aggiungo un minimo di formattazione

    var stileCSS = "<style type='text/css'> body {font-size: x-large;} #it { width:70%; margin:0 auto } #en { width:70%; color: blue; margin:0 auto } #fonte { width:70%; margin:0 auto } </style>";
    var inizioHTML = "<html><head><title>" + titolo + "</title><meta charset='utf-8'>"  + stileCSS + "</head><body contenteditable='true'>";
    var fineHTML = "</body></html>";


    // creo la variabile del doumento html completo
    var documentoTesto = "<div id='it'><h1>" + titolo + "</h1><h2>" + titoletto + "</h2>" + testo + LinkFonte + "</div><div id='en' class='notranslate'><h1>" + titolo + "</h1><h2>" + titoletto + "</h2>" + testo + "</div>" + "<div id= 'fonte' class='notranslate'>" + fonte + pubblicazione + "</div>";

    var documentoCompleto = inizioHTML + documentoTesto + fineHTML;


    //PER SALVARE IL FILE---------------------

    //var wnd = window.open("data:text/html;charset=utf-8,"+documentoCompleto, titolo);
    //Se Ok allora scarico il file
    //    var a = document.createElement("a");
    //    a.href = "data:text/html;charset=utf-8,"+documentoCompleto;   //content
    //    a.download = titolo +".html";
    //    a.click();
    //----------------------------------------


    //apro unanuova finestra con i dati html contenuti della variabile creata sopra
    document.write(documentoCompleto);
    window.stop();










})();