Amboss Copier

Copy article informations from Miamed Amboss.

Versión del día 17/9/2016. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Amboss Copier
// @namespace    http://oix.cc/gm
// @description  Copy article informations from Miamed Amboss.
// @author       Bin Zhang
// @icon         https://amboss.miamed.de/favicon-192x192.png
// @homepageURL  http://oix.cc/amboss
// @version      0.0.4
// @match        https://amboss.miamed.de/library
// @include      /^https?://amboss-miamed-de\.ezproxy\..*/library$/
// @grant        GM_setClipboard
// @run-at       document-idle
// ==/UserScript==

(function(){

var loadingWatcher;
var currentContent;

if (typeof angular !== 'undefined' || typeof angular.element('#LibraryContent').scope() !== 'undefined') {
    setwatcher();
    window.addEventListener("hashchange", setwatcher);
    document.addEventListener('keydown', function(e) {
        if ('card' === currentContent) {
            //if ((e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) || (e.key == 'F9' && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey)) {
            if ((e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey)) {
                // pressed ctrl+alt+c or //F9
                GM_setClipboard(getcardhtml(),'html');
            } else if (e.key == 'a' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
                // pressed ctrl+alt+a
                GM_setClipboard(getcardhtml(true),'html');
            }            
        } else if ('list' === currentContent) {
            if (e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
                // pressed ctrl+alt+c
                GM_setClipboard(getlisthtml(),'html');
            }            
        }
    }, false);
}

function setwatcher() {
    currentContent = null;
    
    var i;
    if (!i) i = 50;
    if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1))) {
        // only cards set $root.loading, poll loading
        loadingWatcher = setInterval(checkloading, i);
    } else {
        i = 1000;
        loadingWatcher = setInterval(function (){
            clearInterval(loadingWatcher);
            loaded();
        }, i);
    }
    //console.log('i=' + i);
}
    
function checkloading() {
    //console.log('watch');
    //console.log(angular.element('#LibraryContent').scope().$root.loading);

    if (angular.element('#LibraryContent').scope().$root.loading !== true) {
        //console.log(typeof angular.element('#LibraryContent').scope().$root.loading);
        clearInterval(loadingWatcher);
        loaded();
    }
}

function loaded () {
    //console.log('loaded');
    //console.log($('#LibraryContent').html());

    if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1)) && $('#LibraryContent').find('article.LearningCard:visible').length > 0) {
        //console.log('card');
        currentContent = 'card';
    } 
    if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
        //console.log('list');
        currentContent = 'list';

    }
}

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function getcardhtml(full) {
    
    var html = '';
    html += '<h1>' + $.trim($('article.LearningCard h1:first').clone().children().remove().end().text()) 
        +  ($('article.LearningCard h1:first').attr('tooltip-content')? (' (' + $('article.LearningCard h1:first').attr('tooltip-content').replace(/^(Synonyme:<br> )/,'') + ')') : '')
        + '</h1>';
    var tempDiv;
    if (full) {
        tempDiv = $('<div>').append($('article.LearningCard>section').clone().find('section, .unwichtig, .veraltet').remove().end().find('li:visible:empty').remove().end().find('ul:visible:empty, ol:visible:empty').remove().end()); // remove meta infos, veraltet and unwichtig
    } else {
        tempDiv = $('<div>').append($('article.LearningCard>section:first p').clone()); // only p extracted, first section without p probably not abstracts
    }
    tempDiv.find('a').each(function(i, anchor){
        anchor.href = $(anchor).prop('href'); // all urls to abs
    })
    html += tempDiv.html();
    tempDiv.remove();
    tempDiv = null;
    return html;
}

function getlisthtml() {
    var html = '';
    html += '<h2>' + $.trim($('#LibraryContent').find('#Title').text()) + '</h2>';
    var tempDiv = $('<div>').append($('table#LibraryList').clone().find('td:not(:nth-child(2), :nth-child(3), :nth-child(8), :nth-child(9))').remove().end().find('th').remove().end());
    //tempDiv.hide();
    //$('body').append(tempDiv);
    tempDiv.find('a').each(function(i, anchor){
        anchor.href = $(anchor).prop('href'); // all urls to abs
    })
    html += tempDiv.html();
    tempDiv.remove();
    tempDiv = null;
    return html;
}

}());