Amboss Copier

Copy article informations from Miamed Amboss.

目前為 2016-09-16 提交的版本,檢視 最新版本

// ==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.3
// @match        https://amboss.miamed.de/library
// @include      /^https?://amboss-miamed-de\.ezproxy\..*/library$/
// @grant        GM_setClipboard
// @run-at       document-idle
// ==/UserScript==

(function(){

var loadingWatcher;

if (typeof angular !== 'undefined' || typeof angular.element('#LibraryContent').scope() !== 'undefined') {
    setwatcher();
    window.addEventListener("hashchange", setwatcher);
}

function setwatcher() {
    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');
    } 
    if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
        //console.log('list');
        document.addEventListener('keydown', function(e) {
            // pressed ctrl+alt+c
            if (e.keyCode == 99 && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
                GM_setClipboard('<a href="url">test</a>','html');
            }
        }, false);
    }
}

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, " "));
}

}());