NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Semplifica articoli SD AUTO DIV // @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'; //estraggo i dati che mi interessano dalla pagina //_______________________________________________________________________________________________________ //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. Lo facci due volte perchè di solito le pubblicità sono massimo due. 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 journal_references = document.getElementById("journal_references").innerHTML; function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } var LinkFonte = getElementByXpath('//*[@id="journal_references"]/ol/li/a'); //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){ var pubblicazione = "Nessun valore per journal_references"; } else { var 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 } </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 + "<a href=" + LinkFonte +" target='_blank' rel='noopener'>Link Fonte</a>" + "</div><div id='en' class='notranslate'><h1>" + titolo + "</h1><h2>" + titoletto + "</h2>" + testo + "</div>" + "<div class='notranslate'>" + fonte + pubblicazione + "</div>"; var documentoCompleto = inizioHTML + documentoTesto + fineHTML; //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(); })();